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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,203d1f2317947ef5 X-Google-Attributes: gid103376,public From: geert@fozzie.sun3.iaf.nl (Geert Bosch) Subject: Re: others clause Date: 1996/09/02 Message-ID: <50d4fc$elf@fozzie.sun3.iaf.nl>#1/1 X-Deja-AN: 177934380 references: <3227AAA6.67C9@ghgcorp.com> organization: La Calandre Infortunee newsgroups: comp.lang.ada Date: 1996-09-02T00:00:00+00:00 List-Id: Mike Bishop (mbishop@ghgcorp.com) wrote: `` In fact, using others is a good idea even when all values are explicitly covered. If you add more values to the type but forget to modify the case statement, you can still handle the new values in the others choice. '' I disagree on this. Say you have code to handle situations A, B and C and these situations are the only ones known to you. Then it is a bad practise to use an "others" choice, because you don't know what would be a good reaction for others. It is better to use no others clause. When you add some new situation D to your program and didn't think about effects on the rest of the code, the compiler will show the place where you have to decide what to do about case 'D'. Then you can think whether a "null" statement would be the right solution, or whether you should really raise an exception if situation D is ever encountered at that place. Forgetting to check if assumptions are still valid when circumstances change is a very common and potentially disastrous error (think of the Ariane 5). Using language features to check as much of your reasoning as possible is a good thing IMHO. Actually, one of the big dangers of object-oriented programming is that assumptions that hold for a base class do not necessarily hold for derived classes. Too many people think that OOP easily scales to large projects and that code reuse is safe, without even thinking about the possible problems. One of the features I'm really missing in Ada is a syntax to specify assertions, pre- and post-conditions and invariants for code and interfaces. Compilers wouldn't have to check these conditions, except some simple cases like static expressions, but they (or external programs) *could* check them and moreover compilers could use them for optimizations. Any new revision of Ada should address this issue, since it is so closely connected to the design goals of Ada. -- E-Mail: geert@sun3.iaf.nl ``I think there is a world market for maybe five computers.'' Thomas Watson, chairman of IBM, 1943