Why do people write code like this? And this guy isn't even an intern or new!

  • 4
    What about:

    if (isActive == true) {
  • 2
  • 8
    Tbf I looked at something I'd written not long ago and found I'd done

    If (something == true) return true
    Else return false
    I facepalmed so hard
  • 5
    I've seen code before like:


  • 4
    If compilers could scream.. .. .. it would be very loud in the office..
  • 2
    Why not this:

  • 4
    I think some people just code their direct sequence of thoughts .. they think "if x equals y, then I want to set the result to true, otherwise it'll be false" as opposed to "the result indicates whether x is equal y"
  • 4
    This looks like horrible code with unnecessary global state and shoddy variables. Could of course be written as
    $returnArray['success'] = ($localLastActionId === $globalLastActionId);

    Having some sort of active record going though a system with a success state is something that is very good practice though (as the record is a nice consistent means of communication throughout the system). It should however always be initialized as false and set to true on success (safer with really returns etc).
  • 1
    I am no expert but I think it is so that anyone new would not have problem figuring out what you mean. If you write it in an extremely simple way, maybe people will grasp it better.
Add Comment