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
From this thread, I think it might be useful to let you declare field
other then write an access function
http://groups.google.com/group/golang-nuts/browse_thread/thread/ffa1c12a24ef8c5c#
type Foo struct {
Index int;
}
type FooIF interface {
GetIndex() int;
Index int;//can we have field declare in interface ?
//let compiler check if structure have this field
}
//access function is annoy.
func (f *Foo) GetIndex() int { return f.Index}
See full explain codes here.
http://gopaste.org/view/eGini
Actually this suggestion is just let user acces witout use reflection.
Since compiler can using Interface do thing like vtable in C++,
I think it should be possible to know what is offset of a field in
structure hide by interface.
The text was updated successfully, but these errors were encountered:
Allowing field declarations in interfaces is a very bad idea. It destroys the strict
separation between implementation and interface. Once the feature is available, it
will be (mis)used, and the resulting code will become less flexible because such
interfaces can only be satisfied by struct with the respective field. We had discussed
this feature very early on in the language design and decided against it.
A better approach is to use accessor functions (and one might argue that Go should
provide automatic accessors, but that is a different discussion).
1. I understand it may work only on structurt, but why feature on interface must
apply too all kind of data ?
2. You know what you want to export, I really don't see the difference to export
accessor function.
I don't know what's the rule called "strict sparation from implementation", what does
it mean and what does it cuase trouble in real?
You have to face this issues, (look how scala and groovy solve accessor functions).
At least this approach is less confusing, faster(no function call overhead).
by Ziyu4Huang:
The text was updated successfully, but these errors were encountered: