4 ms·
I've never understood this objection. Do you not indent your code anyway? If so, why should you also need to delineate scopes in another way? Python allows y
by jsankey 16y ago
I've never understood this objection. Do you not indent your code anyway? If so, why should you also need to delineate scopes in another way? Python allows you to choose your indentation, it just requires consistency: something that is always required by coding standards (with good reason).
If there was a command line switch, would you use it? Why?
- melling 16y agoI indent my Perl code. Not everyone does, however. It's a trivial task to reformat it in an editor. I guess the only complaint I might have is why bother thinking about indentation, ever? Throw in a couple of {} and now the tools can provide additional help.
- edanm 16y agoThe point is, I've never met a programmer who doesn't think of indentation. I've never seen a (real) project which doesn't have indentation. So if everyone is doing it anyway, why not take advantage of it and make it a part of the language? This way programmers learn to use indentation from the start (which any real programmer uses anyway), and indentation is always correct, nothing to ever think about.
- util 16y agoIt makes it harder to correctly do operations on code as text, eg, inserting a chunk of code from elsewhere or moving it out from or under an "if" statement. I have trouble with this occasionally working in emacs at least.
- edanm 16y agoThis does get to be a problem with people not indenting consistently. I.e., some code using tabs and some using spaces, and then copying between them. Technically, your editor should take care of that for you, but some of them don't do it properly (and sometimes can't do it properly), and it really sucks. Well, everything has a downside :)
- melling 16y agoShouldn't tools take care of that before a commit to svn, git, etc? Java has formatters, the Go language has one. Do any exist for Python or Perl?
- edanm 16y agoTake care of indentation, you mean? 1. People don't indent consistently. There are a lot of (imo, pointless) arguments about where to place the braces, etc. One of the advantages of the language forcing a style is that arguments about it are no longer necessary. 2. Why should tools be taking care of this? People indent to understand the code better. Everyone agrees that you have to do it. So what's the problem with the language forcing you to do it? I'd rather it be part of the language than an external tool enforcing it.
- jsankey 16y agoI indent my Perl code. Not everyone does, however. It's a trivial task to reformat it in an editor. But in Python, you don't even have to worry about other people not indenting their code! I guess the only complaint I might have is why bother thinking about indentation, ever? Throw in a couple of {} and now the tools can provide additional help. When you edit Python, the tools can already help as much. The start of a block is obvious (def, if, for, etc), so tools indent for you. To dedent, just hit the right key (e.g. a backspace on an empty line in emacs) -- no harder than hitting the brace key.
- dmn001 16y agoYou do have to worry as their Python code produces errors if they do not indent it properly! I don't like Python either and prefer Perl. (In Python I did not like indentations, dicts, tuples, lists, and the IDLE gui.)
- alphamerik 16y agoI do indent my code, but I prefer to auto-indent. Using indentation to determine if a line of code falls inside or outside some logic block requires a lot more effort for me. Would much rather just use curly braces. Curly braces also make copying and pasting code blocks much easier.
- nailer 16y agoI use auto indent on python all day. Not having to perform secondary bracket mark up is great.
- maw 16y agoYou don't, because auto indent for python doesn't and can't exist.
- crystalis 16y agoYou say this, and get points, but I'm not sure what you mean. I've written Python and gotten each new line to automatically indent to the proper point, with a functional backspace that unindents the appropriate amount. I've then copy-pasted blocks with several different indentation levels that were automatically adjusted to the surrounding code, with the possible exception of an error corrected by a single keypress. To my knowledge, this is no worse than the expectation for a braced language, but much better than the worst case for a braced language. If you mean something simpler than I've taken you to mean, e.g., the conversion of a whitespaceless C program into a whitespaced one, I concede you are mostly correct (';' still works in Python), but I must admit I would still not yet see your point.
- maw 16y agoIf you write code like this: if x: # do stuff # do other stuff Your indenter will not know where to put the third line. In languages whose blocks are closed using nonwhitespace the problem doesn't exist. Your indenter just has to push everything as far to the right as it can, and problem solved. It's nice that your editor gets copy and paste right, but it doesn't and indeed can't decide how to indent your code, something that works in every other language I've dealt with.
- cageface 16y agoPython's whitespace indentation seems like a great idea until you realize that it makes things like copying & pasting code from web pages etc far more difficult and, worse, makes automatically reindenting a block of code in an editor impossible. If I come across a badly formatted block of code in Ruby or Java or C in emacs it takes me one keypress to sort it out. In Python I have to carefully, manually look at each line. It's also fun to spend an hour looking for a bug caused by somebody inserting a tab instead of a space somewhere. We had a production crash that took us a long time to fix because somebody hotfixed a file with the wrong editor and did this. I also don't understand how forcing people to indent code in the same way magically makes people write good code. The kind of programmer that can't or won't indent his code properly is introducing bugs far more serious than bad layout into your project. Python's a nice language in many ways but I consider the syntax to be a bug.
- lars512 16y agoI consider the indentation approach excellent because it's so clear and readable. For exactly the same reason, I prefer YAML over XML, because the result is something more readable, something whose structure is understandable at a glance.
- Jeema3000 16y agoIt's also very annoying to have to un-indent an entire block of code during debugging just because you want to comment out the conditional statement around it...
- 16y ago