The other day I had an interesting idea: What if all exported fields have
an implicit getter. Like e.g.
type Human struct {
Age uint
Name string
}
would implicitly get the methods:
func (h Human) Name() string {
return h.Name
}
func (h Human) Age() uint {
return h.Age
}
*When defining an interface*
type Being interface {
Age() uint
Name() string
}
getters would not have to be defined if they simply return a property. This
would remove boilerplate code. But if a modification or calculation is
needed you would just make a private property and define a custom getter.
*Backwards compatibility*
Explicitly defined getters would be overriding the implicit ones and
therefore not change behaviour of existing programs.
This is only an idea. I post this to know if either this is a valid idea
worth considering putting into go or if there is just something wrong with
my style of coding and using interfaces.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.