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,f92fbb4a0420dd57 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: some questions re. Ada/GNAT from a C++/GCC user Date: 1996/04/02 Message-ID: #1/1 X-Deja-AN: 145453015 references: <4jlj79$h1k@Nntp1.mcs.net> <4jrhj0$lqd@tpd.dsccc.com> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-04-02T00:00:00+00:00 List-Id: [Removed from comp.lang.c++, since I fear C++ folks are bored of this.] In article <4jrhj0$lqd@tpd.dsccc.com>, Kevin Cline wrote: >This is a flaw in the Ada language design, IMHO. Why should >different methods be used to externalize primitive and user-defined types? >It certainly makes program maintainence more difficult; imagine a change >from > > type sequence_number_type is 0..2**32-1 > >to > > type sequence_number_type is > record > time: time_type; > serial: 2**32-1; > end; > >If this change was not anticipated then every use of 'IMAGE to >output a sequence number must be changed to IMAGE(). I suppose. But you'll also have to change other stuff, like any numeric literals, and any arrays indexed by sequence_number_type, and any case_statements, which aren't legal when you change it to a record. This is a much more general issue -- some prefer a language like Lisp, which uses the same syntax for just about everything. If Sequence_Number_Type is really an abstract data type, you'll probably make it a private type in the first place, and then you won't have to change anything outside the package. Actually, I generally do *not* use Integer'Image directly -- I use a function called Image, even for Integer types, and I use type derivation to inherit it. Partly for the reason you stated. Also, Integer'Image has an annoying habit of putting an extra unwanted blank, plus it doesn't work for hexadecimal, and various other formatting options I like to have. >>The "&" operator just concatenates Strings. So to >>print out some stuff, you write: >> >> Put("X = " & Integer'Image(X) & "; and List = " & Image(List)); > >Sloshing all those characters around unnecessarily gets a bit >expensive after a while. This expression is likely to copy the list >image twice before it is actually output. True. We were talking about debugging printouts, so it doesn't matter in that context. In a context where it *does* matter, you can call Put once for each string. Also, in Ada, you can define operators, so you can play the same games as C++ does with "<<" and ">>", although you have to use "&" or something as the operator name. I've never done that, because it seems ugly to me -- a matter of taste, I suppose. - Bob