6 ms·
I'll make a case against DRY principles. A programming language isn't just about the code. It's about the programmer. What the programmer reads and what the pr
by fennecfoxen 15y ago
I'll make a case against DRY principles.
A programming language isn't just about the code. It's about the programmer. What the programmer reads and what the programmer writes are an essential part of programming, and we should look at it not just from a coder point of view (DRY principles) but from a user-experience point of view, where redundancy is frequently helpful!
Consider: Displaying whitespace (indentation whitespace, that is) to the user is surely essential for basic code readability; our human brains like this stuff. But the quality of our perception of is limited. It's easy to tell when something is a few spaces further in, but can you tell at an instant's glance whether something's indented by 8 or 12 spaces when it's preceded by a paragraph indented by 32 spaces? Because that tells you which flow control construct you just closed. (For bonus points, the start of that construct is off the top of your screen.)
Does counting invisible spaces and lining things up with a ruler sound like a great way to figure out the flow of a block of code? I say Meh. Whitespace is a poor medium for communicating something precise like the flow control of a program. The end to code blocks is something important enough that the marker should be something visible, not invisible.
And if that means repeating myself, so be it. But this is a repetition that can be trivially automated. Instead of making whitespace into syntax, go the other way around and turn your syntax into whitespace with your IDE or a code prettifier.
--
Now, from all I hear, the ever-popular Python programming language already does plenty with whitespace, so clearly it's certainly not impossible to work with. But I don't like it :)
- extension 15y agoIs counting delimiters any easier than measuring indentation? Not really. You will just fall back on the indentation in the end anyway. The delimiters never make anything clearer, they just help push the opening line off the top of the screen.
- ansible 15y agoWhat we need are better editor setups that can slightly shade the backgrounds of nested blocks to clearly indicate indent levels and easily enable the programmer to see what matches to what. Something like this for VIM: https://github.com/nathanaelkane/vim-indent-guides https://github.com/nathanaelkane/vim-indent-guides Screenshots at the bottom of the page.
- jholman 15y agocommenting to save for later (sorry)
- jtc331 15y ago/Counting/ delimiters isn't necessarily any easier for our brains than measuring indentation. However, it is (at least for me) much easier for your eyes to line up two delimiters then a keyword/function call/literal/whatever and the end of the block it introduced when that block's termination is implicit from indentation. With the delimiters, I have two similar things to line up visually. With indentation-significant, I have to line up a delimiter with blank space, which is difficult.
- extension 15y agoYou're lining up the statement that opened the block with the statement that comes after the block. Should be easy. And in the most common code style, delimiters don't line up anyway, because the opening delimiter is at the end of the line.
- thedufer 15y agoI guess my feeling is, why automate something that doesn't need to happen at all? If you need to see your whitespace, it should be trivial* to make it visible. Thus, I agree with the comment about brackets being no easier to count than spaces. *Assuming you're using a reasonable editor.
- fennecfoxen 15y agoIt's true; you could use syntax highlighting or IDE features to make things more obvious. You could also turn on syntax highlighting in Whitespace. http://en.wikipedia.org/wiki/Whitespace_(programming_language) http://en.wikipedia.org/wiki/Whitespace_(programming_languag... This is, of course, significantly more ridiculous than an IDE helping you out with your CoffeeScript, so don't take my teasing too seriously ;)
- thedufer 15y agoMy response was meant in much the same tone as yours; I use vim and, while I have never needed visible whitespace, I don't have any indication that its an easy thing to do.
- icebraining 15y agobut can you tell at an instant's glance whether something's indented by 8 or 12 spaces when it's preceded by a paragraph indented by 32 spaces? No, but the problem there isn't the whitespace per se, but the 32 spaces. To quote Linus on the Linux Coding Style guide: If you need more than 3 levels of indentation, you're screwed anyway, and should fix your program. And the Zen of Python: Flat is better than nested. In conclusion, if telling nested levels apart is a problem, that's a code smell, not a problem of the indentation system.