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/35c799df-75bb-4442-9b7f-765273e807ddn%40googlegroups.com.

Reply via email to