Choose names wisely

Published on Monday 05 August 2019 | 1 minute read

With day 10 comes 10% of the way through my #100DaysOfCode. I added another five tests to my newsletter signup process this morning. It remains on a features/ branch, ready to merge with master when it's all ready.

More praise in favour of test driven development - it's a great way of seeing the full impact of adding a new feature to a site. A newsletter signup option might seem like just an input box for an email, a form submit button, and a confirmation email, but there's more to it than that. We need to handle a confirmed email, and we need to handle when an email can't be reconfirmed. We need people to be able to reconfirm their email if the confirmation doesn't work for some reason.

We also need to have a clear logic for all of this, with a good syntax. For example, I started out by setting an attribute on my NewsletterSubscriber model of validation_code. But with the subscriber emails, I am using the words "confirmation" and "confirmed". It's a simple feature so doesn't matter than much. But if I come back to work on it in the future, or someone else works on it, it creates cognitive load - "these two words are different, so they must mean different things, right?". Well in the case, wrong. That's why it's super important to pick good names not only for model attributes but variable names, methods names, class names - the list goes on.

Clear and consist terminology = ease of understanding = ease of code maintenance.

So tomorrow I guess I'll need to refactor my code on the newsletter from validation terminology to confirmation. It will be a good test of my tests :)

Coming back to the time it takes to implement simple features - I didn't need the newsletter signup process yet. I don't get many site visitors yet. It's all well and good being prepared, but a priority would have been developing a site that is good at sharing what I do and is useful and/ or interesting to people. The newsletter could have waited. The time it's taken to put it together has reaffirmed that valuable lesson of true prioritisation in projects.


1 hour of code today. Day 10 of #100DaysOfCode.

Made by Ed in Somerset. 2022.