awalterschulze / goderive

Derives and generates mundane golang functions that you do not want to maintain yourself
Apache License 2.0
1.24k stars 43 forks source link

Function names when deriving for multiple types are not descriptive #33

Closed twpayne closed 7 years ago

twpayne commented 7 years ago

I am interested in using goderive for https://github.com/twpayne/go-geom which exports multiple distinct types.

Some packages may wish to derive functions for multiple types, for example:

package main

type MyFirstStruct struct {
    Int64 int64
}

func (this *MyFirstStruct) Equal(that *MyFirstStruct) bool {
    return deriveEqual(this, that)
}

type MySecondStruct struct {
    StringPtr *string
}

func (this *MySecondStruct) Equal(that *MySecondStruct) bool {
    return deriveEqual(this, that)
}

In this case, there is an obvious conflict: deriveEqual cannot be overloaded to support both types.

Running goderive -autoname resolves this conflict:

$ goderive -autoname .
changing function call name from deriveEqual to deriveEqual_

The function names derivedEqual and derivedEqual_ are not particularly descriptive and easily misread or mis-typed. Instead they should include the name of the type, e.g. deriveEqual_MyFirstStruct and deriveEqual_MySecondStruct.

s-kostyaev commented 7 years ago

I think this can be useful for many derives, not only deriveEqual.

awalterschulze commented 7 years ago

goderive simply needs to see a prefix to know that the function needs to be generated. You can add any descriptive suffix and it will still work.

And if you don't run it with -dedup you will get an error if you mistype it and call it with the same input types.

I hope that helps? Sorry for the delayed response.

On Tue, 29 Aug 2017, 19:52 Sergey Kostyaev, notifications@github.com wrote:

I think this can be useful for many derives, not only deriveEqual.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/awalterschulze/goderive/issues/33#issuecomment-325742955, or mute the thread https://github.com/notifications/unsubscribe-auth/ABvsLTiCV1uYJxQbAadi6ZWdGZSWFglEks5sdE_kgaJpZM4PGSUo .

awalterschulze commented 7 years ago

If you would like to add your project to the users list, please make a pull request :)

That is if I answered your question?

twpayne commented 7 years ago

Thanks! That answers my question - I missed that you could derive multiple functions by using different suffixes. I'll submit a PR to make this more explicit in the README.md and a PR for projects using goderive when I get it working.

awalterschulze commented 7 years ago

Awesome 😀 that will be much appreciated

On Fri, 1 Sep 2017, 10:05 Tom Payne, notifications@github.com wrote:

Thanks! That answers my question - I missed that you could derive multiple functions by using different suffixes. I'll submit a PR to make this more explicit in the README.md and a PR for projects using goderive when I get it working.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/awalterschulze/goderive/issues/33#issuecomment-326517554, or mute the thread https://github.com/notifications/unsubscribe-auth/ABvsLYw60zPxRKtxbhiXGDdxZ1KFxDhrks5sd7rUgaJpZM4PGSUo .