Bad Method Cohesion

    25 August 2014

    In a previous post, I talked about bad coupling through injecting too many dependencies into a class. Developers should also be concerned with the cohesion within individual methods. In the 1993 classic Code Complete (which is great, but a little dated), it said that a method should be under 200 lines of code (LoC). In more recent years, after test driven development methodologies have taken hold, we find that the LoC metric is not as good of an indicator as it was in the past. Therefore, methods with 200 lines are absurdly large in today's world. Large methods have the following problems:

    Bad Coupling with Constructor Injection

    20 August 2014

    In previous posts, I started to explain the difference between Dependency Injection (DI) and a simple factory. To leverage more of the potential of DI, I gave an example of using constructor injection and contrasted that with setter injection. Like all things, too much of a good thing can have horrible consequences. Hopefully, this post can help you to identify when things are going wrong.

    Cyclomatic Complexity

    19 March 2014

    Over the last couple of years, I have largely changed my approach to projects and coding. This has been largely due to newer tools like git, learning from my coworkers at Summa, and from moving to a more open-minded environment where it was possible to experiment with new technologies and ideas. But, anyone who has ever had me review their code in the past knows that the first thing I do is run a static analysis tool and dive straight into the method with the highest cyclomatic complexity. More recently, I have found that if a project gets to the point where I need to employ this technique, the project is already headed down a bad path. That being said, cyclomatic complexity is still an extremely important metric to be aware of and to use as an indicator of problems.