properties

Sergey Gromov snake.scaly at gmail.com
Tue Jul 28 16:07:03 PDT 2009


Tue, 28 Jul 2009 13:20:30 -0400, Steven Schveighoffer wrote:

> Let me come at another angle.  You can't view properties as some sort of  
> enforcement by the compiler.  The compiler is not guaranteeing that if you  
> call something without parentheses, it doesn't execute arbitrary code, it  
> has nothing to do with what the compiler guarantees.  But the *meaning*  
> that the author of the function wishes to convey is available via the  
> requirement of parentheses or lack thereof.  The author of the code is  
> saying "I wrote this function as if it were a field."

I think the reason is purely syntactical.  Specifically to distinguish
nouns from verbs.

Many English words can be used as both.  "Empty" may mean "contains
nothing" or "to throw everything away" and both meanings are equally
valid.  You need context to derive the correct meaning of a word.  You
always have such context in human language because of its nature.
Programming languages are much more formalized which robs you of
context.

Parentheses make a perfect syntactic convention for anybody familiar
with C family languages: verbs have parens, nouns (adjectives, adverbs)
don't.  Because functions do things but variables do not.  So when I
define "empty" as a property in C# I don't promise pure behavior or O(1)
complexity.  I simply state: "This *word* is not a verb. Read it
accordingly."  And it's immediately clear to me that "empty" is "nothing
inside" while "empty()" is "do cleanup".



More information about the Digitalmars-d mailing list