Why are there Properties in D?

Dejan Lekic dejan.lekic at gmail.com
Mon Feb 17 17:06:28 PST 2014


Robin wrote:

> Hiho,
> 
> I am learning D since some time and I must say all in all it is
> truely a better C++! I especially like the statement of Walter
> Bright that nowadays it is more important that the programmer can
> easily read programming text and do not have to "interpret" every
> single line by looking into several definitions and declarations
> in order to fully understand what a piece of program text really
> means as programmers normally spend much more time debugging a
> code than writing one and thus it isn't that important to keep
> program code short - more important is clean and unambiguous code.
> 
> But what about Properties - the feature where functions can be
> called as if they were member variables ...
> Isn't this a step backwards if you think about the sentence above?
> 
> With Properties used in a code a programmer again has to look up
> the definition of all calls and assignments of variables just in
> case they could be Properties and not just member variables.
> 
> So I am asking why should one use Properties? The only advantage
> is that one can leave out the nasty "()" but the disadvantage is
> that especially new people who are working out a code of another
> person or people who have to inspect older code may have a harder
> time understanding what really happens especially if Properties
> are "overused".
> 
> In my opinion this leads to less clear code.
> 
> But maybe I am overlooking something and things aren't that worse
> so it would be nice if someone could tell me about other
> advantages of Properties. =)
> 
> Robbepop

I understand your frustration. It gets even worse when properties are mixed 
with UFCS. People who are new to D just get more confused. :)
I do not know, I find it very hard to read, personally, so I do not abuse 
them like some other people do. I like my code to be understood by anyone in 
the first "code scan".

-- 
http://dejan.lekic.org


More information about the Digitalmars-d mailing list