6 ms·
Long-time Python dev here, recently started picking up Perl (both 5 and 6). As with anything, learning another language will give you insight into how things _
by s_kilk 11y ago
Long-time Python dev here, recently started picking up Perl (both 5 and 6).
As with anything, learning another language will give you insight into how things _could_ be done, and you'll pick up a new perspective on programming.
More concretely, I've been liking perl because it's much more expressive than python, especially when writing small unix-y programs or scripts to control the machine.
And of course, sometimes it's just nice to have a variety of tools in your toolbox. We may as well ask whats the reason for learning Python when $LANGUAGE exists. The answer is always going to be some variant on "just because".
- mattbillenstein 11y ago"more expressive" is often a slippery slope to "I can't read and understand what I wrote 3 months ago" We read code more than we write it, so optimizing for typing time vs reading time is just losing the war to win the battle IMHO.
- DougWebb 11y agoI think you misunderstood what "more expressive" meant. It doesn't mean "more concise", though Perl can excel at that too. It means that expressions can be stated in more meaningful ways. do_the_thing() if $is_ok; warn_the_user() unless $is_ok; The if/unless pair, along with the ability to put conditionals either before or after the statement to execute, is just one example of Perl's ability to be very readable.
- chrisseaton 11y agoIf we're honest with ourselves these discussions are never really about anything more than taste and have almost no technical foundation, but with that said I don't think the trailing conditional is more readable. In the rest of Perl the order in the text of an action normally indicates the sequence of the side effects, but here the first thing to be executed is after the first thing in the text.
- DougWebb 11y agoLarry Wall is a linguist first, and the design of Perl's syntax reflects that. So I can totally buy taste being more important than technical foundation, in the same way good graphic design is done. These expressions with the conditionals on the end are supposed to reflect English phrasing. English isn't strict about the order of parts of speech; you can mix them around to change the emphasis. These expressions are the same; they're not meant to strictly indicate order of execution, they're meant to express programmer intent, the way one programmer might explain the logic to another programmer.
- chrisseaton 11y ago> These expressions with the conditionals on the end are supposed to reflect English phrasing. But nobody's ever explained why that would be a good thing to do. We say things like 'you can read it out loud and it sounds like English', without ever arguing why this is a good thing. Do most programmers even have English as a first language? I'm not sure aspiring to be like natural languages actually has any merit. I think we should aspire to precision and clarity. Natural languages rarely have those qualities.
- grayclhn 11y agoFrom DougWebb, explaining why this would be a good thing to do. >> These expressions are the same; they're not meant to strictly indicate order of execution, they're meant to express programmer intent. We can achieve perfect precision and clarity by naming all of our variables x1, x2, x3, x4, etc. But it's better to give descriptive variable names because it helps us and anyone else reading the code understand what it does. This sort of expression is similar.
- chrisseaton 11y agoI can't see any argument in there. 'meant to express programmer intent'? What does that mean? Basing programming languages on mathematical notation or something else would also of course be 'meant to express programmer intent'. Why are natural languages a better foundation for programming languages than, for example, maths notation or calculi? Everyone in the Perl community seems to think they just intuitively know it is, but can't explain why.
- mattbillenstein 11y agoThis is harder to parse in my mind than: if is_ok: do_the_thing() else: warn_the_user() In that you can see more or less visually what the intent is rather than having to mentally parse the text. But perhaps that's just personal taste. IMHO, expressiveness and conciseness are largely the same idea because when you talk about the former, you mean being able to bang out an idea in fewer lines of code yielding the latter. Having a complex grammar and a myriad of ways to do the same thing seems very neat, but in the end the productivity gained in the writing, you waste several times in the reading, so it ends up being a net loss. But Perl lost the dynamic language wars a long time ago -- I think perhaps some of the flavor got picked up in Ruby? And having a language read like English is IMO, a bad idea -- English is very ambiguous in many cases -- mimicking this in your programming language would be a bad idea indeed.
- marklgr 11y agoIt's precisely a slippery slope argument[1], which is generally much debatable. Perl somewhat indulged the nix culture tendency to write extremely concise and cryptic one-liners, but* this does not mean that verbosity is good and expressiveness is bad. [1] https://en.wikipedia.org/wiki/Slippery_slope https://en.wikipedia.org/wiki/Slippery_slope
- omaranto 11y agoI'm not sure I agree that that there is clear winner in expressivity between Perl and Python. In Perl dealing with nested data structures feels really awkward. And Python's list and dictionary comprehensions and generator expression are very handy and highly expressive. Anonymous functions are much more pleasant in Perl than in Python. The added flexibility in placing 'if' and 'while' in Perl is nice sometimes, but I don't think it is a huge advantage. Going over this (personal) list made me realized I'd probably like Perl 6 better than either Perl 5 or Python...