On 16/04/2017 19:42, Chris Angelico wrote:
On Mon, Apr 17, 2017 at 4:21 AM, bartc <b...@freeuk.com> wrote:
Here is a function from some old CPython source that appears to be something
to do with While statements:

static int
validate_while(node *tree)
{
...
Look, no comments! Are you going to castigate the developers of CPython for
that? (I guess not.)

Can you find the equivalent in the current sources? I think it might be here:

https://github.com/python/cpython/blob/master/Grammar/Grammar#L73


while_stmt: 'while' test ':' suite ['else' ':' suite]

A single, extremely readable line. Abstract, not concrete.

How do you know my code fragment wasn't also generated? Since it was parsing C, the refs for that language also define the while statement quite neatly:

  'while' '(' expression ')' statement

but actually it was done manually. It's part of a suite of functions that do things in a common pattern, and would be documented as a set rather than line by line. And elsewhere calls to such a function would also be part of a chain of tests.

That's if I needed to documented it (but I can't remember how many parsers I've done along the same lines since c.1979).

But I've glanced through the CPython code again, and it is quite lightly commented. Although sometimes it gets quite chatty.

Want to show me your source for this source?

The source files I looked at were dated around 2010. I've no idea where they came from. I think I'd wanted to compile it, but unfortunately, they're not written in C, but a combination of C, make-file, compiler-options, and bash-script with a bunch of Linux dependencies.


Next complaint, please.

No complaint, just saying other projects are sparse on comments too. And my code isn't intended as open source.

--
bartc

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to