4 ms·
Yep. And they also keep single-use code local to the only place it's being used at the moment, which i think can help the readability and maintainability of sai
by epidemian 4y ago
Yep. And they also keep single-use code local to the only place it's being used at the moment, which i think can help the readability and maintainability of said code :)
Functions do have a place too of course; even single-use ones. Especially when you can give them a clear purpose and name.
- Pulcinella 4y agoA sort of reverse or corollary to DRY, “don’t be unintentionally repeatable.”
- Jtsummers 4y agoIt's more of an extension to "Don't use globals", but at a more fine-grained level. Code using this can still be DRY, if you understand DRY to be "don't repeat the same information excessively". Reusing the same variable name in multiple (similar or dissimilar) contexts is not a DRY violation in that sense if the names are more a coincidence than actual shared information. Most programmers have no problem, for instance, with seeing multiple loops declared like: for(int i = ...; ...; ...) { ... } `i` is "repeated", but there's no objection in having multiple declarations since each has a meaning dependent on its local context.