4 ms·
Is Perl Difficult?
- aditya 18y agoSo, whoever wrote this clearly did not read the right perl documentation, everything the author talks about is VERY well explained in the perl man pages which are pretty much a source of gold. The argument that Python is better beacause it is apparently more readable is lame. To me, perl just feels a lot more expressive since I grew up "thinking" in perl. Bashing a language because you didn't read the right documentation and/or couldn't find it is just wrong. I agree that perl can be daunting to learn and that may make it more unmaintainable though, but if you haven't made the effort don't knock the language.
- greyman 18y agoAs I understand it, author tries to demonstrate that Perl is so-called "difficult to learn", and because of that, is not a good choice. OMG!! Something is bad, because it is difficult to learn?!?! For some reason I can't explain, I feel sad about that article.
- jbum 18y agoIs this article flame bait? Hmmm... Let's read the following posts and find out!
- softbuilder 18y agoI left Perl a long time ago and lately have been using Python almost exclusively. That said, statements like this: > insert the same bug into the X programs. raise an eyebrow. In my experience the platform and language determine what the what the bugs will be. Said more simply: You aren't going to have the same bugs in Perl that you will in Python, and vice versa. Certainly you could, but typically you won't. Also, the biggest problem with Perl isn't the language per se, it is the entrenched culture which is inclined to abuse of power and unclear coding, often in the name of "efficiency". Still, Python drives me nuts daily with small things. I can't think of a language or platform that doesn't. Better yes, but not at a level to pick on Perl. Oh, and I'm rusty but I'm pretty sure that regex is wrong.
- rplevy 18y agoI think you are right about there being an error. I didn't try running the code but it looks like it would match everything inside the html comment braces, but incorrectly stop at any occurrence of '-' instead of stopping matching only at '-->' which I assume is what is actually desired there. So it should be /(.X?<!--)(..X?)-->(.X$)/ instead. (Note I am using X as asterix because HN at the time of this writing converts asterisks to italics tags.) But other than that the Perl is perfectly fine. And it is easily readable if you know Perl.
- rplevy 18y agoI think this version would be clearer though: print $_ . "\n" foreach ((<>) =~ /<!--(..*?)-->/g);
- deleted 18y ago[deleted]
- jrockway 18y agoPeople always draw the wrong conclusions in articles like these. He shows a piece of code that uses a regular expression over implicitly-defined variables. I agree that's confusing; regex syntax is very terse, and there's nothing in there to help you learn it. (In regular code, variable and function names can help you infer from context what the other constructs do.) Secondly, it's hard to reason about code that does things that aren't written. "while(<>)" assigning to "$_" for "/.../" to use is confusing. $2 and $3 coming out of nowhere are confusing. The problem, though, is not with Perl; it's with the author's lack of knowledge of how it works. Regexes are nice once you learn them. Operating on $_ is nice once you expect that to happen. $1 and friends are quite handy. Finally, most Perl apps don't look like this. Sure, there may be something like this hidden over in an obscure subroutine, but most Perl looks like every other language. Here's a randomly sampling of Perl from my git repository: http://git.jrock.us/?p=Template-Refine.git;a=blob;f=lib/Template/Refine/Fragment.pm;hb=HEAD http://git.jrock.us/?p=Template-Refine.git;a=blob;f=lib/Temp... Basically, it looks like it would when written in any other language. It's not unreadable or crazy, it's just a program. Finally, here's a more readable version of his example: while ( my $line = <> ){ # or "readline" if you hate <> while( $line =~ /<!--(?<comment_body>[^-]+)/g ){ say $+{comment_body}; } } One more thing; from the article: Even so, I supect that most readers that know both languages, even Perl fans, will agree with me. Not true. I don't know Python, so of course I'm not going to be able to use it to write maintainable code. I do know Perl, though, and I bet I can write much better code than the author of this article. I should note that his program doesn't actually work. It won't work across lines, and doesn't allow "-" in the comment. A full-file parser would do a correct job, and one is available from the CPAN, so it would involve less code anyway.
- kingkongrevenge 18y ago> He shows a piece of code that uses a regular expression over implicitly-defined variables. His snippet is perfectly idiomatic perl code and I find it easily legible. His point is that it's pretty hard to parse that without having already spent some hours with the perldocs. Fair enough.
- 18y ago
- snorkel 18y agosigh Why is it all who moan about Perl immediately point to a regex written in perl and cry "Look! That's perl! It's unreadable!" No dumbass, that's a regex, and regex by the way, looks about the same in every language. It just so happens perl is better at regex than most other languages and perl coders aren't afraid to use it (and unfortunately many abuse it).
- mtts 18y agoHe's not. Read the example again. He's pointing to code that: - uses the implicit $_ variable - twice - and modifies what it points to The regex is just for dramatic effect.
- snorkel 18y agoHe didn't point out that directly but I do agree that $_ is overused among perl coders.
- kingkongrevenge 18y agoI don't think so. As long as there are no issues of nested scopes you should use $_ plenty.
- mtts 18y agoSo there's a bunch of Perl lovers kneejerkingly responding to this post that the author doesn't "get" it. Now I myself love Perl and code in it for a living and I think the author does in fact "get" it, it's just that he thinks Perl is a problematic language precisely because "getting it" is required to use it well. It's something he's explained a little further over here: http://www.prescod.net/python/why.html http://www.prescod.net/python/why.html You may disagree with him and feel that an easier language does not a better language make (I'm not sure I'm convinced either) but complaining he hasn't read the documentation is proof that you yourself haven't grasped what he's actually talking about.
- kingkongrevenge 18y agoAll he really says is that complex languages are harder to learn than simple ones. No kidding. His specific points are valid, except I'm not sure what's wrong with references in Perl. I still much prefer Perl over Python and C++ over C, and I would recommend my preferences even to a beginner. The steeper learning curves are justified by the power. I disagree with his assertion that you should choose a language on the basis of how easy it is to learn. I also think his Perl vs Python debugging claim is baseless.
- nailer 18y ago> I still much prefer Perl over Python > The steeper learning curves are justified by the power. What can you do in Perl that you can't do in Python?
- kingkongrevenge 18y agoSymbol table manipulation, source filters, run-time method generation via AUTOLOAD, proper closures, taint checking, lexical pragmas... I think you'd be hard pressed to implement something like Perl's Moose in Python. I'm not completely sure it's possible. There's a lot of tricky stuff that's easy in Perl but requires tons of hoop jumping in Python. Don't underestimate the utility of perl one-liners. You can't do them in Python, both because of the whitespace and because in practice Python is too verbose.
- snorkel 18y agoPerl isn't difficult, it's just quirky: Perl OO: In Perl classes are called "packages". There are no private methods or private members, everything is mutable. Sigils: @foo is an array, %foo is a hash, but $foo can either be a string (scalar), a number, a reference to hash, a reference to an array, a reference to a function, or a reference to an object. Built-in functions that operate on arrays (push, pop, foreach) do not accept references to arrays, unless put an @ sigil in front: pop $foo <-- WRONG! pop @$foo <-- Oh sure, OK! Lots of special variables: $ in combination with just about any other non alpha character means something in perl. The most often abused is $_, the default variable. Libraries and package files have to end with 1; or return some non-zero value. So sure, plenty of quirks of to learn, but so every lanaguage.
- pmorici 18y agoEvery time I look at Perl code I always go away pissed of for one of two reasons. A) The person that wrote the code did something super hackish and non-sesical which I attribute to the low quality of the language itself. B) I look at things like %, $ and @ and wonder why the hell I have to tell it what the variable type is. And don't even get me started on things like "Chomp" who's behavior changes depending on the value of some cryptic global variable $_\ @%#@#@^$&$*#%&@!
- gaius 18y agoThe person that wrote the code did something super hackish and non-sesical which I attribute to the low quality of the language itself. The language is only half of it, the other half is the culture. If you write Perl that uses an obscure (and perhaps undocumented/unintentional) feature to accomplish some relatively straightforward task, other Perl programmers will worship you as a God. The language and the culture are mutually reinforcing. Ruby is going this way as well. Python language and culture both place a premium on doing things the simplest and most explicit way you can. Over the long run, the culture makes the biggest difference.
- blader 18y agoYeah. So is VIM. So is emacs. So is driving an F1 race car or flying a fighter jet. Development isn't supposed to be easy to learn - but it is supposed to be efficient once you are proficient at it. And that is exactly what Perl is.
- BrandonM 18y agoAs I read this article, I couldn't help but think of the earlier submission on improving writing style: http://news.ycombinator.com/item?id=239147 http://news.ycombinator.com/item?id=239147