6 ms·
Readable Perl (compared to lang*)
NO FLAMES PLEASE.
Another i++ of perl's <blah> is not required.
What have been the successful trade-offs interms of readability in <language>?
CPAN Power
http://search.cpan.org/~fxn/Acme-Pythonic-0.46/lib/Acme/Pythonic.pm :P
http://search.cpan.org/~shancock/Perl-Tidy-20090616/lib/Perl/Tidy.pm
http://search.cpan.org/~elliotjs/Perl-Critic-1.105/lib/Perl/Critic.pm
Lots of modules((like Class::*) to simplify boilerplate code which inturn enhance readability.
Flowcharts[not exactly related to readibility]
http://search.cpan.org/~jnagra/Perl-Visualize-1.02/Visualize.pm
http://search.cpan.org/search?query=GraphViz&mode=all
http://search.cpan.org/~tels/Devel-Graph-0.12/lib/Devel/Graph.pm
- Locke1689 17y agoI notice the conspicuous omission of any Python or Ruby in that comparison (i.e., the languages which most directly compete with Perl's historic specialty)... One thing that struck me is just the shear amount of features and ways to do things that are built in -- whether it's good or not. For example, the "unless" operator strikes me as very useless. It certainly doesn't save any typing and it seems that the existence of many ways of doing the same thing makes it more confusing, not less. That said, I'm definitely in the "Perl has serious readability and maintenance problems and Python makes me weak in the knees" camp.
- kingkongreveng_ 17y agoPerl is perfectly readable. Go find me perl I can't read on CPAN. Like C++, perl greatly rewards expertise and experience. If you want to be able to read everything inside two months, well, go elsewhere. But I'd say you're missing out.
- amix 17y agoI think you got a point. Other well designed languages don't require an expert level for understanding of well written code. Perl (and at some extent C++) requires a lot of knowledge and experience before you can read code. I, for example, don't find @_ that readable or logical - it can mean anything and in Perl operators usually have different meanings depending on the context (which makes it even harder to read code). So Perl is readable if you are a Perl expert - for everyone else it's pretty unreadable.
- thwarted 17y agoOf course @_ could mean anything, but it means just one thing, which is documented in the perlvar man page: @_ Within a subroutine the array @_ contains the parameters passed to that subroutine. Access to the man pages does not make one an expert, anyone can read them. I seriously hope that anyone who is intending to successfully understand or modify code know enough about the language it is written in to actually be able to read it. There are idioms in every language, especially in syntax. Python's inheritance declaration looks like a function call or an argument specification. Ruby's uses < to indicate inheritance. PHP and Perl are more self-documenting in this regard, using "class _subclass_ extends _baseclass_" and by assigning to a variable named ISA within a package respectively. Python's decorator syntax is non-obvious, and uses a perl-ish sigil to boot. Ruby using sigils to indicate scope (vs type, which is how it is done in both perl and older BASICs) is non-obvious. Python syntax for single element tuple creation. PHP's arrays allowing both integer and string indexing in the same array, and its "hashes" or "dicts" keeping order, leads to idiomatic code. Perl assignment list expanstion when using arrays and hashes as subelements on the LHS eating up the rest of the input is idiomatic. unless is idiomatic in perl, but only because few other languages have that kind of construct, and instead force you to use an if-not, which isn't always as readable. Perl's map and sort look like they can take closures, but they're really BLOCKs which is slightly different. The difference between Proc objects, blocks and lambdas and how they can be converted between each other and called in ruby is idiomatic. Latin is readable if you speak Latin -- for everyone else it's pretty unreadable.
- amix 17y agoI will reference to Steve Yegge's rant on Perl. It has a lot of examples on Perl operators that are overloaded: http://steve.yegge.googlepages.com/ancient-languages-perl http://steve.yegge.googlepages.com/ancient-languages-perl - - and how their man pages isn't a big help. While other languages of course have their special syntax, Perl is very extreme in this regard. This is best illustrated by the following diagram of special Perl operators (where most of them are only found and used in Perl): http://www.ozonehouse.com/mark/blog/code/PeriodicTable.pdf http://www.ozonehouse.com/mark/blog/code/PeriodicTable.pdf
- Locke1689 17y agoPerl can be readable. However its wide and varied language features make it easy to make it unreadable. I have nothing against Perl used in good hands by good people but that can't always be guaranteed. The unless operator is the example of one tiny special case (of an if statement) that got its own built-in. My feeling is that unless you have a number of very good usage cases for a feature and it greatly saves time and energy it should not be added as a built-in to the language. It all comes down to this: Perl doesn't have a "Right Way"(TM) of doing things. Many people (perhaps yourself) feel that this is a good thing. I simply believe the opposite.
- mst 17y agoI consider unless to be one of my favourite things in perl that would fit into other languages. The key to the multiple ways of doing things is to make code clearer - you have to look at it not so much as "there's more than one way to do the same thing" as "many things compile down to the same opcodes on the VM". I suspect in other languages lots of things compile to the same thing - x = x << 1; x = x * 2; should produce the same thing. But if I was affecting a bit vector I'd use the former and if I was affecting a number I'd use the latter - because while the operation at the machine level might be the way, they are conceptually two different things and I want to express the concept to the next developer to look at this code. The fact that perl intentionally supplies lots of features to allow me to write my code to express my intent as clearly as possible is an advantage to me, just as I find the english language an advantage over, say, lojban.
- forinti 17y agoI think comparisons usually don't take into account that Perl code is very compact. If you were to unroll a perl 3 liner into a Java 30 liner, would the Java code be as readable? I think not.
- pasbesoin 17y agoYes. I often find the "context switching" in scrolling around a lot more inhibiting that the density of e.g. Perl syntax. Perl syntax also builds on a rich heritage. If you are familiar with that heritage, it's a lot more evident. Conversely, as you learn Perl, that heritage is elucidated. (For example, learning Perl in a Windows environment (I know...) and then moving to UNIX.)
- fexl 17y agoIt is true that script kiddies write ugly and unreadable Perl code. It is also true that professionals write highly disciplined and beautiful Perl code. Incidentally, on the subject of object orientation, I concur with Sriram Srinivasan's preference for Composition instead of Inheritance. He writes in "Advanced Perl Programming": "Then when John Ousterhout's Tk came along, I marveled at the ease of creating widgets, even though it was in C and provided all the features that Motif provided (and much more). The Tk architecture used composition, not inheritance. I have been suitably chastened."
- onewland 17y agoscribd link is broken
- tomneo 17y agoa note ruby's syntax philosophy is a bit on the lisp side. python's syntax philosophy is pragmatic. perl's syntax philosophy is on the linguistic side. thats is why its "bare syntax" like sigils and all are wierd like the case endings in english. but they follow laws which when groked can be abused. like say "ness" can be added to adjectives to create nouns and so on. eg) in ruby or in python varible names are like this, foos = ["foo","bar","foobar"] in perl you simply say @foo = ("foo","bar","foobar"). since perl treats $foo differently from @foo. (but most however do use @names due to their natural inclinations). see http://www.csse.monash.edu.au/~damian/papers/HTML/Perligata.html http://www.csse.monash.edu.au/~damian/papers/HTML/Perligata.... if you can grok gramatical cases.
- balding_n_tired 17y agoI find myself increasing the proportion of Python I use, really for two reasons: the libraries that come with PythonWin; the PythonWin environment, not least the REPL. I agree that Python is rather prettier, but this has very little to do with it.