3 ms·
Small functions are a form of semantic annotation when used properly. If I'm working with code that modifies an image, I'd much rather see "rotate" than a matr
by CuriouslyC 6y ago
Small functions are a form of semantic annotation when used properly.
If I'm working with code that modifies an image, I'd much rather see "rotate" than a matrix multiply. Heck, if I'm dividing a number by some special value, say to normalize it, I'd prefer to see "normalize" than a mystery division. I do agree that I'd rather see x + 1 than "addOne" though, since that doesn't tell me anything the code itself didn't.
- freetime2 6y agoIf a block of code is short (a few lines or less), and doesn't get reused in multiple places, I often prefer to add a clarifying comment rather than extracting the code out into a separate function. That way they reader doesn't need to go jumping around to see what the code does. And you can fit more information on a comment line than you can in aSuperDuperDescriptiveFunctionName.