On Saturday, 11 March 2017 02:27:49 UTC+2, Tyler Compton wrote: > > If we assume a more useful generic task than writing a min function, > what's wrong with using code generation? >
There's nothing wrong with in it of itself. It's a tool like any other. Based on the limited information presented about the problem, it seems using code generation is overkill. And also needs more work. 1. Using a single type (e.g. float32) throughout would mean much less code, overall. Whether this approach is viable depends on the context, but I've often seen "generic" solution to a problem that doesn't have to be generic in the first place. Generic code can often end up very vague and with a poor API, due to the nature of trying to do multiple things at once. 2. If the intent was just to implement Min/Max, there are easier alternatives, as demonstrated by the gif. Quite often I end up using that approach instead of code-generation or generics for that matter, because it is much easier to reason about and gets the job done quicker. (of course, it should go without saying, it has its downsides) 3. Depending on the context, there are existing solutions, which would mean you don't have to write the code in the first place. My default position is -- you don't need generics, code generation... Of course, there are places where you need them. + Egon > On Fri, Mar 10, 2017 at 6:14 AM Henry <henry.ad...@gmail.com <javascript:>> > wrote: > >> If you insist on generics-like code generation: >> https://github.com/cheekybits/genny/blob/master/README.md >> >> -- >> 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...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- 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. For more options, visit https://groups.google.com/d/optout.