On Wednesday, 30 April 2014 at 10:16:12 UTC, Ola Fosheim Grøstad
wrote:
On Wednesday, 30 April 2014 at 08:52:48 UTC, Chris wrote:
Say you have a Python file with 500 lines of code. Try to copy
and paste something with a different indentation from
somewhere else into an if statement.
Paste in non-formatting-mode and use the editor's ability to
block indent? Having an editor that will indent/unindent
regions when you hit tab/shift-tab helps.
Yes it helps, but a language's syntax / usability should not
depend on tools like editors. Also, what if I want to use an
editor that doesn't support all the fancy formatting stuff?
This kind of patronizing bullshit was invented for
non-programmers who might make a mess of the code otherwise.
It is true that Python grew out of a programming language
tradition meant for teaching/prototyping.
But the Python syntax it is more useful for an interpreter
prompt (REPL) than a syntax with explicit begin/end markers.
Most of the non-trivial transformations I do start at the REPL
before being pasted into the editor.
In D you can do this:
if (mode == "TEST") { // Second block added later
if (x == 1) { // First block
writeln("Hurray!");
}
}
I think Go did the right thing by not requiring the redundant
parantheses on the if statement and perhaps also by allowing
the omission of semicolons where appropriate etc. Room for
improved legibility right there.
In Python I would probably use «TEST» rather than
«mode=="test"»:
if TEST&& x == 1:
By this you change the substance of the if statement merely for
test purposes, i.e.
if x == 1: > if TEST && x == 1:
which is not very elegant, and it's error prone (what if you
overlook the TEST && bit for release?)
In my D example you leave the essential part untouched. On top of
that, the fact that to if statements are at the same indentation
level makes it easier to spot that there is something unusual
going on there.