Remix.run Logo
atherton94027 3 hours ago

There was so much complexity hidden behind "do what I mean". For example, scalar vs array context which was super subtle:

  my @var = @array  # copy the array
  my $var = @array  # return the count of elements in array
js2 3 hours ago | parent | next [-]

Or even worse:

  my($f) = `fortune`; # assigns first line of output to $f.
  my $f = `fortune`; # assign all output to $f.
Which allegedly got a HS kid in hot water[^1].

[^1]: "It's all about context" (2001): https://archive.ph/IB2kR (http://www.stonehenge.com/merlyn/UnixReview/col38.html)

PunchyHamster 2 hours ago | parent | next [-]

I think what's most likely to happen here is that: * a developer that knew how it worked used it in code where he *wanted* to get the first line * someone just starting up copied it over and assumed that's the way to get the content of command into a variable

It's essentially complaining about using feature wrong on purpose, because the person that made mistake never learned the language.

my($var1, $var2...) is a way to multi-assign variables from an array.

and that makes perfect sense when you look at it. Perl have no multiple returns, but if you need a function that returns 2 variables it is very easy to make it work with:

    my ($bandwidth, $latency) = speedtest($host)

Perl's feature for returning different type depending on caller is definitely a confusing part but

    my @lines = `fortune`
returning lines makes perfect sense for the use case (you call external commands to parse its output, and if you do that you generally want it in lines, because then you can just do

   foreach my $line (`fortune`) {}
and it "just works".

Now you might ask "why make such shortcuts?". Well, one of big mistakes when making Perl is that it was also aimed as replacement for sed/awk for the oneliners, so language is peppered with "clever short ways to do stuff", and it's a pleasure to use in quick ad-hoc oneliners for CLI.... but then people try to use same cleverness in the actual code and it ends up with the unreadable mess people know Perl for.

the fact you can do

    my ($first_line, $second_line, ...) = `fortune`
is just the feature being.... consistent in its use "when you give it array, it will fill it with lines from the executed command"

you gave it array, and it just did what it does with arrays.

weare138 2 hours ago | parent | prev [-]

Then don't use the low level interfaces. In Perl, language features are plug and play. Everything's in a module. Use the core module List::Util instead.

totallykvothe 2 hours ago | parent | prev | next [-]

That's not super subtle any more than it's super subtle that "*" performs multiplication and "+" performs addition. Sometimes you just need to learn the language.

This is not a general defense of Perl, which is many times absolutely unreadable, but this example is perfectly comprehensible if you actually are trying to write Perl and not superimpose some other language on it.*

creer 2 hours ago | parent | prev | next [-]

What exactly is complex or "super subtle" about this? It's the textbook example from the 1st chapter in the tutorial or something?

atherton94027 2 hours ago | parent [-]

It's just very non-obvious what the code does when you're skimming it.

Especially in a dynamic language like Perl, you wouldn't know that you're passing down an integer instead of a function until the code blows up in a completely unrelated function.

weare138 2 hours ago | parent [-]

Then use one of the type systems for Perl.

https://metacpan.org/pod/Type::Tiny

creer an hour ago | parent [-]

You can't do that if you gave up at the very first sigil puzzle.

I'm fine with that: to program in Perl you need to be able to follow manuals, man pages, expert answers, - and even perl cookbooks, or CPAN or web searches. It's a technical tool. The swiss army chainsaw. It's worth it.

atherton94027 an hour ago | parent [-]

Seems like you and a few other posters are making the article's point – that Perl's culture is hermetic and that new programmers would rather learn Python, Ruby or Javascript rather than figure out which sigil means what.

creer 35 minutes ago | parent [-]

I wouldn't call it hermetic in that the many forms of documentation are insanely thorough and accessible - if not well advertised. There is no gate-keeping (from my point of view). New users are welcome. It's easy to learn (for the people for whom reading is not an obstacle).

But yes, no contest that the world has been on a simplicity binge. Python won by pushing simplicity and by having giant software corporations choosing it (and not complaining about the line noise nonsense). If you want to go into programming professionally, for now many years, you need python.

I don't know that I would put Javascript in the same bag. I mean, it's the other way: it looks simple and it isn't.

But python, yes, python won because it looks simple and google pushed it.

Many other languages now have to reckon with the python supremacy. This is not specific to perl / raku. It will take work for anything to replace python.

agumonkey 2 hours ago | parent | prev | next [-]

I always found contextual eval interesting. It's a generalized version of toString in a way

petre an hour ago | parent | prev [-]

It's not complexity, it's magic. Useful when one cannot be bothered to write array.length. So is if (@a) when the array is empty.