4 ms·
What “$_%@" means for the love of god?
by nuker 3y ago
What “$_%@" means for the love of god?
- jlokier 3y agoIt doesn't mean anything in Perl. The comment is a demonstration of why some criticisms of Perl are unjustified, as people love to make up little things like that, then other people such as yourself end up with the impression that sort of nonsense is ordinary Perl. (You could imagine at a stretch those characters as part of an unrealistic expression, like "print $_%@array" meaning "print the value of $_ modulo the length of @array", but you can write messy code without spaces like that in many languages.) I used to think heavy criticism of Perl's use of punctuation characters were valid, until I looked at PHP, Ruby and Rust, and realised that some of the more popular and even loved languages are punctuation-heavy too. I prefer languages with less punctuation (despite doing expert level Perl), so I think the use of sigils ($variable) is not the best design space, but I think the criticisms of that kind which single out Perl are more like a have-a-go meme than a level-headed comparison by now.
- azangru 3y ago> I used to think heavy criticism of Perl's use of punctuation characters were valid, until I looked at PHP, Ruby and Rust The mandatory dollar sign in variable names looks dumb in php, I grant you that. As well as the dot for string concatenation. But perl insists on the distinction between $variable, @variable, and %variable; which is just wild. How is it that python works fine without all that noise, for chrissake? Or javascript?
- gkbrk 3y agoPython insists on the difference between 2 spaces, 3 spaces, 1 tab, and 2 tabs; which is just wild. How is it that Perl works fine without all that noise, for chrissake? Or Javascript?
- troglodynellc 3y agoIt's to distinguish between references and non-references. pass-by-reference rather than only COW (such as in some languages) is quite useful. You would prefer *ref like in C? You can actually do that (it's a GLOB type). The place people get tripped up is that $scalar can be a string, or a ref. You check that easily with ref $scalar eq 'ARRAY' or whatever guard you want.
- achileas 3y agoDoes Python work fine without all that? If it did, validation and type-checking tools like mypy and pydantic (or the recently introduced Typing in the standard library) wouldn't exist. Or having to write lines and lines of checking code because someone else (also me) forgot to annotate the expected types of some parameters.
- donaldihunter 3y agoI don’t think Python “just works” in this regard. It blows up in your face if you mistake a scalar for a dictionary. In Perl, the sigils are there to help you the programmer distinguish your $scalars from your @arrays and your %hashes. It still blows up in your face if you get it wrong but there’s a visual indicator to help you get it right.
- knorker 3y agoI've seen those three character prefixes in real code. It's not unjustified criticism at all. Luckily I've not needed to work with perl for ~15 years, but it was something like \$@, maybe. > but you can write messy code without spaces like that in many languages I think it's fair to say that Perl forces these extra hoops more than any other language.