poll for properties

bearophile bearophileHUGS at lycos.com
Tue Jul 28 16:16:48 PDT 2009


Steven Schveighoffer:

> Assuming you have no idea what type Box is, what of the following options  
> looks most natural for xxx in order to test to see if b has an element in  
> it?
> a) if(b.empty)
> b) if(b.empty())
> c) if(b.clear)
> d) if(b.clear())

Probably the most explicit in an OOP language is:
if (b.isEmpty()) {...}
Another solution for D code (that I have used in my Set data structure. But it contains a negation):
if (!b.length) {...}
If the standard opBool() gets added then I can may just (as done in Python to test empty collections):
if (b) {...}


> What would you guess looks most natural for yyy in order to remove all  
> elements from b?
> a) b.empty;
> b) b.empty();
> c) b.clear;
> d) b.clear();

b.clear();


> Which of the following functions looks incorrect?

This looks like a redundant redundant question. I like none of them, because I have just said that empty() doesn't look clear enough to me.
Among those four b c and d look worse.


> Now knowing what the actual meaning of clear and empty are, indicate which  
> version(s) of the function in the previous question would surprise you if  
> it compiled.

It's a ugly API, so I may refuse to use that Box.
Generally I want both of them to end with a ().


> Do you think the meaning of a symbol with parentheses suggests something  
> different than that same symbol without parentheses for the following  
> symbols:
> a) select
> b) rock
> c) keyboard
> d) elevate

The first and last look like verbs, so I'm used to see a () after them.


> Thank you for taking the poll.  I tried to be as objective as possible, if  
> you don't think I was, please indicate why:

The test is objective but I don't like it much, because the shown example doesn't have a good enough API.

Bye,
bearophile



More information about the Digitalmars-d mailing list