9

I don't understand some developer's thought processes when they fix a bug/issue.

Let's say the error is -> "Cannot read property id of undefined".

My first thought is to add a check for undefined and null and figure out if further code should be executed if a null or undefined is encountered, depending on what the code is supposed to do.

But some devs are like, "Yesterday the sunrise was at 5:30 AM, Earth's rotational axis is titled at 15 degrees to the left, My aunt asked me about how I am doing today, so therefore the bug fix is required at line 65,456 of this particular kernel file".

And they implement it, and it WORKS.

Weird.

Comments
  • 6
    they had either worked there recently and can guess pretty quickly what went wrong or have a good memory and only from reviews can tell what and where ;)
  • 4
    You know, you can use a debugger...

    Let's say, you have a piece of code that

    1. takes some object

    2. calls some function from it

    Now, assuming clean code, your code expects actual objects, not none or undefined. You could go the lazy road and reject calls that you can't handle. But you'd have to do that in a lot of places. And you'll run into the problem again.

    So you could think: WHY am I getting undefined/none here? This shouldn't happen on this object. So, instead of ignoring the illness and working around the symptom, you try to find the root cause of the problem, by setting breakpoints and running a debugger, tracing back the problem to where it originates from.

    Then you fix the cause of the problem once and for all, instead of working with spaghetti code and workarounds.
  • 1
    An amateur fixes bugs using try/catch, if-else. A pro fixes the actual business logic and knows his way around.
  • 0
    well, that's the two directions you can go:

    * fixing your method not properly handling invalid input

    * fixing whatever method is generating the invalid input in the first place

    ideally, you do a bit of both. but the former usually requires quite some insight into the project structure that not everybody has.
  • 1
    It’s like if you go to the doctor with chest pain and the doctor just gives you painkillers
Add Comment