properties

Rainer Deyke rainerd at eldwood.com
Tue Jul 28 13:36:43 PDT 2009


I C++, I write a lot of functions with names in the form of get_foo,
set_foo, or is_foo.  The get/set/is isn't just clutter, it serves an
important function in describing the semantics of the function.  A
function named 'empty' has different semantics than a function named
'is_empty'.  A function named 'get_color' has different semantics than a
function named 'color'.

To me, 'y = x;' makes a lot of sense as syntax sugar for 'y = get_x();',
but makes no sense as syntax sugar for 'y = x();'.  Writing 'y = get_x;'
instead of 'y = get_x();' is barely an improvement, and nowhere near as
nice as 'y = x;'.

Likewise, 'x = y;' makes sense as syntax sugar for 'set_x(y);', but not
as syntax sugar for 'x(y);'.  I don't want to have to write 'set_x = y;'.

So, yes, properties are just functions.  However, they are /different/
functions from the functions with the same name as the property, with
different semantics.  Its use as a property is logically part of the
name of a function.


-- 
Rainer Deyke - rainerd at eldwood.com



More information about the Digitalmars-d mailing list