From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1e4bb63e08046e1a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-30 12:37:21 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.ems.psu.edu!news3.cac.psu.edu!usenet From: Robert Spooner Newsgroups: comp.lang.ada Subject: Re: In case statment? (was Re: is exception when others => null; smart?) Date: Wed, 30 Oct 2002 15:34:56 -0500 Organization: Penn State University, Center for Academic Computing Message-ID: <3DC04270.3060505@psu.edu> References: <3DB8204B.2080804@attbi.com> <3DB89B83.2060609@acm.org> <1b585154.0210291023.70af4929@posting.google.com> NNTP-Posting-Host: nat3.arl.psu.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0 X-Accept-Language: en,de,fr-FR Xref: archiver1.google.com comp.lang.ada:30240 Date: 2002-10-30T15:34:56-05:00 List-Id: If you avoid using "when others" and a value is added to the enumeration type later, the compiler will tell you where _all_ the case statements using that enumeration type are so that you can examine them and see what changes should be made. Then you don't have to spend a lot of time using the debugger to crawl around in your code finding and fixing the parts that don't work right. There's no guarantee that the default case will be correct for a new value, and shifting errors from run time to compile time is one of Ada's bigest advantages in my estimation. Bob Marin David Condic wrote: > Well, one excuse for always having a "when others" in a case statement might > be that you anticipate additions to the enumerated type driving it and you > want the code to take come appropriate action if it gets a new, unknown > value. > > If you never use a "when others", you get the advantage that perhaps the > compiler or runtime will catch inadvertent errors. If you always use "when > others" you get the advantage of a built in accommodation for a software > fault. Its an engineering tradeoff so "never" and "always" don't seem to > really apply. It depends on the nature of the system and the consequences of > hitting a case statement with a value not covered. -- Robert L. Spooner Registered Professional Engineer Associate Research Engineer Intelligent Control Systems Department Applied Research Laboratory Phone: (814) 863-4120 The Pennsylvania State University FAX: (814) 863-7841 P. O. Box 30 State College, PA 16804-0030 rls19@psu.edu