Some middle-aged guy on the Internet. Seen a lot of it, occasionally regurgitating it, trying to be amusing and informative.

Lurked Digg until v4. Commented on Reddit (same username) until it went full Musk.

Was on kbin.social (dying/dead) and kbin.run (mysteriously vanished). Now here on fedia.io.

Really hoping he hasn’t brought the jinx with him.

Other Adjectives: Neurodivergent; Nerd; Broken; British; Ally; Leftish

  • 0 Posts
  • 20 Comments
Joined 11 months ago
cake
Cake day: August 13th, 2024

help-circle

  • Wait until you learn that postfix conditionals are syntactic sugar and the compiler* turns that line into the equivalent of $debug and print(debug message), putting the conditional in first place, a lot like the ternary operator.

    * Perl compiles to bytecode before running.

    The ternary operator itself isn’t implemented in terms of and (and or) but it could be.



  • Ah. The usually implicit topical “this” didn’t even occur to me because I thought, er, this, was about objects. $_ isn’t used for those in Perl.

    I suppose there might be some parallels with the implicit nature of $_ in non-OO contexts in Perl versus this in OO contexts in Javascript, but, at least to me, that feels pretty tenuous.



  • At the time JS was created, Perl didn’t have a this. A lot of the docs and books suggested using $self but a reference to the object would be passed as the first parameter to all class methods and you assign that to any name you wanted.

    It’s only very recently (as in the last year or so) with a new class system that Perl has hard-coded $self for that purpose.


  • Not strictly true.

    Perl’s default bitwise operators do differentiate between numbers and strings that look like numbers in a way that addition doesn’t*, and the readline/glob operator <> does different things depending on what (if anything) is between the signs.

    There’s also the whole overload pragma for objects, which doesn’t affect default data types, but if you’re sufficiently perverse, you can define a String class that uses ‘+’ like JavaScript.

    * in 2015, they added new operators so that those and the original operators don’t overload and have only one specific purpose if the bitwise pragma Edit: feature is turned on. You might know all this already though.


  • You’re right. I’ve got too much Perl on the brain and forgot my roots. There is a language that does what you’re talking about with the ‘+’ operator: BASIC

    Good luck getting the same thing retrofitted into JavaScript though. I can imagine a large number of websites would break or develop mysterious problems if this (mis)behaviour was fixed.



  • Perl is an old but notable exception. + is purely for addition in the base language.

    If you try to add two strings with it, they’ll be converted to numbers based on any number-like characters they have at their left hand ends, and, if warnings are enabled (and you should definitely do that), you’ll get runtime warnings about it if there’s even anything vaguely non-numeric about them.

    e.g. “1”+“11” will get you 12 with no complaint, warnings or otherwise. Not even the string “12” either, although it’s hard to determine one from the other in Perl. It’s a need-to-know kind of thing. And you generally don’t.

    “a”+“bb” gives 0 as the result because they’re not numbers and “1a”+“11bb” will give 12, but these latter two will give warnings. Two each, in fact, one for each dodgy parameter.

    String concatenation is done with the dot operator instead. “1”.“11” gives “111”. This comes with it’s own minor problems, but at least + is safe.





  • A lot of the original C coders are still alive or only very recently gone (retired, or the ultimate retirement, so to speak), and they carried their cramped coding style with them from those ancient and very cramped systems. Old habits die hard. And then there’s a whole generation who were self-taught or learned from the original coders and there’s a lot of bad habits, twisted thinking and carry-over there too.

    (You should see some of my code. On second thought, it’s probably best you don’t.)


  • For writing loops, many early BASICs had FOR/NEXT, GOTO [line] and GOSUB [line] and literally nothing else due to space constraints. This begat much spaghetti. Better BASICs had (and have) better things like WHILE and WEND, named subroutines (what a concept!) and egads, no line numbers, which did away with much of that. Unless you were trying to convert a program written for one of the hamstrung dialects anyway, then all bets are off.

    Assembly style often reflects the other languages people have learned first, or else it’s written to fit space constraints and then spaghettification can actually help with that. (Imagine how the creators of those BASICs crammed their dialect into an 8 or 16K ROM. And thus, like begetteth like.)

    C code style follows similarly. It is barely concealed assembly anyway.

    COBOL requires a certain kind of masochist to read and write. That’s not spaghetti, it’s Cthulhu’s tentacles. Run.



  • Depends if you go with the original idea, or the battery idea designed by Hollywood execs who didn’t think the audiences would understand.

    … thus proving that Hollywood execs and the people they make their changes for are only good for batteries*, but I digress.

    * For legal reasons, this is a joke. I have to say this because some Hollywood execs have more lawyers than braincells**.

    ** For all the same reasons, this is also a joke.




  • It’s a “joke” because it comes from an era when memory was at a premium and, for better or worse, the English-speaking world was at the forefront of technology.

    The fact that English has an alphabet of length just shy of a power of two probably helped spur on technological advancement that would have otherwise quickly been bogged down in trying to represent all the necessary glyphs and squeeze them into available RAM.

    … Or ROM for that matter. In the ROM, you’d need bit patterns or vector lists that describe each and every character and that’s necessarily an order of magnitude bigger than what’s needed to store a value per glyph. ROM is an order of magnitude cheaper, but those two orders of magnitude basically cancel out and you have a ROM that costs as much to make as the RAM.

    And when you look at ASCII’s contemporary EBCDIC, you’ll realise what a marvel ASCII is by comparison. Things could have been much, much worse.