10 ways to improve your code

1. Write the tests before writing the code. TDD stands for “test-driven development,” it’s more useful to think of it as “test driven design.” “If you’re rigorous about doing it, it has beneficial side effects on the design of your code that has nothing to do with testing, Among those benefits: it discourages embedded object creation, forces mocking of dependent objects, and forces the earliest possible object interaction decisions.

2. Use static analysis tools. “If you’re paying the static-typing tax in Java and C# anyway, you should take advantage of that in static analysis tools,” two categories of these tools: byte-code analysis tools, such as the FindBugs open source tool; and source-analysis tools, such as PMD.

3. Practice “good citizenship” by paying attention to how well your objects interact with the outside world. “Never let them exist in an invalid state, “Mutations should always move from one known good state to another known good state.” you should avoid the singletons, because they mix responsibilities by mixing static and state.

4. Avoid indulging in speculative software development. “The goal should be to build the simplest thing we need right now. The practice increases software entropy, he added, which is a measure of code complexity.

5. Simplify essential complexity and kill accidental complexity. “It’s the difference between, ‘the problem we have is hard,’ and ‘we’ve made the problem we have hard,'” he said.

6. Challenge programming conventions, such as writing long, unreadable test names, and blindly following the JavaBean specification to the detriment of your code.

7. Embrace single level of abstraction principle (SLAP). The idea is based on advice from every public method should be as short as possible, and should consist of steps, each one of which is a private method. “Don’t make abstraction leaps in your code,” he said.

8. Leverage existing platforms with languages targeted at specific problems and applications. “This notion that there’s this one true language that you should write everything in is melting away,” Coders should think in terms of “polyglot programming,” because it takes advantage of “looming opportunities/ problems,” such as massively parallel threading.

9. Learn every nuance of the languages you’re using. If you’re using Java as your everyday language, there are a lot of “back alleys” worth investigating. For example: Java’s reflection mechanism and regular expressions, which are widely misunderstood.

10. Change your perspective and consider “anti-objects.” An anti-object is a kind of object that appears to do the opposite of what we think it should do. it is also, The object metaphor sometimes impedes the solution “by making us try to create objects that are too inspired by the real world.

3 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here