A switch/case too far...
janderson
askme at me.com
Wed May 21 08:24:10 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 and break
abstractions like that.
-Joel
More information about the Digitalmars-d
mailing list