Hacker News new | ask | show | jobs
by Almaviva 5465 days ago
Do semicolons really distract people from thinking about the behaviour of their code? Really? Would these people like their novels and articles decompiled so that every sentence is on a new line, and thus periods wouldn't distract them so much from the meaning of the text? Or is it just transparent after a while, as the way you end something?
4 comments

Books and code have different usage patterns.

In books, you typically start from the beginning and read to the end. You consume the book serially and the only breaks you are concerned about are pauses (period, comma, colon, etc.) and page breaks (chapters).

In code, you typically scan. Scanning a book is a painful experience. The sentences never start in the same spot. In code, the heirarchcal structure and text layout helps for scanning and identifying quickly. As someone said previously in this thread, cookbooks are done the same way and for the same reasons.

I'd prefer a Coffeescript that restored semicolons and braces and didn't depend on indentation to denote block structure. Fixing some of Javascript's most serious warts is a great idea but, IMO, significant whitespace is a bad idea here just as it is in Python and Haskell. It just makes routine code manipulations like copy & paste and block refactoring a lot more tedious.
There are many other compile-to-JS languages that might be more to your liking. Perhaps try Objective-J? It's a strict superset of JavaScript.

http://altjs.org/

I already curse Objective-C for its verbosity, so that's not the right direction for me. Coffeescript is in the right ballpark, I'd just rather have a more explicitly structured syntax, perhaps closer to Ruby.
IMO, significant whitespace shines when used along with a proper editor.

Also, even without an editor, the cleanliness pays off. And you would indent properly anyway...

>Would these people like their novels and articles decompiled so that every sentence is on a new line

Isn't that how we write cooking recipes?

I see your point. Punctuation is a vector for meaning and clarity but is Javascript's syntax any more informative than Coffeescript's? It isn't in my observation. It certainly offers more flexibility in style, but why would you need it? I can't conceive of a reason besides minification.

Your comparison with novels I think is a bit skewed. Literature has a whole different set of readability enhancements such as fully justified text, variable-width fonts, as well as margins and padding. Punctuation in English has been evolving for centuries as people settle on the minimum needed to convey the full meaning as unambiguously as possible. But English also has many many more sets of valid (as well as various definitions of valid) constructs than Javascript does and thus may require a more robus set of punctuation.

There's a principled point about aesthetics and removing unnecessary redundancy. But that shouldn't be confused with whether semicolons affect your ability to think about code. Really I can't imagine how someone could be significantly distracted by semicolons, once they're used to a language, to the extent that it occupies their conscious brain in any way whatsoever. It does take familiarity to get there, but I can't imagine having a mind where this didn't seem transparent and rather irrelevant very quickly.
You're absolutely right, I spent most of the past three years writing Java, C++, C, and C# and they all use semicolons and I certainly forgot about them whilst coding in those langs. But the penalty is in transitioning between languages that use or don't use those features. When I'm writing in C and the like, I tend to stick within that language. But with JavaScript and Ruby, I do a lot more context switching back and forth. Anything I can do to reduce the penalty of moving between one and the other is worth doing in my opinion. Especially when it doesn't affect the final result.