Wednesday, January 12, 2022

Planning Before Coding

After all these years one would think I would know better. But it turns out that when coding for fun I don’t always do the planning that I should. It always comes back to hurt me. If you have been reading this blog lately you know that I have been playing with a Wordle solver. It’s going well. But ..

I started well. I identified several thins my solver should look for:

  • Words that include letters I know are in the word
  • Words that don’t include letters I know are not in the word.
  • Words where a letter (or letters) are in specific positions
  • Words that include required letters that are not in positions I know they don't  belong

I coded up the first two options first and a partial implementation of the third option. So far so good. The problem came when I wanted to add an implementation of the fourth option and a more complete implementation of the third. The problem is that I had neglected to plan for where in the code I would do those checks. I tried tossing them in to the existing method but it was a mess. I had to change a good bit of the code around filtering words to make it both work and be more understandable.

In hindsight, I think I would have been better off creating stub methods for all the options and filling them in one by one. It’s a technique I recommend to students all the time so I should have thought of it myself. This would have given me a stronger framework from the beginning and made my life easier.

In any case, this exercise was a reminder not to start coding before enough of the planning has been done. I know the mod these days is to write fast and break things with a lot of rewriting. I find that to be less than ideal for me though.

No comments: