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

>which is how jumping to all those tiny functions and back plays out in practice.

Why would you jump into those functions and back?



Because I need to know what they actually do? The most interesting details are almost always absent from the function name.

EDIT:

For even a simplest helper, there's many ways to implement it. Half of them stupid, some only incorrect, some handling errors the wrong way or just the wrong way for the needs of that specific callee I'm working on. Stupidity often manifests in unnecessary copying and/or looping over copy and/or copying every step of the loop - all of which gets trivially hidden by extra indirection of a small function calling another small function. That's how you often get accidental O(n^2) in random places.

Many such things are OK or not in context of caller, none of this is readily apparent in function signatures or type system. If the helper fn is otherwise abstracting a small idiom, I'd argue it's only obscuring it and providing ample opportunities to screw up.

I know many devs don't care, they prefer to instead submit slow and buggy code and fix it later when it breaks. I'm more of a "don't do stupid shit, you'll have less bugs to fix and less performance issues for customers to curse you for" kind of person, so cognitive load actually matters for me, and wishing it away isn't an acceptable solution.


>Because I need to know what they actually do?

Strange. The longer I've been programming, the less I agree with this.

>For even a simplest helper, there's many ways to implement it.

Sure. But by definition, the interface is what matters at the call site.

> That's how you often get accidental O(n^2) in random places.

Both loops still have to be written. If they're in separate places, then instead of a combined function which is needlessly O(n^2) where it should be O(n), you have two functions, one of which is needlessly O(n) where it should be O(1).

When you pinpoint a bottleneck function with a profiler, you want it to be obvious as possible what's wrong: is it called too often, or does it take too long each time?

> If the helper fn is otherwise abstracting a small idiom, I'd argue it's only obscuring it and providing ample opportunities to screw up.

Abstractions explain the purpose in context.

> I'm more of a "don't do stupid shit, you'll have less bugs to fix and less performance issues for customers to curse you for" kind of person

The shorter the function is, the less opportunity I have to introduce a stupidity.




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

Search: