So I launched the web app to generate passwords with a mixture of letters, numbers, and symbols. I learned some basic JavaScript and refreshed my HTML knowledge. I practiced perseverance. And then I practiced it again. This was one of the hardest projects I’ve done in years.

One thing that became clear to me is that the way I structure my code is a strength of mine. I assumed everyone structured their code the way I because I find my approach makes it so much easier to troubleshoot why the code isn’t working.

…. Maybe everyone else just writes code that works the first time….. Hmmmmmm.

How do I do it?

Modularly.

I also typically start with a little algorithm so I know where I’m going with my code. If I wanted to write a little program to calculate savings with interest my algorithm might look something like this:

Get user  name
Ask them the frequency of interest calculation they'd like to use
Get user savings for each period
Calculate interest
Display result

Each line in my algorithm then becomes its own module. The great thing about this approach is that you can add diagnostic print statements to each module to get the program to print the results of each step. If you don’t get the expected result, it is easy to tell where in the program the error is occurring.

This approach was difficult to implement in the web app at first. Why? Because I didn’t keep my algorithm front and centre. Not having that led me to lose focus on what I was trying to achieve with a particular section of code.

Because there was no algorithm I also forgot about my tidy little module approach. No algorithm => no modules => no print statements to help me troubleshoot problems. This added two weeks and about 20-30 hours of extra work to this project. That’s a 30% increase in delivery time. If I were doing this for money that’s extra cost that’s either being passed onto the customer or being absorbed by the business!!!!!!!!

All for want of a little five line algorithm.

To summarize what I learned from this experience – in the hope it might be useful to someone else:

  1. Always jot down an algorithm and keep it somewhere you look often
  2. Use a modular approach to code development (This will help you as much as your customers. Once you have a library of modules, you can reuse them with little to no work…and finding errors becomes so much easier.)
  3. Print statements placed at the start and/or end of every module can be commented in or out and are useful to troubleshoot what’s going wrong with code.