gnark-crypto icon indicating copy to clipboard operation
gnark-crypto copied to clipboard

Pointer/non-Pointer refceivers

Open Tabaie opened this issue 3 years ago • 4 comments

Struct methods can take either pointer or value receivers. We have structs with methods of each type, which is currently discouraged by Go documentation. We should either fix all such instances or have an argument why not.

Tabaie avatar Sep 27 '22 20:09 Tabaie

Just out of curiosity, can you explain what you mean when you say, we have structs with methods of both types ?

My incorrect interpretation of this sentence is:

type Foo uint64

func (f Foo) hello()  {}
func (f *Foo) hello() {}

Incorrect because the above would not compile.

kevaundray avatar Dec 05 '22 18:12 kevaundray

I guess it is better to say of each type:

type Foo uint64

func (f* Foo) hello()  {}
func (f Foo) goodbye() {}

Tabaie avatar Dec 05 '22 19:12 Tabaie

I guess it is better to say of each type:

type Foo uint64

func (f* Foo) hello()  {}
func (f Foo) goodbye() {}

Ah thanks for clarifying. To add more context to this issue, I found this article which also corroborates your position.

kevaundray avatar Dec 05 '22 19:12 kevaundray

Makes sense, thank you!

Tabaie avatar Dec 06 '22 00:12 Tabaie