Thoughts on these? Python is one example, and no this is not a stab against Python I like the language.
What languages have a indentation requirement?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityIn Makefiles, it's annoying. In python, I find it very apropos and it makes the syntax a lot cleaner. I think the thing that makes it better in python is that no special characters are required, the only requirement is that you be consistent. You should be doing it anyway, so you get no cost added by following it.
In general, I'm against bondage and discipline features that are geared towards making it hard to write bad code. However, I don't find that Python's forced indentation fits this mold. The compiler/interpreter needs to know where blocks begin and end somehow, and about the only human-readable way to denote this is with indentation. Therefore, using indentation to denote it to the compiler/interpreter as well is a good example of DRY.
Using curly braces for the compiler/interpreter plus indentation for humans is like writing otherwise inscrutable but excessively commented code. Information is specified once for the compiler/interpreter, then again for humans. It has to be kept in sync manually and becomes almost impossible to understand if it gets out of sync.
I like Python's indentation rule.
I said this elsewhere and will repeat here, whoever complains about Python in this respect should be asked to maintain poorly indented source code. If you understand how painful it is to read through that kind of source code, you would appreciate this rule.
I dislike a lot this kind of language requirement.
I think python is a great language but this is keeping me away of it !
For those complaining about not or bad formatted code, I will say: use a code formatter !
I think that this restriction is more invasive than a rule about having parenthesis, using '.' or '->' for member access or using a ';' or a '.' to end a line.
gg=G
or G=gg
Old-fashioned FORTRAN and COBOL had indentation requirements based on punch-card layout, which I found annoying. Indentation requirements don't seem to bother me provided I can use all columns, but having to be careful to start a line on column 7 because 6 is for line continuation is awkward.
Haskell do notation is kind of a nice balance here. If you want to do indentation based you may do so. If you want to do semicolons you may do so. Not quite the block structure since that's a different language, but the idea of "use whatever pleases you because this isn't really an important detail" is one I like.
This seems to me purely a matter of preference.
I personally don't like significant whitespace for the following reasons:
You ask for languages that enforce indentation. Python and make have been mentioned. Another one is the esoteric language whitespace.
FORTRAN has also been mentioned in other answers - early versions required that code start in specific columns (or beyond, so it's not precisely the same).
It is my understanding that Haskell also enforces indentation, according to this part of it's specification: "A nested context must be further indented than the enclosing context (n>m). If not, L fails, and the compiler should indicate a layout error."
There is no free lunch; something must be used for a delimiter. Since we use spacing anyway, using EOL,space and tab characters makes sense and reduces clutter.
No. I rarely get bitten by indentation requirements (perhaps because I'm a stickler for detail). I'd indent my code anyway, so it's not a problem. (The only time it's been an issue is with some old Python code I'm working on; the previous developers wrote it with 2-space tabs (ick!), then newer developers created some files with 4-space tabs, and I have my editor set to 4-space tabs, so indentation is kind of a pain in the older files.) I've never had a problem with it in Haskell, either. It's a bit annoying in Makefiles, but I wouldn't say it's "cumbersome".
lambda
was really weak: In a statement-oriented language, your lambda couldn't even have anif
because you could only use an expression. In expression-oriented languages like Lisp, where everything can go in an expression, this wasn't an issue. The function naming alternative for Python is a heavy drawback.