When I do want to define my own custom getter, how might I tell the language that my new method is a custom getter and not just a method with no arguments and one return value? I think if Go were to have properties, they would have to be explicitly marked as a property in some way to avoid this.
For what it's worth, I'm personally mixed on properties. They do provide a nice syntax for accessing information from an object but they can sometimes make it harder to see what's going on in a program. When I read code in languages with properties, it can be hard for me to know which expressions result in some external code being run and which ones don't. On Fri, Sep 28, 2018 at 3:45 PM 'Peter Müller' via golang-nuts < golang-nuts@googlegroups.com> wrote: > 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 golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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 golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.