Name Variables Well Because Tired
Week one. Day two.
Day one set the pace. Day two was an opportunity to settle into it.
The best thing today was watching Shereef refactor my very tired to_roman_numeral method. The method mostly worked, but had lots of repetition and opaque variable names.
Working through the code, Shereef made two great suggestions. Use explicit variable names. In the past, I’ve used words like “array,” “hash,” or “string” for my local variables. Bad idea. Instead, it’s better to use explicit variables for the sake of 1) yourself, 2) your future tired-self, and of course 3) others. Better names are “arabic_digits,” “roman_numeral_lookup,” and “converted_roman_numerals.” Every oddly named variable is otherwise yet another tax on limited mental resources.
The second great idea is: Use constants for the sake of clarity. For instance, VOWELS might be an array filled with all the vowels. Rather than write something like vowel_array, VOWELS makes the code much more readable. There are better examples, but for now the idea is clear enough.
Two days have passed and I’ve already racked up 24 hours working on various problems at DBC. I’m exhausted, but can’t wait for tomorrow.