The second meeting of "Test-DrivenDevelopment for Embedded C" book club in Tokyo took place on March 4th.
We read the three and fourth chapter
At this time, we read the third chapter "Starting C Module" and the fourth chapter "Testing Your Way to Done". We had first TDD session during these chapters. We wrote test code and product code for LED driver then we refactored both of them.
The third and fourth chapters are highlight of the first half of this book. If you start to read this book, I recommend you to try the example of these chapters by yourself.
There are sample codes on my github repository.
Always make code stable
There are two very informative topics at this time. First one is to make code stable. Author describes TDD work like this:
And I saw this diagram and I found like these:
- There are two stable states of code, which are stable state that passed tests and one that don't pass.
- TDD doesn't make another state of code.
In the stable state that passes tests, there are not refactored code and refactored code. This topic is well known for TDD new comers.
The stable state that doesn't pass tests is a transient state. Compile error, link error, test failure. TDD makes this process obvious. TDD doesn't make unbalance state that passes tests but include incomplete implementation and mistakes.
Do not care about performance too much at first but care about readability
Second topic is code readability. Here is informative description in the book.
don't let the performance factor outweigh improved design and readability unless there is proof the code is contributing to a specific performance problem.
Author doesn't mean that performance is not important. We had same opinion. When we deal with problem on performance, we have to find performance bottleneck with profiler. If you put emphasis on performance and write unreadable code while you don't know where bottleneck is, maintenance time increase and have bad effect on costs.
So here is better way:
- Considering a way to meet consider requirement at architecture design phase
- Finding performance bottleneck with profiler at the beginning of architecture implementation phase
- Refactoring code so that each module becomes more readable
We talked about own attempt
First topic is auto build and test with Eclipse. If you use this function, you can also do static analysis, code format and code coverage as follows. This is very easy.
Second topic is 'AdLint'. This is new open source static code analysis tool. I talked my plan to introduce own environment. I want to show demo next time.
Third topic is auto code formant with code formatting tool such as Artistic Style. You need to care when you use it on build process because it may make unintended code format. Manual execution may be better.
Fourth topic is code coverage tool. 'lcov' is good for gcc.
Third meeting will take place on April. We will read the fifth chapter "Embedded TDD Strategy" and the sixth chapter "Yeah, but …". First one is good to adopt TDD to embedded system development. Second one gives us hints to recommend TDD to other people.