A switch/case too far...

janderson askme at me.com
Wed May 21 23:07:43 PDT 2008


Mike James wrote:
> I was looking thru some DWT examples and there is plenty of code like this...
> 
> if (myObj is thisObj)
>     // do something
> else if (myObj is thatObj)
>     // do something else
> else ...
> 
> It occured to me how much neater it would be if the there was a switch/case construct that could deal with it..
> 
> switch (myObj) {
>     case thisObj:
>         // do something
>         break;
>     case thatObj:
>         // do something else
>         break;
>     default:
>         // do nothing
> }
> 
> I'm not sure how much compiler 'magic' would be required :-)

That could be nice, however I think RTTI checks like that should be 
avoided.  It would be much better to use polymorphism then break 
abstraction using a switch statement.

-Joel



More information about the Digitalmars-d mailing list