Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Just about any programming language can be made readable, with sufficient discipline. But it shouldn't require "discipline" to have basically readable code.

Python is like the opposite of Perl in that respect. It's inherently readable, and you have to go out of your way to make it difficult to grok what the code is doing. (Ruby is somewhere in the middle, but Ruby is more eloquent than Python, so I'll take a little clarity risk for the potential of even greater clarity.)

There's a joke running around Twitter about how it's hard to tell the difference between Perl and a cat stepping on your keyboard. You'll never see that for Python or Ruby.



That Python is fundamentally more readable is a myth. Unless by "readable" you mean that any Python program is superficially more visually similar to other Python programs than are programs in other languages. Syntactic white space will do that.

In comparing Python, Ruby and Perl, each relies to a certain extent on symbols in the code to express meaning. Python uses symbols very sparingly, and those it does use are either very much like other languages or established patterns from mathematics, even going so far as to ban braces for indicating structure--nothing is exotic. Perl is the opposite extreme, with to sigils encode variable context (which is a concept foreign to other language) and complex regular expression and quoting schemes built into to language. Ruby sits very much in the middle between these languages.

The use of all non-word symbols to densely encode meaning helps reduce code size at the cost of apparent readability. That's why you think Ruby is "more eloquent". Perl can be even more expressive than Ruby, but it's compactness can intimidate people, leading to defensive "humor".

Real readability comes from good structure and explicit code, whatever the language. It is especially important for developers using dynamic languages to document the contents of their data-structures.

If Python tends to be readable, it comes from a culture that values readability and focuses heavily on choosing a single, consistent style. Not from any inherent technical factor.

This is a nice piece on code readability in real life terms: http://www.pgbovine.net/python-unreadable.htm (TLDR: code may be readable in over small sections, but what really matters is whether you can understand the whole program. If you get lazy, you will make a mess. Be explicit.)


You can quote all the "facts" you want, but I've done a lot of both Python and Perl, and it's a lot easier to walk cold into a bunch of Python code, even badly written Python. What you call "superficially more visually similar", I call consistency. If I have to use conscious thought to figure out the structure of the code, it's taking from the conscious thought I need to understand its function.

And yes, Perl is even more powerful than Ruby when it comes to making code compact, but compactness and eloquence are two different things.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: