News for hackers. Stuff that matters.
Re:Why Perl Didn't Win by bane on Sunday June 08, 2014 @11:43PM (#7866902)
Maintenance. I say this as somebody who loves Perl, quirks and all (actually because of the quirks). It's actually a beautiful language to work in in the same way English is a beautiful language -- it's a beauty because it's a goddamn mess. But it's a rotten language to maintain.

Sure, it's perfectly possible to write highly maintainable code (I have a few 30-40k line Perl projects that I can open up and get right to work on without too much fuss) and you can create some coding standards and stick to them, and write perfectly maintainable code. But Perl is a bit like C++ in the sense that everybody has different standards and those standards change and "non-standard" bits of the language start leaking into your code and you spend as much time unmessing things as you do writing code.

I don't think Perl will ever really die, it's too convenient, but it's definitely never going to enjoy the dominance it once had. It'll fall back to a very good one-off system admin and log processing language with some extra bits, but it's simply a language that the rest of the world has surpassed and Perl 6 just isn't a realistic offering, after a very loooong wait (nor does it fix the issues non-Perlers have with the language -- it's basically fan service).

Re:Why Perl Didn't Win by amenbrother on Monday June 09, 2014 @12:10AM (#7866974)
I was recently asked to add some trivial code to the end of an existing unmaintained Perl script written long ago. Something along the lines of

  $x = `cat FOO 2>/dev/null`;
  if ($x == "foo") {
      system("BAR");
  }
When I tested it I found BAR was executed no matter what FOO contained without any errors or warnings. WTF? After a little more searching I found the problem was that I should have written

  $x = `cat FOO 2>/dev/null`;
  if ($x eq "foo") {
      system("BAR");
  }
I have absolutely no patience for this kind of crap, but I don't have time to replace the whole thing right now so I just suck it up and move on. I can understand how Perl may never die completely but I'm never going to use it for anything new.
Re:Why Perl Didn't Win by mst on Monday June 09, 2014 @03:52AM (#7867408)
I guess you've never written any bash either, wherein the exact same problem exists except that == and eq are the other way around, for reasons I can't quite remember.

Plus, of course, if you'd enabled perl's warnings system, via 'use warnings;', it would have complained at the use of == on a non-numeric value.

If you don't enable the compiler features that catch problems, then, yes, you can run into problems. Welcome to programming.

Edited to add: I got downvoted within five minutes. If you disagree that my bash analogy is inaccurate, I'd love to hear why.

Re:Why Perl Didn't Win by scrollaway on Monday June 09, 2014 @04:15AM (#7867457)
I did not downvote you, but comparing a language to Bash is certainly in no way flattering, and I would definitely not put it in the "good defense analogy" category.
Re:Why Perl Didn't Win by mst on Monday June 09, 2014 @04:18AM (#7867461)
Comparing a final conditional in a systems-style script that is then calling another program, shell-style, to bash, which is the most common language where you'd execute a conditional then call another program, seems reasonable.

Maybe not flattering, maybe not a good defense, but I think under the circumstances an acceptable comparison.

Re:Why Perl Didn't Win by amenbrother on Monday June 09, 2014 @05:03AM (#7867564)
Thanks for the 'use warnings;' suggestion.

Keep in mind the subject here is maintainence - where small changes with minimal impact to production is the rule and the work is often done by programmers with incomplete knowledge and no patience for explanations. For maintenance you want KISS, not TMTOWTDI.

I'm no big fan of bash but at least bash gets the common case right here without any special settings. For example, if I use -eq instead of == and write

  #!/bin/bash                                                                     
  x=`cat FOO 2>/dev/null`
  if [ $x -eq 'bar' ]; then
    echo baz
  fi
as you imply, bash won't be silent. It will say

  bash-3.2$ ./example.sh 
  ./example.sh: line 3: [: bar: integer expression expected
Re:Why Perl Didn't Win by mst on Monday June 09, 2014 @04:05PM (#7870195)
Equally, bash requires 'set -x' to not ignore errors.

In both cases, the reasoning is significantly to do with backcompat, I believe.

So, yeah, things that have been around a long time often require a setting to be safe in cases that we, ten or twenty or whatever years on, consider common.

Also: I did keep that in mind. That's why I started off suggesting using warnings, rather than (as I normally do for new code) making them fatal :)

Re:Why Perl Didn't Win by Joeri on Monday June 09, 2014 @05:51AM (#7867664)
Sane defaults are a cornerstone of good language and framework design because for better or worse people don't read the manual before they start using something. If a compiler doesn't do the right thing by default (throwing errors on problems a new user is likely to cause), it's a bad compiler.
Re:Why Perl Didn't Win by BugBrother on Monday June 09, 2014 @06:20AM (#7867728)
What sane defaults are will change over the years.

Perl kept amazing backwards compatibility by adding extra statements to modify how it worked. So "use strict;", "use warnings;" and "use <other_newer_perl_features>;".

Both new code -- using the best OO system of the scripting languages, extendable syntax, etc, etc -- will run at the same time as most of the old and crufty stuff from before testing took over after the Millennium.

Re:Why Perl Didn't Win by SilasX on Monday June 09, 2014 @10:48AM (#7868707)
Lines that can affect the global behavior of the program are a mixed blessing.
Re:Why Perl Didn't Win by BugBrother on Monday June 09, 2014 @11:06AM (#7868781)
It would have been bad, if the design had been stupid enough to not make declarations file/package based... :-)
Re:Why Perl Didn't Win by shadowfox on Monday June 09, 2014 @12:31AM (#7867039)
This sort of distinction exists in other languages though: Java has == and equals. OCaml has = and == etc. (Not that Perl doesn't have its issues; but this is very low in that list imho)
Re:Why Perl Didn't Win by TheMiller on Monday June 09, 2014 @12:49AM (#7867077)
Ahd in Common Lisp, EQ, EQL, EQUAL, and EQUALP. See http://www.nhplace.com/kent/PS/EQUAL.html for an explanation of why.
Re:Why Perl Didn't Win by sillysaurus3 on Monday June 09, 2014 @12:59AM (#7867102)
Mistakes from other languages are still mistakes.

One could try to call them tradeoffs rather than mistakes, but then you'd have to explain why the programmer benefits from such circuitous thinking.

Re:Why Perl Didn't Win by pcwalton on Monday June 09, 2014 @01:07AM (#7867130)
I don't think that one is a mistake. At least, if it's a mistake, it's not a mistake in the equals operator. PHP attempted to use one set of comparison operators and the fallout has been far worse: there have been security problems due to the semantics of PHP's == operator attempting to guess whether to perform string or numeric comparison when doing password comparisons.

The mistake, if any, is that numbers and strings are unified into one scalar type in Perl. This allows some tricks, such as being able to use sprintf to perform rounding, but it has fallout in other places in the language, such as here. Given that numbers and strings are unified, having two operators for comparison is the correct decision: it makes the semantics much simpler by having the language not guess which kind of comparison to perform.

Re:Why Perl Didn't Win by TheMiller on Monday June 09, 2014 @11:36PM (#7871727)
They're not mistakes; read the article. "Equality" is not the singular, unambiguous concept that many programmers think it is.
Re:Why Perl Didn't Win by Someone on Monday June 09, 2014 @05:11AM (#7867582)
That is not what perl and bash do. They distinguish between "comparing as strings" and "comparing as numbers". For example, the strings "03" and "3" are different, but as numbers, they are equal (and, I guess "010" is equal to "8", numerically. I didn't try, because I don't want to know)

For bash, read http://unix.stackexchange.com/questions/16109/bash-double-eq... (especially http://unix.stackexchange.com/a/120235) and weep.

For perl, see for example http://www.perlmonks.org/?node_id=276023

Re:Why Perl Didn't Win by tobinfricke on Monday June 09, 2014 @12:53AM (#7867086)
But in those languages, the equivalent to ($x == "foo") will return false (almost) all of the time. The poster here says that this expression is true (almost) all of the time in Perl. Why?
Re:Why Perl Didn't Win by mst on Monday June 09, 2014 @03:55AM (#7867416)
Because if you disable warnings, it silently coerces 'foo' to 0.

This is why disciplined (i.e. non-tiny-script-y) perl code starts off with

    use strict;
    use warnings;
just like disciplined javascript starts off with

    /* use strict */
and disciplined C code enables compiler warnings, and truly disciplined C code makes those fatal, just like in perl you can do

    use warnings FATAL => 'all';
If you don't do that, then you get the short script/one liner style behaviour where, just like sed, awk or bash, it assumes you know what you're doing. If you don't, then you should be asking the VM to help tell you when those problems exist, same as 'set -x' in bash is incredibly useful if you don't plan to add '|| exit 255;' onto the end of every command.
Re:Why Perl Didn't Win by mike-cardwell on Monday June 09, 2014 @05:14AM (#7867593)
I've been writing perl for over ten years. I think I learned to stick "use strict; use warnings;" at the top of my scripts on day number 1. God only knows why so many other Perl programmers never learnt this.
Re:Why Perl Didn't Win by kamaal on Monday June 09, 2014 @01:04AM (#7867120)
But what is $x? Integer? String? Character? Some_Object?

How do you evaluate this, depends on the context. Wasn't that the whole point of a dynamic language anyway?

Re:Why Perl Didn't Win by CatMtKing on Monday June 09, 2014 @01:25AM (#7867178)
After learning Haskell, I'm not sure what the benefits of dynamic typing are anymore.
Re:Why Perl Didn't Win by keypusher on Monday June 09, 2014 @01:37AM (#7867202)
No, not at all. Type coercion is orthogonal to type safety.
Re:Why Perl Didn't Win by AlexanderDhoore on Monday June 09, 2014 @03:10AM (#7867354)
Amen, brother! I call this "weak typing". But some others use weak typing to mean different things (like "unsafe typing") [1].

Javascript, PHP and Perl are weakly typed. Smalltalk, Lisp, Python, Ruby... are strong typed. But all of them are dynamic.

[1] http://en.wikipedia.org/wiki/Strong_and_weak_typing#Predicta...

Re:Why Perl Didn't Win by girvo on Monday June 09, 2014 @05:11AM (#7867580)
I love dynamic languages with strong typing. You get most of the dev time developments, but without the inherent subtle bugs that creep in via automatic type coercion.
Re:Why Perl Didn't Win by amenbrother on Monday June 09, 2014 @12:58AM (#7867100)
Those languages are far more maintainable and their communities have far more respect for practices which prevent programming errors.

I don't particularly care how many forms of equality or comparison a language has as long as the compiler or runtime is capable of telling me the particular one I'm using is probably wrong. If == can't be used with strings the damn interpreter should tell me so instead of silently and improperly coercing the arguments.

Re:Why Perl Didn't Win by aphexairlines on Monday June 09, 2014 @03:51AM (#7867407)
The interpreter does tell you.

    $ perl -e 'use warnings; use strict; print "content" == "foo", "\n"'
    Argument "foo" isn't numeric in numeric eq (==) at -e line 1.
    Argument "content" isn't numeric in numeric eq (==) at -e line 1.
    1
Re:Why Perl Didn't Win by amenbrother on Monday June 09, 2014 @04:25AM (#7867473)
Thanks - I'll try to remember that if I ever have to touch perl again.
Re:Why Perl Didn't Win by cubancigar11 on Monday June 09, 2014 @02:06AM (#7867257)
You should have used strict and warnings. RTFM, I know.

Btw, Java will silently compare references instead of value. Learning a language != increasing vocabulary.

Re:Why Perl Didn't Win by mercurial on Monday June 09, 2014 @04:20AM (#7867464)
Tell me about it. At least Python can make the difference between equality and identity, while a non-overriden equals() in Java actually means "is X Y?" instead of "is X equal to Y?".
Re:Why Perl Didn't Win by mst on Monday June 09, 2014 @03:57AM (#7867424)
I don't want the popularity we once had.

The same people who wrote unreadable, unmaintainable perl went on to do the same sort of damage in PHP, then python, then ruby/rails, and now node.js/go. They were never a net positive to the community, and I'm not sorry to see them causing problems for somebody else.

(and before somebody says "but that doesn't happen in X" ... yes, it does, even python lets you write code that looks superficially comprehensible but turns out to be so horribly illogical structurally that it's impossible to maintain - I quite like python but I've been there and I was kinda scared because at least wrong perl looks wrong to start with, whereas wrong python looks fine until you realise just how much of a crawling horror it is)

Re:Why Perl Didn't Win by chaostheory on Monday June 09, 2014 @05:07AM (#7867575)
> before somebody says "but that doesn't happen in X" ... yes, it does, even python lets you write code that looks superficially comprehensible but turns out to be so horribly illogical structurally that it's impossible to maintain

It does happen, but due to the design of Python / Ruby / Javascript, it's a lot harder to make happen especially when you use a framework.

As a former Perl dev, unless someone maintains god-like discipline over a Perl code-base; it's a lot easier to come up with unmaintainable spaghetti, that no one save for the original developer fully understands how it works, than it is in other competing languages.

Re:Why Perl Didn't Win by esaym on Monday June 09, 2014 @09:36AM (#7868352)
I was thinking the same thing. Didn't say anything because I didn't want to be rude to the "lets cut and paste code from google searches" coders...

If someone really wants to use a language, there is no excuse for not reading a book for that language first.

Re:Why Perl Didn't Win by yellowapple on Monday June 09, 2014 @05:17PM (#7870574)
And when it comes to a "book for that language", Programming Perl really does take the cake.
Re:Why Perl Didn't Win by mamcx on Monday June 09, 2014 @02:45PM (#7869795)
With python is not the same. Even if the developers is truly bad and do a mess, is a decipherable mess. Requiere truly talent to do a hard-to-understand mess in python, and in that case, is very likely the code was made by a good developer ;)
Re:Why Perl Didn't Win by yellowapple on Monday June 09, 2014 @05:15PM (#7870562)
> Requiere truly talent to do a hard-to-understand mess in python, and in that case, is very likely the code was made by a good developer ;)

Last I checked, the whole "if it was hard for me to write, it should be hard for others to understand" was still a mockery, not a seriously-interpreted excuse. It ignores the fact that the programmer's future self will eventually need to maintain that code. The developer might have skill, but one who writes unmaintainable messes as anything other than a Perl-golf-style mental exercise probably lacks wisdom. :)

Re:Why Perl Didn't Win by mamcx on Monday June 09, 2014 @06:57PM (#7870980)
Could provide a example on python of non-intentional bad code, like the kind that could be write by a perl coder, that make them not understand it a week later?

Because that is the issue I was talking about is rare in python. Is true that is possible to write bad in any language, but certainly is harder in some of them

Re:Why Perl Didn't Win by EdwardDiego on Monday June 09, 2014 @12:20AM (#7867008)
> But it's a rotten language to maintain.

I've been diving into some of our legacy Perl and man, the learning curve of the various sigils and implicit variables. Even working with collections was challenging.

I'm working to make it better Perl (I have a copy of Modern Perl on my desk), but that's solely to make it understandable so that we can rewrite it / replace it with something like Salt.

Re:Why Perl Didn't Win by mst on Monday June 09, 2014 @04:03AM (#7867436)
If it's seriously legacy code ... then I'd completely support you rewriting it, and I'd rather see it rewritten as not-perl than left as bad perl, no matter how much I personally do like perl.

This is why I'm glad we're not the 'most popular thing' anymore, these days the same quality of people are producing similarly awful code in node.js and go, and I feel sorry for those languages' communities because of it.

Re:Why Perl Didn't Win by EdwardDiego on Monday June 09, 2014 @05:50AM (#7867659)
> If it's seriously legacy code ...

Well, I'm removing globally scoped maps shared across several modules and about 6000 lines of code. To be fair to the original author though, he was learning Perl as he went along, and when he learned about references he started using them in new code.

Re:Why Perl Didn't Win by yellowapple on Monday June 09, 2014 @05:28PM (#7870631)
If you don't enjoy Perl code that looks like a cartoonish string of censored profanities, you could always try including 'use English' in your program, which aliases more descriptive names to all those punctuation-mark special variables. See here: http://perldoc.perl.org/English.html
Re:Why Perl Didn't Win by crahrah on Monday June 09, 2014 @12:19AM (#7867004)
""non-standard" bits of the language start leaking into your code"

I work on a small team (C++), so this has never been an issue. If you break coding guidelines someone will notice and let you know.

But this really should be integrated into work-flows. (ie/ into Gitlab, Jira, etc.) There should be some kind of step - before you are allowed to merge code - that checks that you are withing coding guidelines.

Re:Why Perl Didn't Win by SilasX on Monday June 09, 2014 @02:31AM (#7867302)
Re:Why Perl Didn't Win by crahrah on Monday June 09, 2014 @12:42PM (#7869188)
Thank you very much for showing me this. I'll definitely look into it.

Learning something new every day =)