Hacker News new | past | comments | ask | show | jobs | submit login

Perl definitely has a lot of non-patterned arcana. For instance,

$| This variable, if nonzero, will flush the output buffer after every write() or print() function. Normally, it is set to 0.

In other languages, you do something like os.stdout.buffered(true) or sys.stdout = io::buffer(sys.stdout) or something like that where you're combining composable pieces: the standard std variable, a standard way of opening files with or without a buffer, etc. Perl instead has an obscure global variable that you have to look up/memorize, and it doesn't even have a sensible name like $STDOUT_BUFFERING, so readers who come across $| in a file have to look it up/recall from rote memorization, or hope it has a good comment above it.




Sure, it's got lots of historical baggage, but there are more sensible alternatives to $| - like STDOUT->autoflush(1) - it's not like you have to use the obscure versions of every feature.


That certainly doesn't solve the problem of other people showboating their knowledge of obscure Perl sigils by using those ridiculous line-noise abbreviations in code you're trying to use and understand, so you have to look up each bit of obscure punctuation in its particular context in order to understand the code.

If hard-to-read-and-remember syntax exists, people WILL use it. And some people will make a POINT to use it, because it makes them feel cool.

Having two totally but pointlessly different syntaxes for the same thing doesn't absolve you from having to learn both syntaxes, because you'll still encounter other people's code that uses both of them -- it just gives you twice as much syntax to learn.

If there's a "sensible alternative", then why does there have to be a "senseless alternative" in the first place?


You have to bare in mind Perls roots are as an awk-like language for the command line. In those instances weird line noise syntax was the idiom and as Perl grew it moved away from that but without breaking compatibility by default.

This leads to serious Perl projects relying on the numerous headers (as described in the very article we are discussing) to ensure everyone applies a more modern coding style.

So you can absolutely stop people from using $|

The point of Perl 7 is to have sane defaults.


Because perl improved over time, but they didn't want to break people's existing code needlessly.

No-one ever deliberately invents 'senseless' things, we just discover better ways over time. Sure, if we could somehow magically always invent the best way first of all, that would be great. But we can't, so we make the best of what we have, and improve when we can. But there's no need to punish the existing users of older, 'worse' things.


The concept of giving functions names spelled out with letters that form words that describe their meaning was invented a long time before Perl figured out that doing that was better than overloading a limited set of ASCII punctuation with random abstract unrelated concepts.


You are going to end up perpetually unhappy if you always assume that people designed things the way they did just because of stupidity / incompetence. Perhaps instead you should take a while to think about the reasons why they might have chosen their design. Even if you can't immediately think of a good reason, doesn't mean there wasn't one.

For this particular case, I'm not sure what drove the selection, but I would guess (since the decision would have been made many decades ago!) it was probably based around perl trying to operate similarly to other command line tools of that era, like awk, sed, (or even ed?), so that people could switch to perl and have a familiar environment? But I don't know, nor have I researched it. In any case, perhaps give the designers the benefit of the doubt before assuming their incompetence?


Yes, that is how Perl evolved. It's called "whipupitude" in The Land of Perl. Larry's initial goal was to create a better sed/awk for Unix.


...and how many of them were designed to be sprinkled liberally in the command line?

Python has a REPL but you couldn’t dump a Python one liner in your Bash pipeline.

Maybe a LISP might qualify but then you’re back to a language family that is unreadable to many and unknown to most (and I say this as someone who loves LISP)

When talking about the original design of Perl you can’t put it in the same category as Python, Pascal and the C-family of languages. Perl was born from an entirely different problem to solve and that’s why some of it’s historic features seem so alien to people outside of the Perl community.


Whatever happened to the neophyte raising him/herself up to level of the master? Programming seems to be the only profession in which the beginner is excused learning the language thoroughly and, worse, that he/she expects the language to be dumbed down to make it easier to learn. Can you imagine a budding musician complaining that musical notation should be made "easier for beginners"? If you want to grok Perl learn Perl ... thoroughly.


> Programming seems to be the only profession in which the neophyte is excused learning the language thoroughly and, worse, that he/she expects the language to be dumbed down to make it easier to learn. Can you imagine a budding musician complaining that musical notation should be made "easier for beginners"?

Yes. Yes I can[1]

[1]: https://how-to-play-electric-guitar.net/tab-symbols.html

The problem isn't merely that notation is easy/hard, but that people will not only pass judgement about a language (or any other idea), they will also work actively to convince others to agree with them, and oh yeah, that programmers are people too.


> programmers are people too

Are we really?


> Can you imagine a budding musician complaining that musical notation should be made "easier for beginners"?

You mean like string instrument tab coloured by finger instead of sheet music? Yes, exactly like that.


Language is a tool for programmer.

Restrict scale to pentatonic even for professionals (remove physical keys, holes etc). They would absolutely mess up otherwise.


But you would still have to master notation if you were to become an accomplished jazz musician, for example.


Sure. The context is "dumbed down to make it easier to learn" not dumbed down and forced on everyone. If you want to go full Brian Eno, you can. (https://public-media.si-cdn.com/filer/2b/e0/2be067d0-c428-40...)


> "Can you imagine a budding musician complaining that musical notation should be made "easier for beginners"?"

Yes, of course I can: https://en.wikipedia.org/wiki/Simplified_music_notation and from the linked website "is designed for learners in general".

> "worse, that he/she expects the language to be dumbed down to make it easier to learn."

And why should "simplify" have the connotation "dumbed down, for dumb people"? Everyone benefits from simpler things with fewer warts and fewer hazards.


Perl is an old accordion.


If what you're saying is true, then why aren't similar criticisms raised against Ruby? Most of the same obscure variables are also present in Ruby.

"If hard-to-read-and-remember syntax exists, people WILL use it"

This statement doesn't appear to hold up under scrutiny.


I suspect that Ruby has almost no usage. I've only ever heard of using it in a handful of startups from the valley and it's only Ruby on Rails.

Wouldn't be surprised if Perl had a hundred or a thousand times more developers, it used to be popular in the 90 and 2000s. They are still alive today and commenting about it, even though they're probably working professionally in something else.


> If what you're saying is true, then why aren't similar criticisms raised against Ruby? Most of the same obscure variables are also present in Ruby.

Not with the sigil names, are they?


Indeed, there are a lot of them actually https://ruby.fandom.com/wiki/Special_variable


Your boilerplate whataboutism confirms my point.

>This statement doesn't appear to hold up under scrutiny.

What scrutiny? I don't see any scrutiny. You just said that, without scrutinizing.


> If hard-to-read-and-remember syntax exists, people WILL use it. And some people will make a POINT to use it, because it makes them feel cool.

Just like every human language that ever existed. And last time I checked, programming languages aren't used or written by AI's or aliens.


Some things are unavoidable though. Perl hijacking a user space variable to do internal sort management? Bizarre to my mind, and utterly confounding the first time one accidentally runs into it.

[0] https://stackoverflow.com/questions/26127617/what-exactly-ar...


I take it you've never done much shell scripting? This part of perl's baggage comes from its roots as a "better" shell/awk/sed. I don't like it any more than you do, but I must say, I wish people would reserve some of the vitriol they have for perl for the shell. Because I gotta tell you Rabbi, perl is a hell of a lot better than shell scripts. And that's even if you compare perl4 (1991-1994 or so?) to the very latest bash or zsh.

edit:

BTW if $| is really at risk of clashing with a variable you defined... something else is wrong. :)

Compare that with the shell, where names like IFS can do unimaginable things if you don't know about them and set them by mistake. (Or maliciously; it's imported directly from the environment, and stuff like this is why shell scripts can basically never be given untrusted input, whereas perl, with the 'taint' option, can.)

Reflecting on all this it's pretty sad that newbies in 2020 are encouraged to learn bash, and continue creating arcane, unreadable, booby-trap-laden scripts in it, all the while looking down their nose at perl.


That's not so much Perl hijacking a user space variable as Perl having some single character globals that have special behavior. Really, you usually learn about those early (sorting is common), and if you're using strict like you should be, if you define them and use them they will work as expected until you use a custom sort, in which case you'll track down the error.

In Perl, you learn pretty early that single character non-alphanumeric variables ($|, $_, @_ $@) are special and if you encounter them and don't know them, look them up. You also learn that $1 through $9 and $a and $b have special uses, so don't use those without knowing what you're doing either.

> utterly confounding the first time one accidentally runs into it.

Yeah, but every language has some of those. Who remembers "Unexpected T_PAAMAYIM_NEKUDOTAYIM" in PHP? Or giant template error messages in C++? Or just plain segfaults? All paradigms and the languages within them have their own trade-offs and gotchas, and part of learning the language is learning those.


Developers spend most of their time reading other peoples code, so yes, one does have to learn the less sensible alternatives, if you choose this tool. It's called historical baggage for a reason.


With any luck Perl 7 with phase out the archaic linenoise features. This is overdue IMO.


I'm no fan of Perl, but you can use $OUTPUT_AUTOFLUSH instead if you "use English;". So this isn't really a Perl language thing; it's a style thing. Other languages can be made to look really bad with poor style. The question then becomes what is culturally accepted, and what is not.


`use English;` as a directive feels like the programming equivalent of someone on TV saying "ye ye ye can you say that in English!?"

Only, it's the programmer saying it this time, not the layman. Perl is a 10x engineer.


The problem is that nobody ever tells you these things, the documentation doesn’t cover them and as a result everyone still uses the terrible original syntax.


What do you mean the documentation doesn’t cover them?

https://perldoc.perl.org/perlvar.html#SPECIAL-VARIABLES


One can also:

    use IO::Handle;
    STDOUT->autoflush(1);
    STDERR->autoflush(1);


TMTOWTDI!


TIMTOWTDIBSCINABTE (pronounced "tim toady bicarbonate").

"There’s more than one way to do it, but sometimes consistency is not a bad thing either."


TIMTOWTDIBSCINABTE

(for those unfamiliar: https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to...)


$| is related to pipes. Much of the sigils are like this.


It suddenly makes sense and isn't so bad.

The $ is a sigil, so it appears before variables like $var, so it's just saying | it out. When typed at the beginning of a one liner it becomes quite obvious what you want. This is clearly not a feature for a large project, but a quick UNIX style one off awk-like script.


In Perl `$` is strictly a scalar variable though this can be a reference to an array, hash or object as they are stored as references. Not to be confused with `$` in PHP which simply denotes a variable of any kind. In Bash `$` denotes the value of a variable.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: