30
galena
2y

Legacy line of the day:
return "ok";

Like, whyyyy?!!?!

Comments
  • 7
    Oh and this return value is discarded btw!
  • 8
    reminds me of the ABAP way of doing booleans.

    Its either 'X' or ' '
  • 4
    @thebiochemic ABAP is an abomination
  • 7
    It's odd but I guess it works

    if (performsomething() == "ok"){

    //great stuff

    }
  • 11
  • 2
    Like this?

    ```swift

    app.get { req async -> String in

    "ok"

    }

    ```
  • 7
    @ojt-rant you forgot the else part :

    if (performsomething() == "ok"){

    //great stuff

    }

    elseif (performsomething() == "nok"){

    //bad stuff

    }

    ðŸĪĄðŸĪŠ
  • 9
    @Grumm ...
    else {
    // This will never happen, I promise
    }
  • 4
  • 4
    @Grumm nah the possible values should be
    'good', 'fine', 'ok' and 'bad' :P
  • 3
    @Jedidja forgot File not found :)
  • 4
    PR Comment: "!ok"
  • 5
  • 7
    Javascript framework xy be like:

    if(x === true) {
    return '👍';
    } else if(x === false) {
    return '👎';
    } else {
    return 'ðŸĪĄ';
    }
  • 1
    @Voxera what a wonderful world if thats the case.
    In my current project lotsa functions just use a bunch of early 'return false' if some checks or calls fail and 'return true' if it runs through to the end
    Ofc thats layered af so in the end it just failes genericly or sth just missing cause the function responsible silently returned false.
    it's C++ as you might guess

    makes my blood boil slightly just thinking about it and the time I've wasted
  • 1
    But that's a magic string.

    And strings are bad.

    return 200;

    There I fixed it.
  • 0
    @Jedidja Damn must be nice to found out where it returned false...

    Not sure if it is good, but here is how I manage stuff like this :

    https://imgur.com/vkaCeb6
  • 5
    @galena lol this reminds me of the CMS of doom database having all kinds of boolean-ish columns. Sometimes true was "x", "1", "ja" or "yes". I've had to create some migrations to fix this legacy hell 😅
  • 2
    @Jedidja what about "oh nonono" as return value?
  • 4
    @PonySlaystation at least, all these values are yes or no.

    Must be hell to see an API return "is this x value what you need ?"

    "how about this"

    ["yes","maybe"]
  • 0
  • 3
    @PonySlaystation Its kinda baffling, that someone even considered localizing a bool to german!
  • 5
    @galena

    I've known someone who had to work on a codebase in German.

    Not joking.

    They translated words like wrapper / interface etc. to german and enforced it.

    One of the most funniest and scariest recruiting interviews I had.

    At first I thought he was joking. But nope. He insisted and we had to put a separate clause in the working contract that he's never forced to work in an non-english codebase again.

    That guy was traumatized.
  • 3
    Fun fact, Elixir does this officially.

    Elixir is an impure, eager, dynamically typed language with no mutable data. Its mixed nature means that it has many features that exist in functional languages as a result of circumstances that don't apply to it. One such property is that every Elixir function must return a value.

    Functions that could and should have no return value, instead return the ruby-esque symbol `:ok`.

    I wish I was kidding, but I/O functions literally just do what they need to do plus the completely redundant line
    `return :ok`
Add Comment