- 5mo ·
- 1m read ·
-
Public·
-
status.pointless.one
@noelrap All right, that was 3am during an air raid alert but now it’s morning so here it goes.
First of all, you do you. If it works for you, fine. If I ever lay my eyes on code like that I will judge it but that ultimately shouldn’t concern you or anyone really.
All-public is bad design. It’s basically Hyrum’s law accelerationism. Exposed bits are assumed to be available for use. Users will look through available API surface and will use those things even if they might’ve used something else instead. This also increases chances of incidental coupling. Thus locking not only the public API portion of the code but also internal—functional—part of it.
Testing argument, I believe, is misguided. Tests are not the product. Tests are developer confidence booster. They’re a poor design tool as they tend to expose every single bit. Presumably, you have an application you’re writing your service object, or a library, or whatever. That, presumably, models some domain process. Use that as your guide for exposed functions. You mention that it’s hard to test complex service objects that have only one public method. Use `send` if you feel that’s easier but also consider that every unit test on that extracted method might shift you further away from good coverage. You might have 100% coverage of individual methods but you might not have coverage on all the combinations they’re used together.
This testing of “private” methods can hide another issue. These methods might appear used (they’re hit by tests) but they might be not used anywhere in the application code. Smaller API surface can suffer from this, too. But it’s easier to spot dead code when most of the tests describe problem domain which tends to be the case with minimal API approach.
Now, you say that these methods might be useful to users. That’s true. And there’s a solution here: make them public when the use case actually arrives!
From my experience only personal scripts are kinda OK to be all-public: I do what I want, no one but me can stop me and it’s the only case where the developer and the user are in perfect agreement because both of them are me. In any case where those two can be different people I found it’s better to follow minimal public API approach. More so when any of those can be multiple different people.