Keep It Simple, Stupid
No data structure nor algorithm should appear twice. Duplicity incrases the challenge
of changing, mantaining and reading the code.
There are plenty of strategies for reusing code. Use them.
Never add any kind of functionality that you don't directly need.
You sacrifice your own time and you're unlikely
testing and documenting it.
Each module/class/function/method should have a clear encapsulated responsibility over the whole software, so it has a single reason to change.
Find your errors as early as possible
Better at coding than at compiling
Better at compiling than at executing
-Wall -Wpedantic -Werror
public private const override
static_assert<...,"...">
Better at executing than at debugging
#ifndef NDEBUG ... #endif
assert(...) pre(...) post(...)
Create your test code and production code simultaneously
is_prime.h | main-test.cpp |
---|---|
|
|
is_prime.h | main-test.cpp |
---|---|
|
|
is_prime.h | main-test.cpp |
---|---|
|
|
is_prime.h | main-test.cpp |
---|---|
|
|
is_prime.h | main-test.cpp |
---|---|
|
|
is_prime.h | main-test.cpp |
---|---|
|
|
is_prime.h | main-test.cpp |
---|---|
|
|
is_prime.h | main-test.cpp |
---|---|
|
|
is_prime.h | main-test.cpp |
---|---|
|
|
is_prime.h | main-test.cpp |
---|---|
|
|
is_prime.h | main-test.cpp |
---|---|
|
|
is_prime.h | main-test.cpp |
---|---|
|
|
is_prime.h | main-test.cpp |
---|---|
|
|
There are tools for facilitating TDD
We asked other MRGCV professors what is their advice for you, seeing code from previous years' students
Sometimes it is easier to use debugging tools than to run full executions while experimenting with parameters, particularly if execution can take several minutes.
Use functions: it is suprisingly common to see "copy and paste" code that could be easily abstracted as a function.
Avoid side effects when possible. These are represented by global variables, non-const reference parameters...
Don't create useless code, where useless means both that you are not going to use it or that it is not needed to obtain the solution
Do not "hardcode" program parameters that you need to change to experiment with: obtain their values from a commandline
or from a file (.ini
, .xml
...)
Produce readable code, comment it when needed. Even better than commenting the code, use function and variable names that are so clear that they can be understood even without comments.