Hacker News new | ask | show | jobs
by hzhou321 1507 days ago
Perl is really cursed by the past glory. People still trying to revive Perl against modern fad, for example, Python. Fad are powered by steam of live Eco-systems, which Perl once had, but no longer have. There is no real reason why Perl couldn't succeed where Python does other than the path of history. And there is no real reason to chase history today.

Rather than looking for killer app or adding modern features, such as the effort of Perl 6, now Raku, Perl should shed features and focus on stability (which it is fighting hard to retain), on ubiquity (which it had and are losing ground), and core performance (which it is slowly degrading due to features). I think it should try to get a core set into POSIX standard. The core Perl can be like POSIX shell, while a distribution always can distribute a fancier, but always compatible Perl.

Perl should replace shell scripting, period. If there is any reason shell scripts is still preferred, then that should be the TOP focus for Perl steering council to address.

It really frustrates me to see people today, me included, are still trying to manage basic software engineering in shell scripts. It really amuses me today to listen to pastors on how to write good shell scripts. It really saddens me today to watch efforts of inventing a better shell for scripting.

2 comments

> People still trying to revive Perl against modern fad, for example, Python.

Lmao Python has been around since 1991 only three years after Perl appeared. How's it a fad? Sucess of python is a testament to the difference a simple and beginner-friendly syntax can make as well as the "batteries-included" paradigm. Most people don't realize how much of a difference these things make especially in removing the initial barrier to get started with programming. There's a reason Go language creators enforced a rigid formatting requirement. It not only improves readability but helps in creating clever tools for syntax checking and other tasks. Readability is key, the fact that Perl code is compatible with that 20 years before makes no difference as they have such bad readability (especially quickly made scripts for sysadmin tasks which no newbie can understand and maintain now). So even for now Python is the best choice for shell scripting, eventually until Go takes over. At this point unfortunately I don't see any area where Perl can make a difference compared to other languages.

> Lmao Python has been around since 1991 only three years after Perl appeared. How's it a fad?

If everyone start wearing pink this year, that's a fad. A fad has nothing to do with when the stuff was invented. It only has to do with people choosing it from the dominant reason being other people chooses it.

> Sucess of python is a testament to the difference a simple and beginner-friendly syntax can make as well as the "batteries-included" paradigm.

So why Python didn't succeed when Perl dominated? As you said, Python was around for quite a while then. "Simple", "beginner-friendly", "batteries-included" are all subjective terms that none of them I think is true compared to Perl. That mostly comes from one's background and culture, not worth to debate.

> the fact that Perl code is compatible with that 20 years before makes no difference as they have such bad readability

Writing Perl the way one writes shell scripts is what gets Perl's write-only rep. Do not write scripts the way we write shell scripts. Write scripts the way we write code -- That is my motivation to replace shell scripts with Perl.

There is no easy way to write readable shell scripts. Perl has all the language features that enables writing readable code. Using bad practitioner as argument for bad language is a bad logic. But if all you saw were bad practitioners (or more likely today, one haven't seen real practitioners by hears about the bad rep and see some bad relics), then it's hard to convince you. Perl has formatter. Perl has strict mode (that should be default). Perl has best practices. The people still using Perl today knows this. People who claim Perl is unreadable are getting that from the 90s.

> A fad has nothing to do with when the stuff was invented. It only has to do with people choosing it from the dominant reason being other people chooses it.

If that's your interpretation of a fad then you're still wrong. The dominant reason why people choose Python is the strong ecosystems that have been built around it - everything from scientific computing, data analysis, machine learning, web frameworks and so on. This happened over decades. And it's no coincidence why so many good libraries have been written in Python. All of their creators have publicly admitted they loved Python syntax, wanted to code in Python and nothing else in their jobs even if it means having to write a whole different library. And because Python has so low threshold for beginners, these caught on fairly quickly and took over. Python core developers listend to the community and quickly adapted to their needs. Meanwhile Perl gods buried their heads in their pursuit of the most perfect programming language ever - and we all know how that turned out.

> So why Python didn't succeed when Perl dominated?

Who said it didn't succeed? It's growth was just slower than Perl. It was slowly building up steam. While Perl exploded and ran out of fuel in 10 years.

> Do not write scripts the way we write shell scripts.

This has nothing to do with writing new scripts. Read my comment again. This is about maintaining/adapting legacy code from 10-20 years back. In 90% of the cases for Perl that means a complete rewrite because there's no point spending time understanding the gibberish. I can't really go back in time and tell those people to write good code or be "good practitioners". And if I have to do a rewrite now, there's absolutely no reason to choose Perl, that ship sailed in early 2000s.

I sympathise with your desire to replace shell scripts, but I don't see why that replacement should be Perl of all things. Like you said, Python has displaced Perl due to ecosystem support, so why chase history here?
Python never succeeded in scripting. Shell still dominates scripting today. Perl is rooted in scripting.
Where do you think Python has failed as a scripting language? I'm not very familiar with Perl, but overall I can't think of any obvious advantages aside from some of the syntactic sugar around invoking shell commands and string matching.

I can see stability as a knock against Python, but outside of 2 vs 3 the only breaking changes I've really had to deal with were relatively short term issues with third party libs.

Perl started with scripting, so many design philosophy are centered around scripting. Python, I think, is started with the goal of building applications. My first impression when I learned Python (around 2000) was the OOP nature of Python. Building classes and objects were least in my mind when scripting.

A few examples:

Perl (flexible/optional function call interface)

    print "hello world\n";
Python (the insistence of function call parenthesis)

    print("hello world")
Perl (direct string substitution thanks to sigils)

    print "Hello $name\n";
Python (a few formats, keep searching for the perfect ones)

    print("Hello %s\n" % name);
Perl (a core set of shell like patterns)

    if (!-d $dir) {
        mkdir $dir;
    }
    chdir $dir;
    foreach my $f (glob("*.txt")) {
        ...
    }
Python

    import os
    import glob
    # google for usages
Perl (good lexical scopes)

    if ($do_A) {
        my $x = "A";
        work_with($x);
    } else {
        my $x = "B";
        work_with($b);
    }
Python

    if do_A:
        x = "something" # did I changed x for somewhere else?
        ...
Perl (a set of defaults balacing the succinctness and readability)

    my %opts;
    while (<In>) {
        if (/(\w+):\s*(.+)/) {
            $opts{$1} = $2;
        }
    }
Python

    import ...
    ...
        m = re.match(r'...', line, re_flags)
        if m:
             opts[m.group(1)] = m.group(2)

Perl's philosophy is "There is more than one way to do it", pick the way that makes most sense to you.

Python's philosophy is "There should be one-- and preferably only one --obvious way to do it", but obviousness is subjective to some, and for the rest, you need learn/search/train the "one" way.

I think this is really just a factor of what you're used to, because none of those Python examples seem like an issue to me, and the Perl examples seem much harder to parse. I personally prefer print as a function rather than a statement, and keeping most standard lib functionality in modules seems like the right choice for anything other than a DSL.

I agree scope leakage is a major stumbling block with Python for sure, but it only occurs with control-flow so rarely causes actual issues once you're aware of it. Aside from that my biggest qualms with Python are the typesystem and whitespace for scoping, but those two don't cause much trouble for typical scripting purposes.

And, for what it's worth, Python's f-strings have been the go-to string formatting approach since 2016 so your example becomes something like:

  print(f"Hello {name}")
Which is doubly nice because you can also use format specifiers and arbitrary expressions like so:

  >>> f"The current year is {datetime.now().year} and the value of pi is approximately: {22/7:.2f}"
  'The current year is 2022 and the value of pi is approximately: 3.14'