Login
You're viewing the code4lib.social public feed.
  • Nov 1, 2026, 2:53 PM

    Reading about public methods shouldn’t call public methods. Kinda mostly makes sense.

    Helper methods should be private kinda thing?

    Wondering how this impacts testing though.

    This might just be something that needs to click with me, but having split things up into quite testable things, it seems a shame not to test them.

    Perhaps there’s a bad smell here I don’t know about … like these should be functions, not methods?
    …

    💬 1🔄 0⭐ 0

Replies

  • Nov 1, 2026, 2:59 PM

    … I’ve long had a suspicion that a lot of data in classes are sort of globals in disguise, conveniently stuffed into objects, limiting scope a bit, but not strictly.

    In structural programming, which is where I cut my teeth, this data gets passed around on a need to know basis, and accessing things outside the function scope is asking for trouble.

    💬 0🔄 0⭐ 1
  • Nov 2, 2026, 10:49 AM

    @daycoder “Helper” methods/classes/functions are usually/mostly a design smell that something is trying to get out - usually an object or a concept.

    Internal methods should always be private.
    Public methods define the object contract. An object should have one and only one reason to change (SRP), so of course public methods can call (message) public methods! That’s composability right there.
    Tests only ever test the object contract.

    These are fun reminders 🙂

    blog.thirstybear.co.uk/2020/09

    💬 0🔄 0⭐ 0
  • 💬 0🔄 0⭐ 0
  • Nov 2, 2026, 11:08 AM

    @daycoder No idea if that helped. I did have an excellent article squirrelled away about Helper classes and the design smell they reveal, but I can’t find it 😕

    Essentially Helpers are escaped functionality that should be sitting within an existing (or not yet extracted) object.

    The example I usually pull out is EmailHelper with a isEmailValid(email) method. Just move it into Email as isValid()! (Maybe simplistic but you get the drift I’m sure)

    💬 0🔄 0⭐ 1
  • Nov 3, 2026, 3:40 AM

    @thirstybear @daycoder For *classes* that always made sense to me, but for *methods* I went through a stint of confusion: How are you supposed to test the internals if they’re private?

    Until it clicked that, you don’t. Because the point is you test the *externally visible* behavior.

    The test should tell you the public methods do the right thing when called. The fact that they may *internally* delegate some work to private helper methods may be true, but not part of the external contract.

    💬 1🔄 0⭐ 0
  • Nov 3, 2026, 3:42 AM

    @thirstybear @daycoder And that, in fact by trying so hard to test these internal helpers, you make a system more brittle.

    Now you can’t refactor the internals of the class without having to make a bunch of bothersome test changes as well, which makes you less likely to do so.

    Whereas that friction, for the *externally called* methods is actually a good sign that you must be careful to change that contract, as it impacts callers.

    💬 0🔄 0⭐ 0