5 ms·
Can someone help me understand the rationale behind semantic whitespace as a replacement for explicit delimiters? Is it purely aesthetic?
by corytheboyd 6y ago
Can someone help me understand the rationale behind semantic whitespace as a replacement for explicit delimiters? Is it purely aesthetic?
- codetrotter 6y agoIt forces consistent formatting within a file. But I think it was more relevant years ago. These days I see a lot of people using code formatters.
- corytheboyd 6y agoYeah that makes a bit more sense, thinking back to arguments about aligning hash key/value pairs in code reviews and how that just never seems to come up anymore (thank god)
- mtalantikite 6y agoI still think one of Go’s best contributions was formatting with ‘go fmt’. It’s refreshing to see so many language communities just embrace a format on save standard and keep it moving. Reading Python has always been a bit of a headache for me, but that probably has as much to do with the lack of type annotations as it does the lack of braces.
- georgyo 6y agoAuto formatters are the future, why should humans ever have to manually format or discuss how it should look ever again. However, languages that have a line length limit are the blight of them. There isn't a python formatter that won't make everything mush. My if clause that is 81 chars wide doesn't need to be broken up. Similar, my strings don't need to be reflowed. Go fmt ignores line length, and always produces a formatted file that is pretty as a result.
- rjmorris 6y agoYou can change the max line length in black (the Python formatter I hear mentioned most often). How would you feel about setting it to something really large, like 1000, to emulate having no line length limit?
- georgyo 6y agoThat doesn't work still. It will reflow all your lines to reflow to 1000. Try it out, anything above 88 makes even the cleanest python a nightmare. I don't like long lines, but reflowing logic is way to aggressive in these formatters.
- rich_sasha 6y agoThe flip side is, if you’re indenting you’re code anyway, as you probably should, then you might as well combine the style and meaning. It works in practice, same difference to me tbh.
- throwaway894345 6y agoThat’s a pretty bizarre rationale given that other languages didn’t need semantic whitespace (or a formatter) to maintain consistency, and the consistency was even achievable for larger code units than individual files. Formatters are definitely the way to go, but baking it into the syntax was never necessary or even helpful IMO.
- xapata 6y agoSuppose you didn't have syntax highlighting. Would the braces be more distracting then?
- corytheboyd 6y ago> Suppose you didn't have syntax highlighting. That might be a bit TOO contrived, at least for me. I could see this coming up for someone working with jurassic hardware not under their control though. Anyway, to play along. I think curly braces help tell what is happening in long source files with deep nesting. But also you could just render whitespace characters as something visible to count them to judge indentation at a glance to get your bearings. Of course the real answer here is don’t write long source files with deep nesting, but unfortunately other people are allowed to write code :p
- xapata 6y ago> jurassic hardware Like the late 1980s, when Guido was creating Python?
- anamexis 6y agoNo, I think braces are even more useful when you don't have syntax highlighting.
- xapata 6y agoInteresting. I find them distracting. I thought the cruft might be more distracting when it doesn't fade into the background via syntax highlighting.
- reificator 6y agoNo they'd be even more useful. I say that from experience: when I was first learning to program I found C much easier than python for this exact reason, and I was not using syntax highlighting. That might be because I was much more prone to nesting back then. These days I get annoyed when I have two levels of indentation inside a function and treat three as a reminder to refactor. But when I started programming I'd build pyramids 8-10 levels deep and argued with people who tried to help simplify it.
- deleted 6y ago[deleted]
- gnufx 6y agoIf you haven't read Landin's "The Next 700 Programming Languages", you should. I don't know if it's still outside the ACM paywall, but you'll find it in a web search if not. It introduced the offside rule -- not actually what Python has -- inspired by mathematical notation. Note "it can be mixed freely with [...] punctuation" (e.g. Haskell). The paper talks about "physical representations", relevant to syntax highlighting mentioned below (or "fontification" in Emacs, reminiscent of typefaces in the publication language of ALGOL).
- okareaman 6y agoI just finished reading it the other day: https://www.cs.cmu.edu/~crary/819-f09/Landin66.pdf https://www.cs.cmu.edu/~crary/819-f09/Landin66.pdf I got there from Erik Meijer's excellent "Confessions of a Used Programming Language Salesman: Getting the Masses Hooked on Haskell": http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72.868&rep=rep1&type=pdf http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72....
- __MatrixMan__ 6y agoYour friends are going to insist on properly indented code no matter what your compiler/interpreter wants, so rather than following one set of rules for your friends and a different set of rules for your compiler, why not teach the compiler to think like your friends so that you only have one set of rules to think about? I'd call it pragmatic.
- mhh__ 6y agoIt forces you to write "good" code. I think it's Python's only real strength. The language is ugly, the interpreter is a genuinely deficient way of making software ("Why use a compiler when you can just write thousands of unit tests to check for syntax errors!?"), and the mechanisms for abstraction are fairly weak - even after all that, n00b Python code is fairly readable.
- aitchnyu 6y agoNowadays tooling will enforce this "goodness" for most languages. Whitespace blocks were a pain when people mixed tabs and spaces.
- markrages 6y agoIt's easier to follow a program's execution when you can be sure the whitespace will never lie to you. You can never have a "goto fail" kind of bug.
- kevin_thibedeau 6y agoIn Py3. Mixed whitespace that Py2 accepts can be very much misleading.