by grabcocque · 9y ago · 0 comments
It got me to thinking about how Perl managed to become quite so profoundly disliked, and I remembered these papers and thought that maybe things like this are the reason.
The motto "there is more than one way to do it" is telling. It allows beginners to write code the way they are most familiar with and give experts a large toolbox to be most efficient in many situations. The trouble is that while the writer only needs to know a subset of the language, the reader has to know everything in order to read other people code.
This philosophy make it very suitable for quick hacks, and that's its primary use. The problem is that quick hacks have a tendency to stay, and some poor guy need to maintain that mess. And when your experience with the language is to maintain the unmaintainable, hate is totally justified.
Note that is is possible to write clean Perl, but it requires effort, and unless you are writing Perl modules, there are probably better languages for that.
Compiler undecidablity is not a problem. Sure, it is not intellectually satisfying, and it may be troublesome for some application where formal proofs are required, but for a language like Perl that is all about practicality, no one really care.
Whenever I write perl, I feel like the binary is actively fighting me, not helping me…
perl is designed to make simple things easy, and hard things possible. Readability is up the the programmer, and writability is up to the editor.
The more telling is you omitting the other half of the motto. TIMTOWTDIBSCINABTE
Perl derives its dislike from about the same source as BASIC (and arguably PHP): Early errors/preconceptions and plenty of non-programmers writing code (home computer users, sysadmins). Perl4 was used for some pretty hacky jobs, replacing sed/awk/shell combinations (which were horribly fragmented across the unices of that time). Modular Perl5 code had little to do with that, but by then the damage was done. Early CGI scripts didn't exactly help, either.
Modern Perl is a step further than that, but when Moose and the like became popular, people already moved away to PHP or Ruby, both being part of the same family.
- interpretation of a variable (is it a list, a number, a string, a hash?) depends on the context in which it's used, and the context depends on, um, its context;
- pervasive global state (`$_` and friends);
- you can mess with compile-time operations, patch the language on the fly, e.g. during module imports;
- autovivification: a single read by key from a hash is enough to actually create this key; variables are a number and a string at once, but the number will not be computed until you need this variable in number context. Reading a non-existing key in a hash as a hash actually creates a new subhash.
- ties: you can override access to any variable by your methods;
- the built-in data structures are special, there is no sane way to emulate and extend them (but, as usual, for sure there are insane ways);
- the built-in `sort` takes a code block (not a closure with parameters), that has magic variables `$a` and `$b` appearing out of thin air. It looks like a closure, but it's not.
- features are often added in a convoluted way. E.g. there was a (now deprecated) feature that allowed `push` and `shift` to take a reference to a hash instead of a hash directly. How was it implemented internally? Basically by backpatching the error condition when the existing `push`/`shift` choked on a reference.
- the language design principle is "Do What I Mean" (where the "I" part varies). It's ironic that a language built "for human communication" by a linguist (what could possibly go wrong?) is harder to read and to reason about that programming languages built around logic.
On the other hand, if your business brings enough income to pay good developers with strong discipline, you can still have a big codebase in Perl and sustain it for years: it's better to have a terrible language and good engineers than bad engineers and a good language.
Additionally, there are several misleading statements in your post. I expect you are aware of the following but just for the record:
> - pervasive global state (`$_` and friends);
Perl uses dynamic scoping (https://en.wikipedia.org/wiki/Scope_(computer_science)#Dynam...) when setting $_ and friends. For example:
$ perl -E '$_ = "A"; say; say for ("B", "C"); say;'
A
B
C
A
For me, dynamic scoping (and, relatedly, RAII) is sorely missed in languages that don't have it. (Although I do agree about $a/$b in sort -- that's a language wart, but not too bad in practice)> - autovivification: a single read by key from a hash is enough to actually create this key;
Not true:
$ perl -MData::Dumper -e 'my $h = {}; $h->{a}; print Dumper($h)'
$VAR1 = {};
You need to read it as a hash or array reference for it to autovivify: $ perl -MData::Dumper -e 'my $h = {}; $h->{a}->{b}; print Dumper($h)'
$VAR1 = {
'a' => {}
};
Autovivification is another feature that I miss in languages that lack it.Your points about the perl5 implementation are definitely accurate, although I suspect a lot of language implementations have their own dirty laundry as well. :)
It's not like having a fascination with weird language quirks makes you have good taste in languages. Especially because weird quirks are the end of usability.
If you know Unix, you will already know about 80% of perl. If you know Perl well, you already know a lot of Unix concepts.
Perl is a pain to learn if you don't have a solid Unix background. However, IME, if you acknowledge the sources Perl draws from, look at how they're integrated, and spend some time learning the underlying technical culture, it actually simplifies the learning process.
Interestingly enough, it's also easier to learn a natural language if you spend some time learning the underlying culture.
That mixing and matching seems exactly like the quirks a linguist would pick up that lower usability (at least for the general user, Unix users are kind of used to being thrown in the deep end of the usability pool).
Who are you?
IMO three things killed Perl, leaving it as an unpopular legacy husk:
- loss of ecosystem. The high points for Perl were CGI.pm and its use as a "super awk" by sysadmins. The first was obliterated by other ecosystems, better and worse: PHP, Rails, Node, Go, and so on. The second was obliterated by "servers are cattle not pets": people have moved from meticulous hand-administration to the use of containers, Ansible, etc - or away from systems administration altogether to AWS or "serverless".
- Perl 6 transition. Second-system effect at its highest. The long wait for this to be completed absolutely destroyed incremental improvement because everyone was waiting for a big bang that came very late. Python managed to avoid this level of community damage but has still split into two languages, Python 2 and Python 3.
- the "two Perls" of style; one was the Wall-influenced style that looked a bit like English. The other was sigil-heavy and incomprehensible. Eventually people decided that it was easier to put up with syntactic whitespace than remember all the $? and $| and so on, so a lot of the Perl audience moved to Python.
I don't really think it was any of these. There's much simpler mechanics at play here: Perl's competition (Python and Ruby) has about the same expressiveness, but is much easier to learn, so for a long time very few people have chosen Perl to learn. There was simply not enough young blood to replace old timers that were retiring, dying, or migrating to other languages.
If you haven't, I suggest reading through https://pragprog.com/book/swperl/modern-perl-fourth-edition
The fracture is very slowly healing. Outside of some huge corporate hold outs with a lot of Python 2 code (Google & co.), Python 3 will win out.
Perl 6 vs Perl 5, on the other hand, I don't even know if you can call it a fracture. A new start would be more fitting.
I don't know much about the Python ecosystem, but my impression is that besides the 2to3 program there wasn't really much of an effort to make them work together.
When Larry Wall was still the lead a lot of progress was made, but then it reversed course in the last 20 years. Every single competent developer left or was booted, and not a single of the many designed features for Perl6 were properly implemented in perl5. Perl5 is now purely a religion, with the heresy to express of loss of faith in the supreme leaders gets you booted, whilst uncivil name-calling and technical destruction by wannabe middle-managers took over.
The undecidedability problem is caused by the dynamic lexer. It's actually a feature to drive the static parsing rules dynamically.
And that's not even a statement about how many ways there are to the same/similar things things; these features all are intended to facilitate different stuff. I think it is the biggest language I've ever programmed in, fighting for top spot with C++.
I think core-language-feature counts are something it's better to have in moderation. JavaScript of ~2010 was far too small a language, so it had crazy library/cargo-cult utility bloat. Lisp is somewhat similar: it's elegance in its small size and simplicity, but that results in a lot of beginners (re)writing a lot of unnecessary code. Perl and C++ have too many core-language features; everything else is somewhere in the middle.
...and all that is without even getting into some of the insane language extensions you can find in third-party libraries. There's an on-after-module-load hook someone wrote that's implemented in terms of a syntax extension to the language, that isn't quite an operator or a statement. There's a coroutine library which is written mostly inside to the fatal-killsignal core dump handler I think (or something similar). And the list goes on.
If an app needs something, it will either get it from there, or failing that, from add-on packages.
That only matters for fitting into a small embedded system where you can perhaps get a smaller image if you just bundle the exact set of packages that are required.
Due to inter-package dependencies, that plan can easily be foiled.
In the end, it's better to have a big, "batteries included" language. For one thing, it is all released at once. No separate versioning for one hundred different packages. The regression test suite for the language can cover that functionality which would otherwise be in packages. No nonsense of releasing a new version of the language and then relying on field reports about broken packages.
I'm only arguing for moderation in the syntactic/language-feature department; I agree with you that a good, curated set of wide-ranging libraries is something that every language should have--ideally as part of the core distribution.
At the time of inception and around the peak of popularity I do believe it was a quite innovative language. But by now we have a much larger set of languages aimed for the same target group, many of which have gained larger adoption among developers of this time.
In a way I can almost see Node as "the new Perl" in the sense that it's a widely used language across platforms praised for it's large set of available libraries and ease of creating "quick n' dirty"-hacks.
I'm guessing the reasons are actually more conspicuous than computer science concepts of "undecidability" since most working programmers don't read academic papers to judge whether they like/disklike a programming language.
The conspicuous reasons seem to be a combination of:
1) PERL's usage of sigils.[1] One the one hand, it makes code compact and terse. On the other hand, many perceive the source code as "line noise" or "sigil hell". This is the opposite problem of other disliked languages like Objective-C where people complain it's too verbose.
2) PERL not having a constantly updated ecosystem that keeps up with new trends in computing. PERL was great for text munging (alternative to sed & awk). However, PERL wasn't extended as the driving language for dynamic web pages (Brendan Eich created Javascript instead of embedding Perl interpreter in Netscape browser), or GUI data entry forms programming (Java and C# gained popularity), or machine learning (Google developers designed Python to be 1st class in Tensorflow), etc.
tldr: PERL is perceived as "legacy" with ugly syntax
[1] https://en.wikipedia.org/wiki/Sigil_(computer_programming)
This is largely because of the sheer volume of weird global state inspections/mutations you can do in Perl--or I guess it's more accurate to say that Perl has a conveition of it being "OK" to heavily and frequently inspect and mutate global state. You can monkey patch in many languages, and sometimes it's even encouraged (Ruby), but only in Perl is it not uncommon to see monkeypatch removal or seriously altering replacement of core functionality. I've had modules hackily unload other already modules because the loaded modules' names matched a buggy load-time regex. I've had packages clobber text handling or encoding routines in other packages at compile time, or only after calling a certain function a certain way. I've had modules change the behavior of the core signal handling APIs so that any code that talked to them . . . didn't actually handle signals. And those are just the pithy examples that fit in a single sentence.
Now granted, this isn't a criticism of Perl-the-language but more of (depending on how you choose to interpret it) library authors who don't prioritize or even consider interoperability with other tools, or of Perl-the-community's conventions regarding when it's OK to go mess around in globally-stateful guts of code you don't control. You could also just as easily say that it's a symptom of the big, multipurpose monolith I had to maintain--which is valid, but other not-designed-for-huge-projects languages don't, in my experience, have problems quite this bad when they're forced to scale.
My goal isn't to cast blame, but to point out that CPAN is incredibly bloody far from a high-quality, stable, or usable code repository for certain very common use cases.
Citation needed.
I wasn't talking about the size of cpan because it's not relevant to my point. I was talking about Perl not being at the forefront of everyone's minds and being used as a 1st-class environment as computing entered new domains. E.g. instead of Sun or Microsoft taking an existing language like Perl and giving it a canonical IDE to let programmers write data entry GUI applications, they create Java & C# instead. When Google/Android decided on a development language for their smartphone SDK, they chose Java instead of Perl. It doesn't matter if cpan has mobile phone libraries now.
You seem to be taking my observations about Perl as some sort of veiled attack. I'm just reporting why and how Perl got to the state of being "disliked" today in programmer surveys. It's not about the "undecidability".
Sigils have nothing to do with Perl's terseness; actually, they make code very slightly (one character per variable) more verbose. In Perl 5, $foo is a scalar, @foo is a list, %foo is a hash, etc. $foo[0] is the first element of the list @foo; it gets a $ because the element being accessed is a scalar. This is in contrast to most languages where variables are referred to like 'foo' and that's that.
@foo
... is more compact than C#... ArrayList foo = new ArrayList(); // C# v2
var foo = new ArrayList(); // C# v3
And Perl %foo
... is more compact than C++: auto foo = std:map<string>;In Perl, you write:
my @list = (1, 2, 3);
Whereas in Perl's popular successors, Python and Ruby, you write: list = [1, 2, 3]
Saying the former lost out because the @ makes it unreadably terse is nonsense.