3 ms·
> Documenting code via single-caller functions is usually a mistake, because to everyone else who looks, the set of functions is an API. That's a really good w
by OJFord 7y ago
> Documenting code via single-caller functions is usually a mistake, because to everyone else who looks, the set of functions is an API.
That's a really good way of putting it.
I try to avoid it by not writing new functions, but gladly using existing ones, in my implementation of whatever single new one.
For example if I'm writing a find_and_update_foobar function, I'll use find_foobar if it exists, and with the right signature, but I won't write it just to implement the one I actually care about; ditto update_foobar.
But, professionally I've mainly only used python; so I find it still deteriorates into a mess. (I type hint extensively, but still it only takes some missing hints, or something too loosely - or wrongly - typed.)
I haven't used rust professionally/enough/on something large enough to be sure, but my feeling is that it just having a type checker prevents so much mis-refactoring.
- nicoburns 7y agoInterestingly, Rust can be quite opinionated abour code organisation (it makes you keep things in bigger chunks), because some of the compiler analysis doesn't work through function boundaries.
- heavenlyblue 7y agoI think this one is bullshit, can anyone else comment on this one? Are there things you may only do iff you using a single function body?
- nicoburns 7y agoA key one is partial borrows of structs (i.e. borrowing only 1 field, and then later borrowing a different one).
- zelphirkalt 7y agoBut then what happens to "Your function should be doing one thing and one thing only." (The thing indicated by its name, considering the current abstraction level.)? Perhaps it is not always a bad idea to decompose that function into 2 properly named "steps", which reside in their own functions.