poll for properties

Kagamin spam at here.lot
Wed Jul 29 02:20:50 PDT 2009


Steven Schveighoffer Wrote:

> Please respond to this poll before reading other responses.
> 
> Read the following function:
> 
> void foo(Box b)
> {
>    if(b.xxx)
>      b.fill(5);
>    else
>      b.yyy;
> }
> 
> 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())
> 
> Answer:
> =============

a

> =============
> 
> 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();
> 
> Answer:
> =============

d

> =============
> 
> Which of the following functions looks incorrect?
> 
> void a(Box box)
> {
>     if(box.empty())
>       box.fill(5);
>     else
>       box.clear();
> }
> 
> void b(Box box)
> {
>     if(box.empty)
>       box.fill(5);
>     else
>       box.clear;
> }
> 
> void c(Box box)
> {
>      if(box.clear)
>         box.fill(5);
>      else
>         box.empty;
> }
> 
> void d(Box box)
> {
>      if(box.clear())
>         box.fill(5);
>      else
>         box.empty();
> }
> 
> 
> Answer:
> ==============

All of them. It's impossible to determine which method clears and which checks for emptyness. I don't like b.yyy; hanging on its own either.

> ==============
> 
> You read the documentation for Box, and it looks like this:
> 
> /**
>   * check to see if a box is clear
>   */
>   bool clear();
> 
> /**
>   * empty a box, returning true if the box had contents before emptying
>   */
>   bool empty();
> 
> 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.
> 
> Here are the functions again for reference:
> 
> void a(Box box)
> {
>     if(box.empty())
>       box.fill(5);
>     else
>       box.clear();
> }
> 
> void b(Box box)
> {
>     if(box.empty)
>       box.fill(5);
>     else
>       box.clear;
> }
> 
> void c(Box box)
> {
>      if(box.clear)
>         box.fill(5);
>      else
>         box.empty;
> }
> 
> void d(Box box)
> {
>      if(box.clear())
>         box.fill(5);
>      else
>         box.empty();
> }
> 
> Answer:
> ==============

Did you mean, which function's behavior would surprise me in run time? Given the functions' code structure there's only one possible way for meaningful operation: if clause checks for emtyness, else clause empties. So the first two functions will surprise.

> ==============
> 
> 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
> 
> Answer:
> ==============

a,b,d
I remember somewhere verb-like words were used to denote objects...

> ==============



More information about the Digitalmars-d mailing list