3 ms·
Abstraction is not mainly about avoiding repetition though. It's about (well...) creating abstraction. Imagine if you have to check permission to do something,
by Double_a_92 7y ago
Abstraction is not mainly about avoiding repetition though. It's about (well...) creating abstraction.
Imagine if you have to check permission to do something, and that check is really complex and long code.
If would be better to have code like:
if (hasPermissionToEdit(myUser)){ ...
Than a ton of ANDs and ORs in that if, that nobody would quickly recognize as a permission check... even if it's just there once.
As a minimum I'd put that in a properly named variable first, if I really wanted to avoid an extra function.