4 ms·
I am surprised by the number of people here praising Perl. I understand it was useful for its time, but the reason why programmers aren't using it is because it
by shubhamjain 4y ago
I am surprised by the number of people here praising Perl. I understand it was useful for its time, but the reason why programmers aren't using it is because it's a crap of a language. Fine, it's pretty crazy how much you can do in Perl with just few lines of code, but who cares about that except you? It's an active struggle to make Perl code readable and it not turning into a mess.
Perl not only makes it the syntax difficult with all the absurdities (special variables, so many prefixes $,@,%, terse function names, tens of ways to do one thing), it also makes it impossible to Google. Imagine spending your whole afternoon trying to dig what "($fc) = /^(.)/" does; a maintainer's nightmare. I am not that old but from a little searching, it seems to me Perl always had a bad reputation, and for good reasons.
- dale_glass 4y ago> Imagine spending your whole afternoon trying to dig what "($fc) = /^(.)/" does The issue with that is that it's a core part of the language's syntax so how are you going to search for something like that? It's a bit like trying to search what the `Obj foo{3};` means in C++, nothing in the text is a keyword, so it will vary from one program to the next and therefore won't be searchable.
- shubhamjain 4y agoConventional languages follow a pattern and you can get somewhere because the syntax will seem vaguely familiar if the paradigm is the same. I can guess the code you mentioned is some sort of declaration. Perl deviates too much at times and the numbers of choices is seriously high, which makes the job considerably difficult.
- BaseballPhysics 4y ago> Conventional languages follow a pattern and you can get somewhere because the syntax will seem vaguely familiar if the paradigm is the same. Got it, so all languages should look kinda similar so you don't actually have to learn them to grok the code. Let me guess, you also dislike Lisp, Smalltalk, and Haskell?
- kazinator 4y agoI'm guessing that it's a compound assignment. /^(.)/ is a regex match with a capture group. Perhaps this produces a list or tuple like ("a") if the buffer starts with "a", and that becomes the value of $fc. So that is to say, maybe ($x, $y, $z) = /(\d+)-(\d+)-(\d+)/ breaks down a string like 123-334-559 such that $x gets "123", $b gets "334" and $z gets "559". I did a very small amount of Perl 4 programming in the mid-to-late 1990s.
- dale_glass 4y agoNot that, no. ($fc) = /^(.)/ We're doing a regexp match, capturing the first character of a string. This is an usage of the implicit $_ magic variable. The () in the regexp means we want to capture this part, and the "." matches any character. ^ is the start of the string. We're doing ($fc) rather than $fc because regular expression matches work differently depending on context. In array context they return a list of matches. In scalar context they return a match count. So the ($fc) forces an array context to return the actual match. So, TL;DR in a more traditional language this would be: firstChar = left(someString, 1) And actually in Perl you could do: $fc = substr($var, 0, 1); as well, which would be far more understandable to a less Perl-inclined person, but with regexes being such a core part of the language they tend to show up for purposes users of other languages may not expect. This is indeed a pretty good demonstration of some of Perl's quirkiness. If you like it, it's nice and flexible, if you don't, then it's annoying as hell.
- tadzik_ 4y ago> Imagine spending your whole afternoon trying to dig what "($fc) = /^(.)/" does; a maintainer's nightmare Why are you maintaining Perl code without knowing any Perl though? This syntax is obvious to anyone who went through the trouble of following the basic tutorial. It's a language you need to learn before using it. It's unfamiliar, but not unreadable. > It's an active struggle to make Perl code readable and it not turning into a mess Are you speaking from experience? I don't find that to be the case. I don't understand Haskell, but that's because I never bothered to learn it. Should I say it's a crap language just because I do not understand the basic bits right off the bat? There are good reasons to dislike Perl (I have my own good reasons, having worked with Perl professionally for close to 10 years), but the syntax is really not one of its real problems.
- chris1993 4y agoThat's an example of poorly written Perl code to grab the first character from $_, and bad code can be written in any language. More conventionally it would be written as "$fc=substr($_,0,1)" which seems reasonably clear and obvious.