4 ms·
Either comment your code or move darlings to a properly named function, which is even better. @sentence = capitalizeEveryWordInThe(@sentence) Then you can bot
by justsaysmthng 11y ago
Either comment your code or move darlings to a properly named function, which is even better.
@sentence = capitalizeEveryWordInThe(@sentence)
Then you can both unit test (if you're into that kind of thing) and refactor without breaking a lot of things.
- hughw 11y agoI've found I often prefer reading and writing the actual guts of the inlined function, over naming it something semantically significant. It's often difficult to craft a good English name for the function. It can inhibit understanding to have to change context to learn what a function does by looking at its code (OtherModule.capitalizeEveryWordInThe). There can be small semantic variations (capitalizeEveryWordInThe, capitalizeEveryWordButFirstInThe) requiring an exploding util package. Edit. I'm saying I find the one-liner form frequently more understandable than one embodied in a function.
- justsaysmthng 11y agoYeah, I guess it depends on how many instructions are in that one liner and how intelligible it is three years from now. The expressiveness of the language also helps a lot. a.map { x in x * 3 } is probably intelligible enough (in Swift) so no need for util.multiplyEveryElementBy3(a)..