• Trailblazing Braille Taser
    link
    fedilink
    2076 months ago

    I propose a new, more threatening kind of control flow.

    do {
      /* something */
    } or else {
      /* you don't want to find out */
    }
    
    • @[email protected]
      link
      fedilink
      585 months ago

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

      OpenFileOrDie()
      
          • @[email protected]
            link
            fedilink
            10
            edit-2
            5 months 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.

      • @[email protected]
        link
        fedilink
        English
        105 months ago

        Personally, I like to call catched exception variables up, so for a rethrow I can throw up;.

        • @[email protected]
          link
          fedilink
          25 months ago

          Except rethrowing an exception in C# is just throw;, anything else is a crime against the person who reads your stacktraces.

      • @[email protected]
        link
        fedilink
        45 months 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.

      • @[email protected]
        link
        fedilink
        English
        35 months 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)

    • @[email protected]
      link
      fedilink
      85 months 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.

  • @[email protected]
    link
    fedilink
    English
    1056 months ago

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

      • @[email protected]
        link
        fedilink
        45 months 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
      link
      fedilink
      106 months 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.

      • @[email protected]
        link
        fedilink
        7
        edit-2
        5 months 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.

        • @[email protected]
          link
          fedilink
          25 months ago

          Many languages let you scope variables.

          In c# you can create an arbitrary scope to declare variables in. Most likely in others as well.

          • @[email protected]
            link
            fedilink
            25 months ago

            Ah clever, didn’t think of doing this. Not having to encapsulate if statements in scopes would still look cleaner though

            • @[email protected]
              link
              fedilink
              1
              edit-2
              5 months ago

              It’s handy if you’re creating temp variables for single use that you don’t need to use again.

              Although I admit I’ve only ever done it a couple times lol

              Again in c# you can omit the scope and only the next statement is part of an if or loop.

      • Deceptichum
        link
        fedilink
        26 months ago

        Let’s just scrap every language except various forms of BASIC.

        • @[email protected]
          link
          fedilink
          46 months 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

    • @[email protected]
      link
      fedilink
      75 months 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.

      • @[email protected]
        link
        fedilink
        35 months 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.

  • @[email protected]
    link
    fedilink
    38
    edit-2
    5 months ago

    Why not just ifnot? Same count of characters but an o instead of a possibly problematic single quote.

    • @[email protected]
      link
      fedilink
      205 months 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
      link
      fedilink
      16
      edit-2
      5 months 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
      135 months ago

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

      • @[email protected]
        link
        fedilink
        English
        85 months 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.

  • @[email protected]
    link
    fedilink
    English
    326 months ago

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

  • taanegl
    link
    fedilink
    246 months ago

    I’m just hoping this paves the way to code with Southern dialect

    iffun is == true
    iffun ain't == false
    
      • @[email protected]
        link
        fedilink
        6
        edit-2
        5 months ago

        That reminds me of an old paper about how to create a compilable C program out of old game ROMs. Decompile to assembly. Implement a bunch of #define statements that implement all the ASM statements. Now compile it to a native binary on whatever platform.

        Won’t likely be faster or more accurate than regular emulation methods, but it’s a neat idea considering that the source code on all this stuff was lost a long time ago.