Hacker News new | ask | show | jobs
by hughw 3752 days ago
I'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.

1 comments

Yeah, 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)..