Revised RFC on range design for D2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Sep 28 18:01:36 PDT 2008


Chris R. Miller wrote:
> Improper use of properties make code that looks ambiguous.  Is that a 
> public member or a method?

Under what circumstances is that distinction important?

> It reduces codebase coherency

How? Why?

>, which is 
> normally not a huge problem except when new programmers are reading 
> through the code to see how it works.

Why do they need to know whether it's a computed or a state value?

> If someone mistook that method 
> call via property as a member, then they might use it as such in code 
> they write.  Because it's actually a method, it has the potential to 
> rope in serious amounts of processor work.

That is the complexity issue that was discussed a while ago in the 
digitalmars.d group. I agree that certain interfaces should come with a 
complexity guarantee. But the line is definitely not drawn at 
member/computed value. Besides public members are bad style to start 
with, so essentially the argument is that everybody must litter their 
code with (). Why? Because there is the implied assumption that what 
doesn't have the () is a member variable access. I am challenging that 
assumption.

> It's the same reason you don't want to overload simple operators in C++ 
> with potentially large algorithms, since it creates an illusion that the 
> operator is really a simple operation when in fact it could be quite 
> tedious.

I agree. That is what the STL does.

> This is - of course - a matter of practice with C++, and isn't 
> a language requirement, but it does illustrate that it's something to be 
> conscious of.  Similarly, you wouldn't want to load up a D invariant 
> with a lot of hard processor work, since that would incur a lot of 
> overhead following each public function call.  There's nothing 
> explicitly wrong about doing it, it's just bad practice (according to 
> some).
> 
> I hope that was coherent.  I believe I read about it in /Code Complete/, 
> if you want a source.

I don't have the latest, so a quote would be helpful.


Andrei


More information about the Digitalmars-d-announce mailing list