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,dab7d920e4340f12 X-Google-Attributes: gid103376,public From: nasser@apldbio.com (Nasser Abbasi) Subject: Re: C is 'better' than Ada because... Date: 1996/07/16 Message-ID: #1/1 X-Deja-AN: 168467380 sender: news@biosys.apldbio.COM references: to: "James A. Squire" original-sender: nasser@apldbio.com organization: Applied BioSystems newsgroups: comp.lang.ada Date: 1996-07-16T00:00:00+00:00 List-Id: From: "James A. Squire" Strong-typing alone means less opportunities to screw up. good point. And that's just one area. What about piggy-backing case parts of switch statements because someone forgot to put in the "break;" statements? What about the lack of bounded enumeration types, especially the crucial Boolean type and the corresponding "!=0" default boolean condition, which kicks in because you forgot to specify "==" instead of "="? good points. What about the inability to specify input-only scalar parameters (or can you declare a parameter to be "const" now?)? I am not sure I understand this. Do you mean like doing enumeration IO in Ada ? What about the lack of any boundary checking at all? ^^^^^^^^^^^^^^^^^^^^^^^^^ What about runaway pointers? But runaway pointers is what makes C/C++ programming so much more challenging :) James make good points ofccourse, but I think the view that C++ programmers would have is that some of the above could be fixed by using classes instead of the primitive language data types. At least to the point of boundary checking. As an example, one would use an array class instantiated to the correct type and the size of the array, where this class would throw an exception (or do an assert) if the index is out of bounds. SOmething like this: ---------------------------------------------- template< class type, int dimension> class array { .... type operator[] ( int index) { if( index >= dimension || index < 0 ) throw ... some object as the exception // or assert ( index < dimension && index >=0); // all clear now , index is within range, get the index data return data[index]; } private: type data[dimention]; }; -------------------------------------------- and one would then create objects of this class as array a; // now a is array of int 0..9 array b; // array of chars 0..99 .. now writing this int i = a[11]; // should throw an exception So, in C++ it seems that one can say, if there is something not right in the core langauge, one can use the core language to fix this problem, as the example above show, one uses C++ to fix the fact that C++ do not have boundary range checking. The problem I see with this is that this addes a layer of software between the application/usr and the core langauge, in the above example, this layer is the array class software, so would would then use this class to make arrays instead of using the array construct avaliable in the core language. Adding this layer requires support. Who will write these classes? are they going to be part of the standard libraries, are they going to be well documented and tested? who will do that? Are they going tobe on each platform ? etc.. In Ada, array boundary checking is "build" into the langauge, it is part of the language definition, and what execptions are raised is also defined, so I think this makes it feel safer. But if those C++ classes are become part of the standard library (as STL template classes would be), then there should be less risk in using them I would guess. But now it seems there are many C++ class libraries out there, and code written using one class library one be hard to port to another. Example, If I write my code using Rouge Wave class library, or MFC or etc.. and later on I decided I do not want to use that class library any more, I would be stuck. In Ada, on each platform, the same array boundary is done the same way, since it is in the language, not in some higher library layer. Nasser -- Nasser Abbasi. C/C++/Ada Solaris. GeneAssist - A client/server application for Nucleic acid and protein sequence search and analysis. Perkin Elmer - Applied BioSystem division. email: nasser@apldbio.com MSEE(control), MSCS, MSCE, FM (Fide Chess Master).