10 ms·
What would you suggest instead? Please do not say Python. Using spaces for syntax is madness.
by Freebytes 3y ago
What would you suggest instead? Please do not say Python. Using spaces for syntax is madness.
- xigoi 3y agoYou never make use of horizontal spacing when, say, making notes on paper?
- gavinhoward 3y agoNotes on paper are for humans. Programming languages are for humans and machines. Machines do better with braces. (I've written lexers for both.) Also, try to write an automatic formatter for a whitespace-delimited language; if your indentation is wrong, your logic is wrong, whereas with a brace language, if your indentation is wrong, you run a formatter, and it's all golden.
- xigoi 3y agoA parser is something you write once and then it's done, so it shouldn't be the deciding factor. And parsing indentation-based languages is not that hard, just replace indents and dedents with a special token. In a brace-based language, if your braces are wrong, your logic is wrong. How is that better? At least a mistake in indentation is much easier for a human to spot.
- gavinhoward 3y agoRun the formatter, and the brace-based mistake is easy to spot too.
- xigoi 3y agoSo what's the point of having braces if you're going to use indentation anyway?
- gavinhoward 3y agoTo do more things with the source than just compile it.
- xigoi 3y agoAnd how do braces and semicolons help you with that?
- gavinhoward 3y agoExactly what I mentioned above: source formatting is just one of the things you can do with braces and not significant whitespace. [1] Also, forget a brace in your program, just one, and the compiler can tell. Forget one indentation? No dice. And while braces can break things too, editor settings can make it much easier to break things with significant whitespace. [2] [3] Also, refactoring. [4] Editor stuff. [5] [1]: https://news.ycombinator.com/item?id=3296782 https://news.ycombinator.com/item?id=3296782 [2]: https://medium.com/@rwxrob/significant-whitespace-is-still-the-devil-66d48674dc02 https://medium.com/@rwxrob/significant-whitespace-is-still-t... [3]: https://news.ycombinator.com/item?id=24854090 https://news.ycombinator.com/item?id=24854090 [4]: https://lobste.rs/s/yyuo7f/significant_whitespace_good_bad#c_mkmzgz https://lobste.rs/s/yyuo7f/significant_whitespace_good_bad#c... [5]: https://lobste.rs/s/yyuo7f/significant_whitespace_good_bad#c_gbo7kj https://lobste.rs/s/yyuo7f/significant_whitespace_good_bad#c...
- xigoi 3y agoPython does have an auto-formatter [6], so clearly indentation doesn't prevent that. > Also, forget a brace in your program, just one, and the compiler can tell. Should we duplicate every character, so the compiler can tell if you leave one out? This is not a radiation-hardened quine [7]. > editor settings can make it much easier to break things with significant whitespace. Then use an editor which doesn't. > Selecting all code contained in a brace or a parents is so much easier (in vim the % movement) than if you have to walk lines. I have a plugin for Neovim that adds indentation-based motions. The implementation is trivial. [6] https://github.com/psf/black https://github.com/psf/black [7] https://codegolf.stackexchange.com/questions/57257/radiation-hardened-quine https://codegolf.stackexchange.com/questions/57257/radiation...