"correct" tab/space rule? (prothon)

M

Mark Hahn

Ville Vainio came up an idea for one final tweak of the tab/space indent
algorithm we are using in Prothon, and the final result surprised me, in
that it directly addresses the problem of mixed tabs and spaces. We have
been having flame wars about tabs vs. spaces and I was thinking this was an
opinion kind of thing and it never occured to me to look at it as a simple
bug that needed fixing. Give me a second of your time to pitch it that way.

When you mix tabs and spaces in Python and you change the tab width in your
editor, the indents don't visually line up any more, even thought it
compiles fine. This is the bug/problem. If you just don't allow tabs and
spaces to be mixed in any one block, where you define a block to be a group
of matching indented lines, then this problem cannot occur and the bug
cannot occur.

Our new Prothon rules fix this problem while allowing maximum flexibilty to
use both tabs and spaces, and we've thrown in a new easier continuation
method just for good measure.

Prothon indentation rules:

1) You must use only tabs or only spaces for indents in any one indentation
block. You cannot mix tabs and spaces in a block. A block is defined as a
group of consecutive indented lines. Non-indented lines seperate blocks.

2) Each indent level can have any number of characters more than the
previous level, whether you are using tabs or spaces. If you drop back to
the left to dedent, and your column position does not match any level above,
you will get a lexer error.

3) If you increase the indentation level above the previous line by even
one character, and that previous line does not end in a colon, then the new
line will be considered a continuation of the previous line.

4) If a line contains an active (not quoted or commented) (, {, or [
without a matching end character, then the following line is always a
continuation, no matter what that following line contains.

5) There is still support for using the trailing backslash ( \ ) to indicate
that the next line is a continuation. This may be removed in the future if
everyone agrees to do so.

6) A continuation line is effectively added to the end of the previous line
so any line following a continuation line uses the last non-continuation
line for the "previous line" in all the rules above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top