Re:Ten Years of “Go: The Good, the Bad, and the Meh
by Veraticus on Tuesday July 18, 2023 @03:24PM
(#36777917)
I would say that a BulkInsert(Any) is a significant premature optimization over just inserting an object as would apply specifically to that object. Because it sounds like you'd have to do weird reflection stuff on the object to determine how and what to insert where.
If you are inserting an object, you should insert it, rather than create complicated generic insert methods that morph themselves based on the object being inserted. That is idiomatic Go.
Re:Ten Years of “Go: The Good, the Bad, and the Meh
by rowanseymour on Tuesday July 18, 2023 @04:01PM
(#36778332)
My example was a bit simplified but basically the function takes a SQL statement and a slice of structs that use db:column field tags. It's no more doing "weird reflection stuff" than say json.Marshal
Why prematurely optimize for differences that may not (and in practice aren't really likely to) happen?
Keep in mind that the tradeoff with generics is usually not 3 lines of clear or 1 line of hard to read, it's one line of clear code (T -> T), one line of unclear code (Interface{} -> Interface{} + casts), or n lines of complex code (concretely reimplementing the function for your particular case).