• gex
      link
      fedilink
      arrow-up
      57
      ·
      2 years ago

      Some C++ style guides suggest the following naming convention for functions that crash on any error

      OpenFileOrDie()
      
          • frezik@midwest.social
            link
            fedilink
            arrow-up
            10
            ·
            edit-2
            2 years ago

            Perl also has unless() for the very purpose in OP, which is a more sensible choice.

            Oh, and if you need to reinforce your belief that Perl is a mess, the single-quote character can be used as a package separator instead of “::”. This was set in the 90s when nobody was quite sure of the right syntax for package separators, so it borrowed “::” from C++ and the single quote from Ada (I think).

            That means the ifn't() in OP can be interpreted as calling the t() function on the ifn package.

            The “::” separator is vastly preferred, though. Single quotes run havoc on syntax highlighting text editors (since they can also be used for strings). About the only time I’ve seen it used is a joke module, Acme::don't.

      • Vorthas@programming.dev
        link
        fedilink
        arrow-up
        4
        ·
        2 years ago

        One of the modules in a project I’m working on is called VulkanOrDie which always makes me crack up when I see it in the compilation messages.

      • OpenStars@startrek.website
        link
        fedilink
        English
        arrow-up
        4
        arrow-down
        1
        ·
        2 years ago

        It’s funnier when you try to SysCallAndDie() :-P

        (that’s a real thing in perl btw - I guess that function didn’t get the memo)

    • jadelord@discuss.tchncs.de
      link
      fedilink
      arrow-up
      5
      ·
      2 years ago

      It exists, kind of. Python has this construct

      for item in iterable:
          ...
      else:
           ...
      

      which always puzzles me, since it depends on a break statement execution. I always have to look it up when the else block is executed.

  • OpenStars@startrek.website
    link
    fedilink
    English
    arrow-up
    101
    arrow-down
    2
    ·
    2 years ago

    Please God let this be a humorous post that somehow does not also find a way to manage to come true…

      • NotSteve_@lemmy.ca
        link
        fedilink
        arrow-up
        4
        ·
        2 years ago

        At one of my first jobs, I was tasked to rewrite a bunch of legacy Perl scripts in Python and the unless lines always made me trip up. I don’t know why but it really messed with my mental flow when reading Perl code

    • chaogomu@kbin.social
      link
      fedilink
      arrow-up
      11
      arrow-down
      1
      ·
      2 years ago

      Basic used “else”.

      It’s nice. “if”, “then”, and “else”. I spent a year programming a shitty roulette game on an Apple 2e back in high school. I still remember the joy of using if/then/else paired with goto to make a horrible mess of spaghetti logic.

      But yeah, “else” is nice.

      • SubArcticTundra@lemmy.ml
        link
        fedilink
        arrow-up
        7
        ·
        edit-2
        2 years ago

        Using a standalone ‘else’ would tickle my brain in the same nice way that being able to declare a variable inside an ‘if’ statement as if it were a ‘for’ loop (which you can do in modern C++) does.

        • pearsaltchocolatebar@discuss.online
          link
          fedilink
          arrow-up
          4
          ·
          2 years ago

          Please God, no. I had to unravel terminal scripting code that was written in some propriety BASIC language with basically no documentation.

          Took me a chunk of time trying to figure out how it worked before I made the realization that it was BASIC

    • EnderMB
      link
      fedilink
      arrow-up
      7
      ·
      2 years ago

      I haven’t written any Ruby for years, but I still praise it in every conversation I have regarding programming languages. It’s basically a much simpler Python, with some design ideas that are both beautiful and deeply strange.

      • OskarAxolotl
        link
        fedilink
        arrow-up
        3
        ·
        2 years ago

        Ruby was designed to evoke joy and they absolutely succeeded. Usually, programming is mostly a means to an end to me. But using Ruby just feels so amazing, it’s almost impossible to even describe to somebody who has never used it before.

    • marcos
      link
      fedilink
      arrow-up
      6
      ·
      2 years ago

      The Perl version of it is even greater!

  • ohlaph
    link
    fedilink
    arrow-up
    53
    ·
    2 years ago
    aint (something) {
        somethingElse()
    }
    
    • Ookami38@sh.itjust.works
      link
      fedilink
      arrow-up
      19
      ·
      2 years ago

      I think it’s just capitalizing on a trend to add n’t to otherwise noy contractions, to make them into contractions. Contractionn’ts, if you will

    • Ferk@kbin.social
      link
      fedilink
      arrow-up
      15
      ·
      edit-2
      2 years ago

      Yes… how is “reducing exclamation marks” a good thing when you do it by adding a ' (not to be confused with , ´,or’` …which are all different characters).

      Does this rely on the assumption that everyone uses a US QWERTY keyboard where ! happens to be slightly more inconvenient than typing '?

    • KmlSlmk64
      link
      fedilink
      arrow-up
      14
      arrow-down
      1
      ·
      2 years ago

      If someone really wanted to add it, probably the best would be to use unless

      • JoshuaEN
        link
        fedilink
        English
        arrow-up
        9
        arrow-down
        1
        ·
        2 years ago

        I really liked having unless in Ruby; a ! can be easy to miss, while unless made it clear without needing to write out != true.

        • HexAndSquare
          link
          fedilink
          arrow-up
          3
          arrow-down
          1
          ·
          2 years ago

          It’s also cool when you do unless(!condition). I particularly like this.

  • xia@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    31
    arrow-down
    2
    ·
    2 years ago

    “Help’s with readability”? You know what else helps? Not using contractions and introducing an unbalanced single quote.

  • Caveman
    link
    fedilink
    arrow-up
    25
    ·
    2 years ago

    I’d take a not or “if not” operator tbh.

  • muntedcrocodile
    link
    fedilink
    arrow-up
    18
    arrow-down
    1
    ·
    edit-2
    2 years ago

    With ahit like that its not microsoft java its now microsoft javascript

    • felbane
      link
      fedilink
      arrow-up
      15
      ·
      2 years ago

      Please remain calm, we are sending paramedics to your location.