Name That Prune!
The following C# code shows a particular style of check that I seem to find again and again in various companies. It is a pretty simple refactor which you can just about do in your head, yet I seem to see programmers produce this time and time again.
Let's play a game of Limbo. Given the number of statements, how low can you go?
For Computer Science grads, this should also be bread and butter, but seems to sometimes be one of those things that CS grads forget after they hold the cylindrical piece of plastic in front of the camera whilst wearing the ceremonial mortarboard. For those maths guys out there, after a change of symbolism, this is easy. In any case, give the justification for your decision.
Once you have done that, if you can find other refactorings, feel free to perform them. However, for a discussion point, is there a point at which you stop? Feel free to take into account any aspect you find pertinent. This can include readability, performance, testability or any other facet important in good software development.
{ int x; int y; bool result; // ... whatever happens here! if (x == 3) { if (y == 2) { result = true; } else { result = false; } } else { result = false; } return result; }
return x == 3 && y == 2
ReplyDeleteWe have a winner!
ReplyDelete