469,336 Members | 5,556 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

"correct" tab/space rule? (prothon)

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.
Jul 18 '05 #1
0 1226

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mitchell Vincent | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.