7 ms·
Most people talking about Perl are quick to groan about its ugliness. I’ll first note, most of them don’t know Perl... OK, I'll bite. I know Perl. Perl is ve
by mhartl 18y ago
Most people talking about Perl are quick to groan about its ugliness. I’ll first note, most of them don’t know Perl...
OK, I'll bite. I know Perl. Perl is versatile. Perl is powerful. But Perl is Ugly with a capital 'u'. Give me Python or Ruby any day.
- SwellJoe 18y agoMost folks who say Perl is ugly are talking about one of two things (or both): Sigils or Regular Expressions. Regular Expressions have turned out to be so useful that they've been slurped into every modern language (and using the Perl interpretation of regex to boot), so it's pretty much a null statement to say that Perl is ugly because of regular expressions...because it means every language is ugly. This is usually what people mean when they call Perl executable line noise...but is it really the fault of Perl that folks write regexes that are longer and more complex than is readable? Perl just happens to be a culture that is steeped in UNIX history, and sometimes we reach for a regex before other more readable tools...it's a failing of the developer, rather than the language. I find regexes in Python quite ugly, myself, since they're in the ghetto of a library rather than a first class part of the language. In Perl, you can take a reference to a regex, or turn it into an object, and of course, you can use regexes extremely concisely and in one-liners and quick throwaway scripts. I consider this a worthwhile tradeoff. Sigils, on the other hand, are core to the language and Perl uses them more heavily than almost any other modern language (PHP and Ruby both use them to some degree, but nowhere near the degree of Perl), so if it's not the sort of thing you like, then Perl is not the sort of thing you'll like. This one, at least is a point of real difference. I don't find sigils particularly offensive or particularly nice; I'm pretty much indifferent to them. Though I am happy to know that the inconstant sigils of Perl 5 are going away in Perl 6, as they've been a source of confusion for me on many an occasion (though less so when I'm working with Perl a lot--I haven't written a bug in weeks due to that particular quirk, and I don't think I've ever written one that the compiler didn't catch immediately). References are also problematic, and will also be made prettier in Perl 6 (in particular, function references are automagic when it is apparent that's what you want to happen). My first dynamic language (if I don't count tinkering with ARexx on my Amiga when I was a kid...and I don't) was Perl, and I worked with it for several years. Then I went to work in a Python shop, luckily with some of the best Python developers in the world working on some of the most interesting Python code going (if you use Python, you use some code written by several of the folks I was working with), and I really enjoyed working in Python and found it "cleaner" than the Perl I was accustomed to. After a few years with Python, I found myself working with Perl again...and I set myself the task of learning it a bit more systematically then I had the first time around. Turns out, Perl is a quite pretty language...and I like it better than Python. Both are very fine languages, but Perl suits me better. I was merely judging some extremely nice Python written by masters of the language vs. random snippets of Perl found on the Internet, and unsurprisingly Perl fared poorly in the comparison. Ruby, on the other hand...I might actually find it prettier than Perl--it has a lot of the things I love about Perl, and very few of its rough edges. Though I'm not fond of the seeming standard usage of "end" for blocks. You guys know you don't have to use those, right? I mean, it's not Pascal. You can use curly braces, and it'll work just fine...and bouncing on % works. I'm also not fond of the occasional verbosity of Ruby that seems to be a function of its "everything is an object" philosophy. Anyway, beauty is in the eye of the beholder...and conciseness is one of my primary "beautiful" qualities. And, if Perl is anything, it is concise (at least, it can be, and for almost any task).
- trominos 18y agoThe ugliest parts of Perl (in my admittedly not-exceptionally-well-informed opinion) are dereferencing variables and automatic list flattening. I honestly don't know what kind of crazy design process could possibly lead to the way Perl handles nested lists. $a[0]->[0]? @{$a[0]}? Why? God?
- william42 18y agoIt handles lists that way because of the braindead idea of sigils which, in order to be semantically consistent, cannot have as an element of a list being a list.
- philh 18y agoI'd like to see you back that up. $a[0][0] does exactly what it looks like it should do: it takes the first element of the list at $a[0]. (Incidentally, this is exactly the same as the gp's $a[0]->[0].) The only problem sigils introduce is the -> in expressions like $a->[0]. ($a is a reference to a list, and you can't write $a[0] in this case because it will look at the list @a.) I'm not entirely sure why perl doesn't have good support for nested arrays and hashes, but I'm pretty sure it's not to do with sigils.
- SwellJoe 18y agoIt's historic. In The Beginning...Perl was a different language, a simpler language built to take the place of awk/sed/grep/shell in one mostly consistent package, and when it later obtained complex data structures, they were implemented on top of the existing semantics, which involved arrays and hashes that could only store scalars. I don't think anyone thinks list-flattening is a good idea, these days. And, of course, Perl 6 gets better handling of complex data structures...if I recall correctly, it gets an explicit "slurpy" sigil that provides the flattening behavior, but I don't actually work in Perl 6 yet, so I'm not sure of that.
- SwellJoe 18y agoIt has nothing to do with sigils. It has to do with the legacy of arrays and hashes only storing scalars in ancient Perl. Perl 6 does not flatten by default. (And, obviously, sigils remain a core part of the language.