Beware modifier word inflation in variable naming

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the naming category.

Last Updated: 2024-11-23

I had a constant JobPost::POSSIBLE_ROLES which included roles like bookkeeper and tax_advisor and was used to populate these options in drop-down boxes in forms.

But the prefix possible ending up spreading like a cancer throughout the code, and I soon had wordy variables all over the place like:

<? php

foreach ($possibleRoles as $possibleRole) {
  ... $possibleRole
}

Lesson:

Shy away from variable names like MODIFIER_X and instead prefer just x.

However don't apply this too far - class names have their own rules whereby architectural concerns become important - e.g. XService might be OK (especially if the Service suffix implies something about the API)