Some people think unit tests is a waste of time. For them you should spend more time developing real code instead of doing unit testing. But I disagree. I am more at ease when unit test are running every day without failure. Indeed know my code works like I want. Personally I am faster to develop code because I am testing incrementally my developement. In my experience my code tend to have less bugs too.
I find that Unit testing has many advantages:
– Gain time when reproducing a problem / testing functionality before integration. Instead of launching the entire application to test your changes, you can just test the small part you did.
– Regression testing. The code is easier to refactor when there is lot of unit tests. If there are big changes in the code the unit test should help us to avoid regression.
Unit test are great, but if they are not run daily it is like they do not exist. That’s why it is very important to have a platform that launches them every day. For example for Java projects Jenkins is a popular platform.
To my mind this book is mind blowing. The first time i read it , it was a revelation. Thanks to it, I grasped the use of systematic Unit Testing.
Before reading it, I was doing unit testing systematically while bug fixing. This was because of the strong policy of my first company.
After, I also understood many other programming practices. I realised that Unit testing or automatic testing is one of the most important tasks to do while programming. It allows automatic regression test and easier maintenance and bug fixing..
Another idea important to me : code only once policy. No duplication allowed. This is what i have been implementing so far .
Addtitionally, the use of design patterns is really useful to maintain the code . Before reading the book, as a young engineer getting from university, I barely knew what it was useful for. Design pattern is a skill you can implement whatever object language you use : C++,C# ,Java,etc… I have used it with these programming languages with success. It allows better extensibility and maintainability of the code.
Whenever there is a choice between different algorithms or possibility of extensions : use design pattern. The factory pattern is the one that I used the most in the end.
Advice for a young programmer
I would advice to a young engineer to start reading this book. Indeed, it introduces you with many skills you will need to learn if you want to be an excellent programmer. To my mind, the first things you will need to learn are :
To add systematically unit test in your code. If you want to go further: use TDD method.
Have a platform which launch your unit tests everyday . Be proactive: if it does not exist, suggest one to your manager. This is very important because without it your unit tests are not used. And therefore they are useless.
When you resolve a bug , first reproduce the bug. The best way is to reproduce the bug with a Unit test. Make the test failed at first,when the test is reproduced,the test should pass when you found the fix.
Use the ‘no duplication’ of code policy. It is better to factorise the code to avoid duplication. In the long run the maintenance of the code is easier.
Use design patterns to make the code more extensible. When you develop a solution in programming, you should always think long term. For example: you need to develop a simple algorithm but maybe you will use a different one in the future. Use the factory method pattern in order to call easily a different algorithm in the future.
Learn MVC design pattern. It teaches how to separate the UI interface into several layers. It is important to have a user interface clearly separated into different modules in order to modify change of technology later.
Use Sonar to improve your coding skills. This tool when used with Jenkins, will show the problem in the code.
All these tips come from the book, therefore don’t hesitate to read it. It teaches lot of important skills that experienced programmer will only learn after years of development.