I was recently fixing a bug in some code and while I was figuring out what the problem was I came across some code that looked something like this:
If x == 1 Then
doWorkBasedOn(x)
Else
doWorkBasedOn(x)
No matter which path the code took the result would be the same as just calling doWorkBasedOn and passing x as the parameter.
My assumption is that someone started this code doing the check for x and then calling doWorkBasedOn(x) assuming that future logic would not always result in the same path. Then someone else, I hope, came in and added the else statement to get their story completed without really looking at what the previous code was doing.
Regardless of how the code got to this state, the last person to work on it should have taken a second to step back and look at what they were doing. Because this code was needlessly complex, a bug was introduced. Had this been done without this extra complexity it would have worked correctly the first time. If at any point someone had really looked at the intent of this code they probably would realized that it was doing more than it needed to.
I would suggest to take a step back and look at what your code is doing before and after you work on it and see if there is extra complexity that you can remove. This will keep your code base as easier to understand and less likely to contain bugs.
I would suggest to take a step back and look at what your code is doing before and after you work on it and see if there is extra complexity that you can remove. This will keep your code base as easier to understand and less likely to contain bugs.
Comments
Post a Comment