11
Grumpy
8y

At first it seemed harsh, but then I learned that he committed code like

if (a == b)
return true;
else
return false;

Comments
  • 2
    Yes the punishment is appropriate.
  • 0
    why is that bad?
  • 1
    @craig939393 @craig939393 It's just as stupid as writing
    if (x == 1)
    return 1
    else if (x == 2)
    return 2
    else if (x == 3)
    return 3
    ... ad infinitum.
  • 0
    @Grumpy sorry, but I want to understand if you are willing.

    say you were coding in JavaScript and an element could be in 3 different positions on the page. what not use an if statement like above in that circumstance?
  • 0
    @craig939393 Because it's completely senseless to transform a value into itself before returning it. It's like going to the bank and exchange a $100 bill for another identical $100 bill. What's the point?

    So, the proper code in my initial post is

    return (a==b)

    and in my previous comment, it would be

    return x
  • 0
    so your point is don't save things to variables when you don't need to? do it directly in the if statement?
  • 0
    @craig939393 No. Look at my previous comment: There's no if statement at all. There's no need for one.
  • 0
    ohhh. nvm...thanks lol
  • 0
    I'd say return (a==b) is to the point, but I get how the abomination could happen. Especially while still learning. It's unnecessary but more clear about what's going on for a newbie dev.
Add Comment