7 ms·
General question: what are some pros and cons of Perl compared to other languages like Python, Ruby, Java, Clojure, Haskell? What makes Perl unique and people s
by supster 11y ago
General question: what are some pros and cons of Perl compared to other languages like Python, Ruby, Java, Clojure, Haskell? What makes Perl unique and people so enthusiastic about it?
- vezzy-fnord 11y agoIt reifies the process of munging and pattern matching on text streams in a way few other dynamic languages do. Perl 6 particularly so with grammars (similar to lex) as a first-class construct. It's more appropriate to compare it to SNOBOL and AWK.
- latenightcoding 11y agoYeah let's compare Perl with AWK lol
- Mithaldu 11y agoYou may find it funny, but one of the motivators for Perl being made was to get a better awk, which is why it's highly compatible with awk syntax.
- Tycho 11y agoCons: huge cognitive overhead from remembering how to reference your data structures the correct way.
- TurboHaskal 11y agoAs a Perl fan, I think that's a valid point. It takes five minutes of a good tutorial to understand what references are and how they work. Yet it's not rare to see so called senior developers still failing to use them properly and introducing bugs because of it.
- pflanze 11y agoI too think it's a fair point; Perl tends to have too many syntactical features that take up processing power in the brain: JavaScript style foo.bar.baz is just lower overhead than $foo->{bar}{baz} or $foo->{bar}->{baz} or $$foo{bar}{baz} or if foo is a hash variable, $foo{bar}{baz} or variants. The brain has to filter out whether the first variable holds a reference or is a hash variable, then has two different dereference syntaxes to choose from (ok JavaScript has two variants, too), then later '->' are optional. You get used to it, but it still draws some attention away from the more interesting parts of a program. In a way my project improves a bit over this, since you're often not using Perl base data structures directly anymore; OTOH of course that means writing out a function or method call, and while this is more universal (which I like) it also uses more space to type. Also, sigils are getting more pointless when using libraries (I usually don't use % and @ anymore, always references, the good part of which is that this is giving a bit more consistency).
- kbenson 11y agoI would argue that it less adds cognitive load than it shifts that load from other portions of the language. Dealing with references makes some operations (such as telling if two variables contain the same data in memory) very easy, while making others (such as top level access to hash/array items) harder. I think that it makes some advanced operations easier to understand at a glance and reason about at the expense of those unfamiliar with the language (or references in general).
- pflanze 11y agoFor me the enthusiastic part is that it's the first language I used for a lot of stuff. My brain knows how to work with it. I know what I get. Perl is also a constant, it doesn't change a lot and my scripts from almost two decades ago still work. Also, it's part of the basic install of any common Linux distribution. Dealing with a reference-counting GC is a bit of a nuisance when occasionally having to help it along manually, after getting used to a real GC, but it can also be beneficial: memory usage is deterministic and rather low. Perl is also slow handling data structures compared to languages like Java, Clojure or Haskell, unless you implement those / the bottlenecks in C, which functional-perl currently does not do. Perl is very hacky, in both the good and bad senses: it's not a simple and clean language or ecosystem (kind of the anti-thesis of Scheme), but it's also very malleable: core perl allows you to do a lot of things for which you would need macros or similar features (I still don't know how Ruby works in this regard) in other languages, and various approaches to extend it exist nowadays (e.g. you want something nicer than "sub { my ($x)=@_; ... }"? Today you can write a module that allows you to write "fun ($x) { ... }" pretty cleanly (also someone implemented[1] one for this example already)). Also, I've been positively surprised to find good hackers in the Perl community when I returned; perhaps that's correlated. [1] https://metacpan.org/pod/Function::Parameters https://metacpan.org/pod/Function::Parameters