4 ms·
For stuff like string handling, text processing and even variable interpolation, Perl blows Python and Ruby out of the water (and despite criticizing Perl's reg
by jonathansizz 16y ago
For stuff like string handling, text processing and even variable interpolation, Perl blows Python and Ruby out of the water (and despite criticizing Perl's regex, Python ended up copying it almost identically). Much of this power stems from Perl's much-derided use of sigils (e.g. $scalar, @array, %hash) and context.
Personally, I find Perl's
$header2 = "Dear $title $name,";
to be more readable than Python's
header2 = "Dear %(title)s %(name)s," % vars()
Another benefit to using sigils is that it's immediately clear when reading code what type of data is being referred to, while in other languages you often have to read back through the code.
On the other hand, Python has done a great job in positioning itself as the new BASIC (in a good way), and so of course Python gets much more exposure in the educational setting and thus has greater mind-share amongst younger coders.
Python is simpler and easier to learn well than Perl, but nevertheless Perl is a very powerful and useful language that takes a lot of undeserved criticism (e.g. see the comment of wyuenho in this thread).
Incidentally, I found the Google Trends link hilarious, as all the news snippets on the right of the page refer to people called Ruby and actual Python snakes (hey, maybe people are searching for things other than programming languages..)!
- wyuenho 16y agoI think what you have said is quite fair. However, I must clarify that I wasn't criticizing Perl's use of sigils, I was criticizing Perl's use of punctuations. There's big difference. Sigils does indeed make the types of variables clear, tho I find that context alone is enough. Objects in natural languages don't have to have types in their spellings to convey their categories after all. The use of genders in some languages is superfluous, Chinese doesn't require that. All I'm saying is, Perl requires too much more mental power to process than Python because of it's large vocabulary and inconsistent grammar rules. It is really a natural language, but a natural language is not needed for programming.
- bellaire 16y agoYeah, punctuation, wow. I mean, here's a sierpinski triangle generator: 32.times{|i|i.upto(31){|k|putc~k&i>0?32:35};puts} Oh, wait. That's Ruby. I meant to say: <?for($n=33;$k=--$n;print~\xf5)for(;$k;)echo-$n&--$k?~\xdf:~\xdc; Oh, sorry! That's PHP. My bad... here we go: print map($%&$_?$":'#',0..~($%=$_)),$/for-32..1 There we go... You're right, Perl is so much worse! The point is, of course, you can write ugly code in any language, or you can write beautiful code in any language. Python actually is fairly legible nearly all the time... n=32 while n:print''.join('# '[-n&k>0]for k in range(n));n-=1 but that comes at the cost of added verbosity and reduced flexibility . Whether that's better is a matter of taste, not of fact.
- tene 16y agoI'm sorry, but which grammar rules in Perl 5 are inconsistent? I've taught Perl 5 professionally, and while I certainly do acknowledge that Perl isn't optimal for learning, "inconsistent grammar" is not on my list. It does have a more-complex grammar than, say, lisp, but it's still an extremely consistent grammar, as far as I've been able to tell. I also disagree with the claim that a large vocabulary in Perl is a notable issue. The size of the Perl grammar and language is sufficiently smaller, in my experience, than the size of all of the library APIs that I have to deal with when writing Perl programs.
- btilly 16y agoFor stuff like string handling, text processing and even variable interpolation, Perl blows Python and Ruby out of the water... I agree on Python. I disagree for Ruby. It is a tossup. In most cases they are equivalent, Perl has autovivification, it is easier to interpolate functions into strings in Ruby. All in all it doesn't matter.