For a class declaration like (using a dynamically typed language I am develop):
class Foo
{
var bar
{
get { return bar; }
set(value) { bar = value; }
}
}
User can the write something like:
var f = New Foo();
f.bar = 20;
var n = f.bar;
The compiler then will convert f.bar = 20 to a setter call and n = f.bar in a getter call. What could be an efficient runtime representation of the setter/getter functions inside the Foo class?
Should the compiler decide to use to setter ONLY based on the fact that f.bar is used in an assignment expression?