TDD (1)

Comment Driven Development for low-level design before coding

When trying to write code samples in front of someone else, for example during an interview, it's a good idea to start by writing down the steps required before converting those to code. Instead of writing them down just as a list, format them as comments with blank lines in between to make filling out the code easier. int main(void) { // fizz buzz example: // test integers in range 0 to 100 // print fizzbuzz if divisible by 3 and 5 // print fizz if divisible by 3 only // print buzz if divisible by 5 only // if none of the above conditions, just print the number } It's much easier to debug the algorithm or design by rearranging and changing those comment lines than by changing the code once you're committed to all the details - variable names and types, function names and signatures all need to be kept in sync. It allows you to explain your thinking out loud to others and yourself before you get into the implementation phase. Many practicing coders recognize that this is a good idea "I realized that's what I do in job interviews... I already do this but only in…

Continue reading...