260 points · by kamaal · 13y ago · 130 comments
When I write in another language I spend a long time looking for a library like the ten I'd find in CPAN, sometimes I find one but often enough not, then a long time complaining about how if I used perl I'd have access to the perfect CPAN module and therefore already be done with the whole project, then basically reimplement the CPAN module in the smaller inferior language, then finally write glue logic to link stuff together.
I never fail to be amazed when I see pages and pages of an inadequate homemade xml parser written in an inferior language or maybe a blizzard of regex, and then hearing bragging about how in Perl the elegant alternative language code would closely resemble line noise. No, in Perl, those pages and pages of buggy code would instead closely resemble one line: "use XML::Simple;" Repeat a zillion times over.
My "perl" programs / systems actually shrink in length over time rather than expanding, which is unusual in smaller languages.
Perl has integrated debugging. Perl has pluggable runops so profilers can be attached to the platform (e.g. Devel::NYTProf). Distribution == CPAN and the 'make dist' system from ExtUtils::MakeMaker, again built in.
The introspection is -different-, perhaps, but I'm not sure I'd say it's better or worse.
Nothing meaningful? You set it to break into the debugger when that exception is thrown, and then debug it. I'm honestly not sure how this is any different an experience to in java - any java application not actively being debugged will write a stack trace to its log file and either exit or move on to the next request too, no?
Also type erasure.
Funnily enough, they're both examples of the same problem, stitching new features onto a language that was not at all prepared for them.
EDIT: I just used "strace /usr/bin/java -jar myjar.jar" and saw what looks IO but I'm not familiar with strace output yet. It looks like a handy utility though. Can you give an example of something that you expected to see but didn't when you tried it?
Interesting. It never occurred to me to want this. What sort of use case is this for? It seems Perl is capable of something similar:
use Enbugger::OnError 'USR1';
Then 'kill -USR1 pid' and your process will jump into the debugger.learn more here: https://metacpan.org/module/JJORE/Enbugger-2.013/lib/Enbugge...
Shockingly, attaching to running processes has been a feature of UNIX for decades.
Knowing Perl, it probably is possible, and I just never learned about it.
The java 'runtime' is hardly Java. Its like saying Pentium is C.
Java the language is hardly comparable with a scripting language like Perl.
This is a fact: <opinion here>.
Java calling anyone else's stack traces is backwards and hilarious, and only going to get better in about 15 years when java finally gets lambdas.
When I was at Google, the opinion among some of the SREs I knew was that Java there was better than elsewhere so you actually did get reasonable debugging stack traces, but the C++ libraries there were still significantly easier to debug problems in than the Java ones.
Yes, I know that those AbstractFactoryFactories let you produce convenient higher order abstractions, but when things go pear shaped, they can make it really hard to figure out what was supposed to be happening, let alone where it went wrong.
http://stackoverflow.com/questions/4185665/guava-equivalent-...
With all due respect to the Java runtime (if not its memory use :-( ), it is part of a totally different ecosystem compared to the usual suspects of the scripting languages.
(And I'd argue that it is always easier to debug a scripting language than C/C++/Java, except maybe just for long running server processes.)
When I took the job at Blekko they said "We do most of our stuff in perl" and I was dubious about that.
However, now that I've been exposed to V5 for a couple of years and have probably written a few thousand lines of code in it, I find its easier to write a quick hack in than Python, and it certainly has a better 'command line' feel than Java. But it wasn't until I started coding up a quick CMS type gizmo for making HTML pages that I truly "got" the power of CPAN backing it up. There is a lot of stuff there. Folks like me who gave up on the language in the V3/V4 days as "hopelessly hacky" should re-visit it.
http://stuff.mit.edu/afs/sipb/user/marc/hotjava/doc/people.h... (top left corner)
I've still to come across a language that lets you get your ideas down as quickly. It's full of fantastic time savers, e.g. the for(<>) construct and the format output functionality cover a bunch of common use cases in minimal keystrokes (let me pipe in some data, analyse it, then spit it out in a clean report).
It can hurt readability but for small one offs, it often doesn't matter.
Perl's autovification allows me to build a data structure at parse time with code that is trivially verifiable. Python forces me to sprinkle the code with a thousand tests for whether or not the field is initialized yet, or write extra code to define things like defaultdict instances (with syntax that I always have to look up, and which in my experience most python programmers don't understand).
Not to mention that if I want to use an OO syntax for that data structure I have to write extra code defining a class for it (and inevitably be yelled at by the pythonista security branch for all the __whatnot__ methods I forgot to define).
Python's comprehension/generator syntax is nice, though, and doesn't have a clean analog in perl. One thing it does do well is chaining up "filter" operations on aggregate data structures in a clean way. And that has value and is worth emulating. But honestly most of the rest of the language is junk compared to perl or ruby.
As for regexes - while they are somewhat clumsy in python, they don't have to be defined distantly:
m = re.match(r'(\d{4})', buf)
if m:
print "year: %s" % m.group(1)
The only thing that really bothers me about the above is the need to separate the assignment of m from the test.Re comprehensions: seems to me they are just Python's version of Perl's map and grep.
grep:
@good = grep { $_->{width} > 9 } @crates;
good = [c for c in crates if c['width'] > 9]
map: @squares = map { $_ * $_ } @nums;
squares = [i*i for i in nums]
Which is better? I think Ruby's way is the best, and Perl/Python are a wash here.Now, on the autovivification note, I wonder if we can make a Python class that has the desired behaviors. Like:
c = PerlishStruct()
c['foo'][17]['bar'] = 'baz'
You don't really think it's junk, do you? Perl, Python and Ruby are extremely similar; I'd say Perl's more ergonomic, but messier; Python's cleaner, but sometimes awkward, and Ruby pretty much has the best of both worlds. m = re.match(r'(\d{4})', buf)
'map' is more general than just the single, convoluted statement of list comprehensions, which really seems as a kludge from unwillingness to accept multi-line lambdas. So something new was invented that had to be learned; then it was argued it is a boon. (Like references in Perl. :-) )(There is some defaultdict functionality for autovivification in Python iirc.)
Yeah, they are all similar. I don't know enough Ruby to have an opinion.
And then there are a pile of modules that implement python-style generators, some using https://metacpan.org/module/Coro (co-routines implemented as threads), some using crazy hacks:
https://metacpan.org/module/Compile::Generators
It's a shame really, since all the building blocks needed to implement a useful mode for writing one-liners are there. In fact, I have a work in progress module that tries to address this issue: https://github.com/gvalkov/python-oneliner
It looks like a fantastically expressive language, but i fear the learning curve would be too steep for my time invested to pay off - others would have to spend the same time to learn it as well, negating any code sharing / reuse in my org (we don't use J).
I found others i had to share code with weren't as interested as me about writing maintainable perl code - i got really fed up with a patch work of "write only" perl scripts performing useful functions in prod. From DB maintenance tasks to general housekeeping, to work-arounds for prod app issues that never got prioritised for strategic fixes.
I found in practice python code produced by most others was easier maintained: it seemed to more or less force people to write more readable and therefore, maintainable code.
I also viewed the fact that Python was one of the premier languages across so many problem domains (Systems, DB, GUI, Web, Large data, GPU, etc.) as being a sure fire payoff for any time invested in it.
In environments this size it's not any one persons actions dictate what becomes the status quo: different groups will have different agendas and therefore priorities and views. I guess i was lucky that everyone else was either willing to give Python a go, or was easily convinced.
FWIW over the past few years it's proven to be a good choice for us. There are still O'Reilly books float about, esp between the newcomers but there's no zealous "where's my camel book!" shouts anymore.
What do you mean by "readable" and how does Python seem to enforce that?
Unmaintainable? Who cared. Got shit done. Too many ways to do things? Who cared. Got shit done.
I have this totally false feeling that BACK THEN* we wrote IRC bots and we were happy. And `perl -e '"A"x800'` was the destroyer of worlds.
* - shit, I just realized I'm young.
Interesting how I consider Perl an 'old' language, and the others new languages. I guess it says more about how revolutionary Perl was at the time and how quickly it became widespread. The only other language I know of that went from 0 to everywhere in under 5 years was Javascript.
Pascal is 42, C is 40. Lots of fun info on that page.
int i 4;
and the assignment operators being the other way round:
a =+ 2;
The point is, when discussing the age of a language, how important is the degree of change over time? At what point is it a new language? The same is true of human languages. I can understand Shakespeare with little trouble, but I miss some points unless there are footnotes. I can get a bit of Chaucer, but far from full comprehension. Beowulf? Not a prayer. But it's all "English"...
Hm. If we do this, then C++ is merely one 'capstone' on the history of Algol development, which is about as old as Lisp is.
Scheme, for example, is a decade older than Common Lisp, but it's still commonly considered a Lisp (no pun intended).
PHP was first created in 1994, so it's 18.
I'd peg Python's coming of age around 2001, although I could be wrong about that. Ruby is even fresher out of the oven, not really reaching the limelight until 2006.
But for my own stuff I still reach for Perl. Best testing infrastructure on the planet and that, in combination with CPAN, lets me get shit done.
https://groups.google.com/group/comp.sources.unix/browse_frm...
Perl Kit, Version 1.0
Copyright (c) 1987, Larry Wall
You may copy the perl kit in whole or in part as long
as you don't try to make money off it,
or pretend that you wrote it.I had thought someone had done a perl 1 release that built on modern systems, but on a quick hunt I can't find it.
See for example https://github.com/mirrors/perl/commit/8d063cd8450e59ea1c611... for the perl 1.0 annoucement (click on the [...] link to get the full commit message).
My more active interest in perl was pre-git :)
It might be fun to see that run against the Perl core.
I also like looking at the number of lines of code. If your features go up while complexity and lines of code go down -- that could be a good sign.
I have been working as a programmer for 25 years and started using Perl in 1993 or so. I cannot express what it felt like to have this incredibly powerful tool that seemed to integrate all of the sed, awk, shell, and C code that I had for research. Using Perl absolutely felt like magic, particularly for analyzing text.
I love Python, Ruby, and Lua too, but Perl will always be the tool that quickly gets things up and running.
To me Perl is awesome :) Too bad I do PHP for a living, but I still enjoy it when doing something for myself. Like last time I learned about web framework Mojolicious ( http://mojocasts.com/ ) and built http://gotldr.com and http://hntldr.com leveraging Mojolicious and Redis - https://github.com/hippich/perl-tldrer . It took me few evenings, but I really enjoyed tinkering it.
Perl is a very handy and powerful scripting language but it should not be considered as a durable solution. Whatever is quickly hacked using Perl should be probably rewritten in a much more structure language, especially if you plan on maintaining this code.
... in any language should probably be cleaned up if you plan on maintaining it.
Perl6 is looking quite fresh considering how old you think it is. I just submitted an article I'd seen to HN which shows how a formula like...
4.7kΩ ± 5%
... can be parsed inline with Perl6 code.It's interesting to me how often people cite "Unicode in code" as some sort of amazing thing. I once posted on S.O. about the idea that maybe we should have a programming language where the vast array of options in Unicode were exploited to make things like Regular Expressions more readable (avoiding the backslash plague alone would be worth it).
I got smacked down by people complaining that they didn't know how to type anything but ASCII.
Sigh.
re: Unicode - Perl6 does already use unicode characters for some of its operators. Take the Hyperoperator »« (http://perlcabal.org/syn/S03.html#Hyper_operators):
my @a = 1..5;
my @b = 6..10;
my @c = @a »*« @b; # => 6, 14, 24, 36, 50
And there are >> & << synonyms for those who find using unicode chars too odd: @c>>++; # => 7, 15, 25, 37, 5 |
\|/
http://stackoverflow.com/questions/7617852/whats-the-differe...Do people just prefer one function with a bunch of fiddly little enums or something?
Now bear with me for a minute while I explain you this whole thing.
Have you worked with a language where your though tool just wasn't for you? Have you felt that language was pushing down its own self believed principles down your throat? What happens when programmers face such situations? They just leave the tool and go to something else. Perl is one of those few tools that adapts to the programmer, rather than expecting the programmer adapt to it.
Now like every other design choices you can ever make, it has its own tradeoffs. Being flexible, adaptive, powerful and quick to evolve means at times you have to sacrifice a little consistency. You can sure present your arguments and your design perspective against it, but your design again will have its own trade offs.
Why so many different ways of doing things? For example why do we have something like 'map' and 'foreach' in Perl? You won't understand this when you have used and written code that leverages these keywords to their power. Its more or less like explaining why Ice cream is delicious to somebody who has never eaten it. Unless you taste it yourself won't truly understand.
Perl is quick to learn. You can learn as much Perl to do the kind of work you can do in Python/Java/whatever. But as you learn more Perl, you become productive at solving problems. You can do it quickly, with succinct code with more powerful syntactical features.
EDIT:Corrected typo.
croak(): (slang) To die[1]
confess(): to provide information, commonly[2] as one is dying[3]
carp(): To complain, often at length and of minor details[4]
cluck(): Not actually sure about this one, although 'clucking their disapproval' seems to be something of an english idiom.
So yeah, there's some logic to the choices, even if it is rather whimsical. It's a valid point to say it's not immediately obvious, but it doesn't take long (from experience) to figure what they do and out which one you want for a given situation.
[1] http://www.grammarphobia.com/blog/2012/01/croak.html
[2] Obviously some religions promote regular confession, but the 'deathbed confession' is afaik common even among the less pious/religious.
Where are the Perl-hating trolls coming from on HN?
(I thought Guido said that it was time to stop trolling, so it isn't Python people now?)
I don't hate Perl (I first learned CGI programming with it), but I do think there are better ways to write maintainable, enterprise scale software. There are two main problems with Perl (as I see it): 1) The language is so permissive that it allows newbs to write bad code but still obtain results. Habits, both good and bad are learned! 2) Perl experts seem to delight in writing code that's "tricky" (for lack of a better word). It's like a contest to see who can wring the most out of one 80-character line of code and it leads to mid-to-low functioning Perl programmers being confused.
Modern Perl and other recent books push people towards developing good habits.
The current generation of experts tend to either put our tricky in very well encapsulated CPAN modules, or comment the hell out of it, or both ... or if at all possible, stick it into a paste site somewhere for other people to go "whee!" at and do something sensible in the main codebase.
Your complaints about perl were absolutely valid a decade ago ... these days there's still some truth to them, but we've grown up a lot since then :)
How is this different than any other language? You can write bad code in any language. Perl might allow for more obfuscated code which really makes it harder to read - but that again reflects on the programmer - not the language. Take a look at a code in PHP, Python, C, or any language written by "newbs" and you will see poor practices used everywhere.
I can't see any relevance for a professional choice if newbies can shoot bigger holes in their foot with a certain tool.
That is a natural result of a powerful tool.
>> Perl experts seem to delight
Anecdotal. Ten years old description of half humorous use (and exercises). Also very different from best practices even then -- and especially different from how many/most work today.
Let me also note: If Perl wasn't better in many ways, you trolls would make serious arguments instead of "experts seem to delight"... [Or as you wrote above "Twenty-five years already? Now it can retire with full benefits."]
But I'll bite a little. Perl has the best OO system of all the scripting languages (Moose). The CPAN is the gold standard for scripting languages (and probably everything else). The testing culture is afaik second to none. The same goes for Unicode support. And so on.
I won't explain myself, smoyer's example (except the 'hate' part) pretty much sums up what I think about Perl. And yes, I believe it's a great language, although looking from a state of development of modern languages point of view, objectively speaking, it's a bit outdated language. And therefore, in my opinion, will find less and less applications in the future (and yes, Python is and will be its main competitor in many fields).