You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't have an answer on how exactly it the generating should look like but I'm thinking about situations when generics are useful to me.
Interfaces are some kind of generics but they don't cover all the cases. Let's consider the function below
funcsortInt(in []int)[]int {
//...
}
To implement sorting for float32, float64 etc I have to basically copy&paste the code and change types. To make it easier I can use go generate to automate it.
Writing another sub-program in my project which generates these functions shoulds a bit hacky to me and a bit too complicated compared to what I want to achieve.
What I want to suggest to create a simpler way to do so. What? I don't have a good answer to this question yet. One of my ideas is providing a new package that accepts a template and path to a file and does the generation for me.
go generate -from-file file.tmpl -target somefile.go
The file.tmpl file would be the Go template. Parameters would be bounded from the command line arguments.
go generate -from-file file.tmpl -target somefile.go -arg argName=value1,value2,value3
The text was updated successfully, but these errors were encountered:
bkielbasa
changed the title
(Proposal) Improve generating files
proposal: Improve generating files
Oct 27, 2019
I don't understand what you are proposing. A separate program that can be invoked by go:generate? That doesn't have to be a proposal. Just write the program you want.
I don't have an answer on how exactly it the generating should look like but I'm thinking about situations when generics are useful to me.
Interfaces are some kind of generics but they don't cover all the cases. Let's consider the function below
To implement sorting for float32, float64 etc I have to basically copy&paste the code and change types. To make it easier I can use
go generate
to automate it.Writing another sub-program in my project which generates these functions shoulds a bit hacky to me and a bit too complicated compared to what I want to achieve.
What I want to suggest to create a simpler way to do so. What? I don't have a good answer to this question yet. One of my ideas is providing a new package that accepts a template and path to a file and does the generation for me.
The file.tmpl file would be the Go template. Parameters would be bounded from the command line arguments.
The text was updated successfully, but these errors were encountered: