I really think the testability issue is the biggest one. Generally, testing the main package is....cumbersome at least. So it's reasonable to say, "I'm not going to test the main package, but I will keep it so simple that it is impossible for a bug to exist in there." Then everything else in your application can be easily and thoroughly tested with the built-in testing tools.
On Wednesday, February 14, 2024 at 4:40:19 PM UTC-5 Jerry Londergaard wrote: > On Wednesday 14 February 2024 at 10:23:37 pm UTC+11 Mike Schinkel wrote: > > I cannot speak for others but I can tell you why I keep my `main()` small: > > 1. I prefer to put as much logic into reusable packages as I can, and > `main()` is not reusable outside the current app. > > > This is understandable. I guess I'm talking about things that you probably > aren't going to be expecting to be re-imported elsewhere. > > > > 2. CLI packages like Viper are configured to be invoked with just one or a > few small commands in `main()`, and then there is an idiomatic standard for > putting the code for commands in a `/cmd` directory, so that's were most of > the code is typically found that is still part of the app but that is not > in reusable packages. > > > This also makes sense, if there is an idiomatic standard for things in > Viper, then doing it in the expected way is benefit in and of itself. > > > Is there a reason this approach is problematic for you? Just curious. > > > I'm relatively new to Go, so I guess I'm just wondering if there's > something else I'm missing. It would seem that having a dedicated package > that exists purely as the entry point for the application, and can't be > re-imported, > would be the most logical place to put code specific to that purpose that > you don't want re-imported. > > If it isn't anything beyond personal preference, or maybe idiomatic when > using specific libraries, that's obviously fine. I just wasn't sure if > there were > historical, or other technical reasons I was missing. > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/912755c7-f8d4-43c2-8b87-60ba0e48a8b9n%40googlegroups.com.