3 ms·
> If computation is complex and requires multiple subfunctions that you don't want to leak to the global namespace In cases like this, I still use a top-level
by Twisol 4y ago
> If computation is complex and requires multiple subfunctions that you don't want to leak to the global namespace
In cases like this, I still use a top-level free function, but it just instantiates a (private) class and invokes those (private) subfunctions itself. There's usually no need to leak the implementation's strategy for managing complexity to callers.
Of course, if your computation required interactivity with the caller, then it's not a one-and-done batch deal anyway, so free functions would not have been as appropriate in the first place.
- kgeist 4y ago>In cases like this, I still use a top-level free function, but it just instantiates a (private) class and invokes those (private) subfunctions itself That's a good approach I follow myself, too. The fact that I decided to use a class to manage complexity is an implementation detail; callers should not be aware of it. I don't think there's an opposition "free functions vs. classes", they complement each other.