This might appear to be a rant against brace-less, semicolon-less languages; i.e. Ruby, Python and a few others. It is not.
In my real life, I study English, and literature. Yes, it has nothing to do with programming, barely anything to do with computers, and some say it voids my geekiness (like that’s a bad thing). But this field often gives me the strangest ideas:
The braceless ones seem to believe that throwing away extra punctuation is going to make programmers’ lives better. It irks me that some consider these omissions selling points. In an example challenging PHP’s readability, Digital Web’s article points out three distinctive Ruby code features:
- Ruby doesn’t wrap its decision structures in curly braces nor does it wrap the comparison in parentheses.
- Semicolons are a thing of the past.
- The Ruby code is more readable to the human eye.
Ruby’s readability is suggested to be caused by the lack of braces, parentheses and semicolons. But I believe the design, especially that of its libraries, is what makes Ruby resemble English, and results in more readable and concise code. Ruby’s strengths are semantical, rather than syntactical. But I digress.
In English, punctuation is essential to quick readers. Our mental parser splits larger chunks of text into smaller pieces—tokens, if you will—and scans those for keywords which form a summary of the text we’re reading. We use commas, periods, and quotes to identify syntactical tokens, and determine which parts of a text are worth focusing on for a moment.
This is an old argument: Imagine reading an article with no punctuation, or, to be less extreme, no capitalization or spaces between paragraphs. The overflow would have our brain scanners do double as much work, and would still result in a poorly-comprehended mental summary.
The same applies for programming languages. Curly braces, parentheses, and semicolons are the most notable offenders. The Web 2.0 generation loathes them, sometimes passionately. But come to think about it, these are exactly what we look for when reading someone else’s code; and no, begin...end blocks can’t substitute {...}, simply because they don’t stand out.
I notice this most with Java developers. These people have developed built-in, mental pattern-matching rules for code. Believe me, they too know Java is ugly, but it’s verbosity could actually help them when reading, or scanning, large portions of code. They immediately notice deeply-nested if clause, unchecked errors, and bad practices.
I’m not saying we should all go back to Java. But when you’re going to work on your Next Big Language, don’t forget that you write once, read many times. Make it easy for everyone else to scan code.