Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!cwjcc!hal!nic.MR.NET!csd4.milw.wisc.edu!uxc!uxc.cso.uiuc.edu!m.cs.uiuc.edu!p.cs.uiuc.edu!johnson From: johnson@p.cs.uiuc.edu Newsgroups: comp.lang.c++ Subject: Re: Improved switch statement (was Re: Message-ID: <77300018@p.cs.uiuc.edu> Date: 29 Dec 88 14:33:00 GMT References: <574@redsox.UUCP> Lines: 16 Nf-ID: #R:redsox.UUCP:574:p.cs.uiuc.edu:77300018:000:902 Nf-From: p.cs.uiuc.edu!johnson Dec 29 08:33:00 1988 This discussion about modifying the switch statement in C++ is pretty amusing. Case statements are bad programming style in object-oriented programs. Instead, you should use virtual functions. Don't say that you want to distinguish the values of integers and virtual functions won't work in that context. That just reveals that you are using integers where you should be using something else. There are certainly places where one should use switch statements, mainly when you are converting from a non-object-oriented part of the system to the clean, elegant part. However, I put switch statements in the same category with goto statements: sometimes necessary but never elegant. Virtual functions are even faster than switch statements. For proof, see the paper by Russo and Kaplan in the latest C++ conference. There is no reason to use switch statements when you can use virtual functions.