samedi 27 mai 2017

coding principle behind "if everything has it then nothing should have it"

As I am looking through the source code of a project I'm working on, I see the following pattern:

//in one class:
function getNavigation($region_id, $clear_cache = FALSE){ .. }

//in another class getPage($region_id, $clear_cache = FALSE){ .. }

..and so on. These functions all have the same second parameter, with a default value of false.

Furthermore, looking through the calls to these methods, each call ONLY passes one parameter, the $region_id - never a value for $clear_cache. I say ONLY, but there is one exception in test coding, that's it, where it's set to TRUE.

My intention is to remove the clear_cache variable and replace it with another needed parameter on the premise that "if everything has it then nothing should have it, and we should just assume it's the default way." I usually don't ask non-specific coding questions, but is there any name to this principle in coding?

If the coder wants to do that one test case then they can just manually change the value :)

Aucun commentaire:

Enregistrer un commentaire