It does however make you think about reusability and keeping consistency in code, in the getCharities example there, is something that could be reused elsewhere.
Sorry, but I don't see why reusability is relevant here - when it was suggested to create multiple 'versions' of getCharities with different combinations of parameters to avoid branching. One could even argue that it is the exact opposite of reusability: duplication.
Unless we have wildly different logic for getting by country or tier - in which case it isn't even about branching as they would be two different functions in the first place, what we would most likely have is this:
Why make the reader jump an extra hoop just to get to the actual logic? And even if we were to force reusability on this, what is more reusable: getCharities or getCharitiesByCampaignAndCountry?
I know the example are meant to be simple, sometimes contrived, but this is precisely why I don't see why eliminating else helps in any way with readability.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It does however make you think about reusability and keeping consistency in code, in the getCharities example there, is something that could be reused elsewhere.
Sorry, but I don't see why reusability is relevant here - when it was suggested to create multiple 'versions' of
getCharities
with different combinations of parameters to avoid branching. One could even argue that it is the exact opposite of reusability: duplication.Unless we have wildly different logic for getting by
country
ortier
- in which case it isn't even about branching as they would be two different functions in the first place, what we would most likely have is this:getCharitiesByCampaignAndCountry -> return getCharities(country, campaign, defaultTier)
Why make the reader jump an extra hoop just to get to the actual logic? And even if we were to force reusability on this, what is more reusable:
getCharities
orgetCharitiesByCampaignAndCountry
?I know the example are meant to be simple, sometimes contrived, but this is precisely why I don't see why eliminating
else
helps in any way with readability.