switch statements

switch statements require you to exhaustively consider all relevant or possible inputs (if you don’t rely on default).

Interestingly, the notion that switch statements can require a default is reflective of the truth to the idea that when the stakes get high, we all fall back to our default level of training or function. This has global applications to our functionality and, by extension, the inputs (things,people/their methods,contexts) in our lives as well

  • neidu2@feddit.nl
    link
    fedilink
    arrow-up
    7
    arrow-down
    2
    ·
    edit-2
    10 months ago

    using regex to find the absolute value of a number:
    $number =~ s/-//;

    using regex to check if a number is odd:
    print “odd!\n” if (($number / 2) =~ /\./)

    …and generally abusing regex for weird stuff it wasn’t intended for, because the regex engine is surprisingly efficient.

    🌼 Just PERLy Things! 🌼

    • 9point6@lemmy.world
      link
      fedilink
      arrow-up
      7
      ·
      10 months ago

      Absolute value: if less than zero multiply by -1

      Is Odd: if modulo 2 is 1

      At most both of those are a 3-4 (x86) CPU instructions. There’s no way any regex engine is going to be remotely equivalent if we’re talking about efficiency.

      I always had a suspicion you perl guys were crazy