97
bert
9y

When you see a someone write this
if(condition){
return true;
} else {
return false;
}

Comments
  • 3
    Isnt that more readable?
  • 5
    @working one line is hella more readable than 5
  • 4
    Classic junior syntax
  • 11
    return condition;
  • 0
    @awol @bert what is it that you achieve by doing it? does it make your code order of magnitudes faster? how is one style significantly better than other?
  • 2
    It's embarrassing when someone has to write out the syntax from CS 101 in devRant...
  • 0
    @working it makes things harder to read for someone else, plus it's unnecessary. Technically it's slower, although in reality it's prob not, but it's just plain stupid
  • 0
    when your BOSS writes verbose code like that 😩😖
  • 0
    @awol if your condition happens to return a null the verbose syntax actually returns the right value.
  • 2
    IMO variables named "condition" should already be of Boolean type. If it's a nullable type then you shouldn't be testing it implicitly in an if anyway.
  • 0
    you guys probably think ternary operators are more readable, too.
  • 0
    var authenticated = user?.loggedIn ?? false;

    One line. Succinct. Readable.
    My opinion: why write 5 lines when you can write one line (as long as clarity isn't lost)?
  • 1
    @working I like it when code is written in a verbose way to make it more readable, but in this case it is just unnecessarily. True is true because it is true, but only if true equals true considering it is true-ish. For js boolean expressions it can be necessary indeed, but that's because the language is crappy itself.
  • 1
    ^ agree. Verbosity for the sake of clarity == ok. Or should I have used ===? Damn it, JS!
  • 10
    Or when you see someone write

    if (condition) {
    //whole lot of stuff
    } else {
    //exactly the same whole lot of stuff
    //one extra line
    }
  • 1
    readability is important but I would say something like this is easier to read without. also faster:

    condition = false;
    if(condition) {
    return "foo"
    }

    return "falsy"

    The main bonus is no else statement.
  • 1
    @-Jay
    Sometimes a ternary operator can be nice too.

    return condition ? "foo" : "bar";
  • 6
    return condition ? true : false;
    lol
  • 1
    Oh this makes me cringe
  • 0
    Is it the bracket placement you're talking about? I don't personally have a preference but I know people seem to. What're the pros and cons of each?
  • 1
    @james no, not curly braces, although that is a usual source of conflict amongst developers. This one is about the developer writing "check condition. If it's true; return true, otherwise return false" then why not just write "return condition"?
  • 0
    @dev3 I see, thanks! :D
    I thought that was placeholder/example code
  • 0
Add Comment