183 points · by ingve · 10y ago · 94 comments
Sometimes, Perl trades depth of knowledge for length and explicit minutia of code. It can be confusing if you are not familiar with the dialect, but terribly powerful if you are.
And behind the scenes, a lot of effort has been put into making DWIM (Do What I Mean) not only intuitive but often quite good at implementing an optimized solution (e.g. quite performant data representations).
P.S. Thank you, chromatic, for your continuing generosity and... I guess I will call it "belief", in the Perl community I encountered 15 years ago.
P.P.S. I never was a Perl "expert", and I'm woefully out of touch, these days. But the occasional bit I read leads me to believe that the above still pertains. And I'm curious to learn about version 6, which while a long time coming, really wanted to "take it to the next level". If and as it succeeds, it should be very interesting indeed.
I owe a lot to random Perl community people for helping pull me up (literally since I was a child) to the point that I could get a job, then get better jobs, and eventually choose my own work and support a family.
Its been years since Perl has been the main tool in my toolbox but there is plenty in ~/bin and I plan to give Perl 6 another go. Still, I think of Perl often and fondly.
Has anyone else ever had that "If I am ever wealthy I will help __some open source community__"? More and more I realize life is passing by and being wealthy isnt important to me at all. So I better just say thank you here. ;)
Perl had p5p to guide them, and various conferences and very close knit groups which I was proud to be a part of.
I'm now more in the node.js crowd, which is huge, but feels like there's no good guiding group. I'm a mod in #node.js but the traffic there isn't communal. The node.js mailing list gets about 5 posts a day. I don't even know where people go to ask/talk about Node any more. Is it stack overflow? Somewhere else? Or do people just flail about not really knowing what they are doing? Sadly it feels like the latter.
And yes, the documentation of perl modules still far surpasses anything I've ever seen in other languages.
The way I use Stack Overflow makes me feel dirty. Usually it starts when I Google an error message because I'm using a new (to me) combination of language/framework/module/plugin. My mindbrain and fingers conspire to automatically select the Stack Overflow link even though it might be 3rd result and #1 and #2 might be from the official docs of whatever technology.
When I get to SO I read the answers first. That is often enough to shake something loose in my brain about my own problem. If that doesnt help I'll read the question to make sure I'm reading the right thread. I only comment or answer on rare occasion because it means that 1. I ended up on an inappropriate thread but actually know the answer and 2. it happens to be a fresh unanswered question. Seriously, I hope some of you are using SO the way they want it to be used and clicking on ADs or whatever. ;)
I used to answer questions in IRC channels just because I was already hanging out there, knew some people, and hey- I got answers from this group I might as well give back. But on SO I dont feel any attachment to a community, its just about Internet points. And for those who arent keeping score its just get-in-get-out. Maybe its just me.
If you don't yet, I recommend you subscribe to the perl weekly: http://perlweekly.com it's a great, concise overview of what's happening in perl (5 and 6). A very simple, low effort way to give back financially would be to sponsor the newsletter via GratisPay http://szabgab.com/gratipay.html Obviously there are also many other ways, financial and non-financial, to contribute to the community.
The last time I looked at Python 3, Perl still had much better Unicode support. In particular, grapheme support in regexes, built-in casefolding, and easy normalization made a 100+ country project much easier.
The stability of the language, core libraries, and CPAN modules across major releases really helps with maintenance. Python's 2/3 break was a bummer for a lot of people for a long time that I'm glad to have (mostly) avoided.
And do you plan to update the book to cover Perl6 some time in the future?
I have no plans to update the book to cover P6; I think it does what it needs to do as it is now.
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".
Going over this (personal) list made me realized I'd probably like Perl 6 better than either Perl 5 or Python...
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.
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.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.
I use Python usually but Perl is simply faster at processing large amounts of text.
And while Python has made great strides in regex readability since the 90s, Perl's regexes are still more cleanly and flexibly incorporated into the language.
I think the very nature of Perl meant that I had to learn additional tricks to make the code make more sense when I returned 6 months later...tricks that I wish other languages embraced. Having your code not be obscure is the minimum, not the maximum you should be shooting for.
Also - I'd still write short scripts (basically glorified one-liners) in Perl vs Python. JS is getting up there, but still isn't as expressive as Perl.
Edit: And I say this with full respect for other languages, particularly Python that has done a lot for many areas of development
But here are some examples:
Perl often gets flak for "There's more than one way to do it", and sometimes that's justified: It's confusing to do things a billion different ways. BUT, sometimes you can use those different ways to be meaningful. So:
foo() unless (condition) vs if(!condition){ foo() }
They are FUNCTIONALLY the same, but COMMUNICATE differently. If you don't pay attention to the latter, then TIMTOWTDI will be an enemy. If you do, then it can really help.
Also: "not", "and", "or" - I wish more languages had these. && and || might seem to be the same thing, but there's no reason to cling to foreign symbols where native (for english speakers) symbols do the same. ! is particularly bad, since it's so small, can easily blend in to an adjacent paren, and yet REVERSES the meaning. Don't get me started on the terrible switch/case syntax that is perpetuated for no reason other than C did it.
Moving away from syntax, hashes/dictionaries/associative arrays/Js objects, these guys all have the same basic addressing style. If you're using them in a context where the key will almost always be present, why not use that?
instead of addresses[currentAddress] use address_of[current] (or addressOf[current]
Instead of building variable names that are 4-5 camelCase words, use the hierarchy of your structures to communicate more clearly.
variables are WORDS. Too few words doesn't communicate clearly, but too many is just as obtuse.
There are a great many "clean" bits of code out there - nicely structured, nothing wrong, but I'll still have to read the whole to understand a part of it. Similar to the semicolon argument: The reason I object to dropping semicolons is not that the statement needs it - but that I need to read the next statement to retroactively know if the statement needs it.
If you can write code so that a reader understands what is happening as they read, rather than understanding the whole and then viewing the parts in that context, your code becomes that much more maintainable.
Also, while Python's library ecosystem has grown a lot over the years, in Perl you can find so many modules on CPAN, ranging from very common tasks (like talking to a database / ldap directory / network service) through fairly exotic (at least in my perception: e.g. formatting datetime values in just the right way to feed them to MS SQL Server, figuring out if a given day is a holiday in a given federal state of Germany) to downright silly (but in a clever way: CPAN's ACME::* branch). You think of it, CPAN probably has it.
One thing I have grown to appreciate about Perl is its mentality of helping you getting the job done no matter what. Python is a - relatively - clean and simple language, where Perl is not ashamed to be messy, but it's oh-so-useful I just cannot stay mad at it. ;-)
Last but not least, the Perl community is awesome, there are so many friendly and helpful people around willing to share insights, code, and words of encouragement. (That is not to say other languages have bad communities, not at all!)
It is incredibly effective at helping prototyping rapidly small ideas.
> the Perl community is awesome, there are so many friendly and helpful people around willing to share insights, code, and words of encouragement.
And CPAN helps a lot too! It can be considered as an important part of what makes this community so special, it is a very serious repository of modules, I mean not only code: it is incredibly usable, with lots of documentation and a crazy test infrastructure (http://www.cpantesters.org/) that helps to build quality distributions.
The good thing with the Modern Perl book is that, before explaining the language itself, it explains the Perl philosophy. And then it explains about the community and the CPAN. Being modern is also about not writing code and re-using long-tested modules from CPAN with cleans APIs: it helps to compose quality code and make maintenance easier.
There are still so many negative tradeoffs in Perl 5 -- especially, and most crucially, for new adopters -- that I don't think it will ever make up the ground it has steadily lost to Python/Ruby/PHP over the last 15 years. P6 has addressed many of P5's most notorious faults, while perpetuating others, and quite likely introducing a whole family of newer, far subtler traps and pitfalls. All while being not particularly fast, poorly document (last I checked -- about a year ago), and like Perl 5, just plain.... zany.
That said, there are a lot of incredibly bold -- we might even say, "ahead-of-their-time" ideas in Perl 6 (just as there were in Perl 5, in its time), and I sincerely hope many of these will be carefully studied -- and I won't be surprised if some of them are incorporated to whatever "lingua franca" that ultimately emerges and ends up burying Python, hopefully not too long from now.
Sincerely, at this point (Dec 2015) I feel like python is well too far along to be buried. As you state, if something better comes along I too would welcome it, but, and correct me if I'm wrong, python has been around for 20+ years, I don't see it being buried anytime soon.
P.S. That was intended as VERY light-hearted ribbing, not as a snide remark.
Yes, the GIL - global interpreter lock (in python) is a reason if you are doing multithreaded stuff in a scripting language (which i think is a bad idea by definition because suddenly you are debugging problems in your program as well as the interpreter/runtime)
Perl 5 has an interpreter instance per thread, so it doesn't have a global interpreter lock. It will have other problems with threads though - you can easily run into deadlocks for example.
The third item in the threads perldoc, after the table of contents and the version, is a big, fat warning about how you shouldn't use them [1]:
> The "interpreter-based threads" provided by Perl are not the fast, lightweight system for multitasking that one might expect or hope for. Threads are implemented in a way that make them easy to misuse. Few people know how to use them correctly or will be able to provide help.
>The use of interpreter-based threads in perl is officially discouraged.
> Perl 5 has an interpreter instance per thread, so it doesn't have a global interpreter lock. It will have other problems with threads though - you can easily run into deadlocks for example.
Which makes threads more expensive than processes on *nix because you don't get the advantages of copy-on-write processes. Also most of the librarys that use perlxs modules aren't thread-safe.
i didn't 'pretend' that - that's a misstatement; still a big fat lock in the interpreter isn't a concurrency solution at all, instead of running concurrently your threads will be mainly blocked on the lock.
Interpreter threads is an approach that does without a global lock, but as i said it is still a pain to debug the result - as you are effectively debugging both your program and the runtime.
> Which makes threads more expensive than processes on *nix because you don't get the advantages of copy-on-write processes.
threads are not copy on write processes; that is not unique to perl threads. The advantage of threads is that it makes easier to share data - with processes you will need to do a shared memory segment for that. Also it is less costly to create a thread rather than a process.
As far as I can tell, concurrency and parallelism in perl6 are a quite different and really powerful tool.
... unless, I suppose, they are following the practices in Modern Perl ala Moose and some other things. I guess maaayybbeee they could translate across. But it would be touching ever single line, in a transformation that would be on par with switching to Ruby (or Python I suppose).
Edited: an earlier version of this comment that referred to an outdated FAQ (mentioning a perl 5 to 6 translator).
The plan is to eventually have a perl6 CPAN, or something. They'll figure it out.
(no epub though)
I agree that it might be a bit ugly to have your name on it repeated but it is quite "discreet" nonetheless, and unless your name overlaps with a particular perl keyword, it should not impact full text search.
It's a very small price to pay compared to having physical books only, or Adobe DRM :-/
If this is DRM then so is adding my name to digital documents I write in Notepad or Vim as well.
Fortunately it's super easy to unpack a pdf with pdftk or the like then you can delete the text of the watermark with sed or perl if you like then compress again.
I have a script that removes a list of watermarks automatically prior to importing to calibre.
Come to think of it I should propose this as a feature for calibre.
Thanks, chromatic and PragProg.
https://en.wikipedia.org/wiki/Chromatic_%28programmer%29
It's fairly common in hacker culture to use pseudonyms.
That said: Don't feed the deletionists. Don't let them say chromatic wanted it.
They are possibly the worst part of the wikipedia/stackexchange bureaucracy.
Perl 6 does not. It will hopefully one day, but come Christmas time, we're not all going to just drop Perl 5 and start coding Perl 6 exclusively. They're Sister languages; Perl 6 does not deprecate Perl 5.