Slashdot videos: Now with more Slashdot!

View

Discuss

Share

We've improved Slashdot's video section; now you can view our video interviews, product close-ups and site visits with all the usual Slashdot options to comment, share, etc. No more walled garden! It's a work in progress -- we hope you'll check it out (Learn more about the recent updates).

Blocks that are normally indented now have to be closed explicitly with an end keyword.

I see what they did there.

Highly un-Python-ic: a new keyword to close the if/for/etc statements.

But it is a confirmation of my own conclusion that with the vanilla Python syntax that is impossible to accomplish.

Python support for me wasn't as important. I simply wanted to see and compare use of different languages in such context. And see whether a generic, language-neutral preprocessor makes any sense. (Here it is, btw.)

(Source: personal experience. I work on a Python IDE that has to deal with lots of that kind of stuff for e.g. implementation of refactoring. Once we had our whitespace-preserving AST, the rest was and remains easy.)

You have different use case, which is 100% controlled code. IOW, you can rely on the original indentation to create the AST.

My use case is:

{user-start-code}
{generated-code}
{user-finish-code}

where "user-*-code" is an arbitrary user supplied string.

If the user start/finish code is just a function call, then it is all fine.

But if the user code is "if something:{CR}{TAB}aaaa", then the user intent simply can't be made clear from the Python's syntax: (A) is it "if (something) { aaaa }" or (B) it is "if (something) { aaaa" (and the closing "bracket" is in the finish code).

I've spent few hours tinkering, but there is simply no way to tell A from B definitively in the Python's syntax.

P.S. It is a sort of preprocessor, which allows to mix plain text with an arbitrary language. In generated output, the plain text is simply replaced with the print statements.

It is hard to generate Python code, without actually analyzing what's precisely is being generated. If source is 100% generated - it is doable, relatively easy. But generally generated code also contains pieces of user code, which might/might not require its own indentation and also reindentation to make it proper part of the generated code.

If Python at least allowed optional block statement - curly brackets or begin/end or whatever. But nope. It is appears to be sort of a religious issue for the language creator and some of his followers.

I personally do not like Python for that reason. I prefer to have a visual marker that block is closed. You know, like a dot at the end of the sentence.