Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> You could break it up into 5 separate functions that document their intent semantically, thus blowing up the LOC by 5x

I do this all the time and the "blowup" is not anywhere near that bad.

> or you could write a short comment explaining the intent in natural language.

You really can't. Or rather, you aren't going to convey the information that the new function signatures convey, shorter than the signatures themselves.

> What's more effective?

In my literal dozens of years of experience, the function refactoring. You also get the benefits of less deeply nested code, and more things the compiler can check automatically.

> I'd argue it's always going to be using all the tools at your disposal when and where it makes sense to use them, whether that is comments or self-documenting code.

Sure. Comments allow you, for example, to explain the external pressures and motivations for the semantics of those smaller functions.



Yeah, I am just providing one contrived example. The cost benefit analysis won't always be so obvious as that in reality. My point was that if you're not using a blend of both comments and code semantics to explain your code, then you're leaving explanatory power on the table. It's unlikely that you're explaining the code in the most efficient manner if you're not using all the explanatory power you have available.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: