Clean Code

Book Introduction Programmers create problems for themselves when they write code solely to satisfy a compiler or interpreter. Have you ever been significantly impeded by bad code? If you’re a programmer if any experience then you’ve felt this impediment many times. Indeed, we have a name for it “wading”. Attitude Most managers want good code, even when they are obsessing about the schedule. They may defend the schedule and requirements with passion; but that’s their job. [Read More]

Best Practices

Give me a lever long enough and a fulcrum on which to place it, and I shall move the world. ~ Archimedes. Wikipedia defines it as a “method or technique that has consistently shown results superior to those achieved with other means, and that is used as a benchmark.” It is really important to use techniques and methods to guarantee quality results in processes and products in software development, so I decided to write up the software engineering practices and principles I’ve learned over the years. [Read More]

Replace conditional with polymorphism

The essence of polymorphism is that it allows you to avoid writing an explicit conditional when you have objects whose behavior varies depending on their types. Polymorphism gives you many advantages. The biggest gain occurs when this same set of conditions appears in many places in the program. if you want to add a new type, you have to find and update all the conditionals, but with subclasses you just create a new subclass and provide the appropriate methods. [Read More]

Replace Error Code with Exception

A method returns special code to indicate a wrong path. Throw an exception instead. In computers, as in life, things go wrong occasionally, when things go wrong, you need to do something about it. In the simplest case, you can stop the program with an error code. When a routine finds an error, it needs to let its caller know, and the caller may pass the error up to the chain. [Read More]

Introduce Parameter Object

You have a group of parameters that naturally go together, replace them with an object. Often you see a particular group of parameters that tend to be passed together. Several methods may use this group, either on one class or in several classes. Such a group of classes is a data clump and can be replaced with an object that carries all of this data. This refactoring is useful because it reduces the size of parameter list, and long parameter lists are hard to understand. [Read More]

Replace Temp With Query

You are using temporary variable to hold the result of an expression. Extract the expression into a method. Replace all the references to the temp with the new method. The new method can then be used then in other methods. The problem with temps is that they are temporary and local. Because they can be seen only in the context of the method in wich they are used, temps tend to encourage longer methods, because that’s the only way you can reach the temp. [Read More]

Duplicated code

Number one in the stink parade is duplicated code. If you see the same code structure in more than one place, you can be sure that your program will be better if you find a way to unify them. When coding I focus mostly on duplication. When the same thing is done over and over, its a sign that there is an idea in our mind that is no well represented in the code. [Read More]

Refactoring

What is refactor? Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure. It is a disciplined way to clean up code that minimizes the chances of introduce bugs. In essence when you refactor you are improving the design of the code after it has been written. Why do I need refactoring? [Read More]