The last time I wrote an interpreter it was hard, not conceptually, but to get all the components working in the right order.
In intro programming, I was taught to write the outline of a class/function write pseudo-code using comments, then turn that pseudocode in to real code, it worked something like this:
class Player{
private health = 0;
public int changeHealth(int change) {
// change the private health
// return the new health.
}
}
This style works well enough because it lets you quickly see what should be broken in to methods, and outlines your algorithm so mistakes are usually syntactic in nature, but not always, especially when you don't write the proper pseudocode or have a good idea of what the algorithm should look like.
This time, I wrote tests first, and built the program up from the smallest pieces, rather than drilling down and creating new methods as I went along. I suspect this has much to do with the successes experienced by many developers, as they are forced to not create thousand line functions.
The cycle I followed was something like this:
- Write a test
- Write code
- Make sure it works
- Write a test for another case of the same function
- Make sure it works, if not fix it.
- If not all cases are satisfied GOTO 4
- Move on to the next function
No comments:
Post a Comment