Hacker News new | ask | show | jobs
by dukoid 2047 days ago
I think there is a simple way around the complexity: Make the field "foo.bar" indistinguishable from the outside from the getter / setter pair bar() / set_bar(). This has the disadvantage of losing the ability to distinguish method calls and references by the presence of parens, but I think overall it should pay off.

I have written up some more details here: https://stefan-haustein.com/simplifying-properties

2 comments

This is also known as the uniform access principle: https://en.wikipedia.org/wiki/Uniform_access_principle

I believe Ruby and Smalltalk more or less work that way.

Thanks a lot for the pointer! I was initially distracted by listing C#, JS and Python as examples, but the article clearly states:

"Many programming languages do not strictly support the UAP but do support forms of it. Properties, which are provided in a number of programming languages, address the problem Meyer was addressing with his UAP in a different way. Instead of providing a single uniform notation, properties provide a way to invoke a method of an object while using the same notation as is used for attribute access. The separate method invocation syntax is still available."

Eiffel was one of the first languages to introduce it that way.