🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4209

Re: M2 IO

#4209
From: Robert Nagler
Date: Sun, 17 Apr 1988 08:59
64 lines
3958 bytes
In reply to Nevin J. Liber's message:
> Yes, but when you use printf() you have to declare the type of each
> variable in the format string.  If you use C++ streams the compiler does
> this for you.  I know of no other way to do something like this with a
> variable number of arguments.

Sorry for not being clearer.  With "printf" you declare the "output format".
In the C++ example, you say "put this out for me".  In C++, you have the
same problem if you want to output "format specifiers" (as stated in my
previous message).  I repeate the question: Does C++ provide format
specifiers, e.g. "%-.10s", "%10.5e", "%04x", etc.?  I find these very
convenient when doing anything more than debugging output.

>>Does C++ allow infix procedures other than the standard set?

> No.  Doing this tends to lead to unreadable code.  For example: If I
> overload the word 'or' as an infix operator, this sentence no longer has
> the same meaning that I intended (this is because 'word' becomes 'w or d'.
> Did you find the other 'word' in that sentence which contains 'or' yet?).

So you are trying to tell me that if we had overloading in Modula-2, we
wouldn't be able to overload the words "OR", "AND", "NOT", "IN", etc.
because "words" lead to unreadable code?  Some people might argue that:
        e := a AND b AND c OR d;
leads to unreadable code.   For that matter, others might argue that:
        if ((*timer && ((*timer)->tv_sec == 0) && ((*timer)->tv_usec == 0)) ||
            (gfx->gfx_flags & GFX_RESTART)) {
is unreadable.  I think readability is in the eyes of the beholder.

We have established that C++ only allows infix operator overloading.
The next question is: Does C++ allow procedure name overloading (a la
Ada) or default parameters (a la Mesa)?   In other words, do I need
to name my procedures differently even though they perform essentially
the same functions (e.g. could "printf", "fprintf", and "sprintf"
all be called via the same name)?

> Learn about the language before you criticize it!!!
You are right.  Please correct me where I deviate.   I am interested
in C++, but I haven't had a chance to use it.

>>Note the advantage of M2 generics over C++ is that you not only get
>>the pointer, but you have the option of pass-by-value or pass-by-reference.
>>Another important feature is that M2 generics pass the size of the type
>>which can used in a limited form of dynamic type checking.

> C++ has both call-by-reference and call-by-value (the former being
> new with respect to C and the latter being the same as passing an
> address in C), as well as a way to have automatic dynamic type checking
> (if you want the additional runtime overhead that's required).

I wasn't speaking in terms of ordinary parameters.  My point was with
respect to generics, that is, is there an equivalent of ARRAY OF SYSTEM.BYTE
in C++?  It might be called "refany" or something of that ilk.  From my
understanding of C++, I believe generics are handled only by pointers
(a la Modula-2 SYSTEM.ADDRESS).  If this is incorrect, could you do a
quick example and send it to me (or to this list)?

Is C++ dynamic type checking available for arbitrary objects?  We've
got pseudo-dynamic type checking in Modula-2 (implemented in a Module),
but it is limited to pointer variables.  How does one get ahold of the
type of an object in C++?  Is it like "typeof( foo )"?  If so, can one
have "type" variables and/or parameters?

Rob
Technical Details
Message-ID: <8804170859.AA18926@klaus.olsen.uucp>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!mailrus!ames!pasteur!ucbvax!unizh.UUCP!nagler%olsen

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!mailrus!ames!pasteur!ucbvax!unizh.UUCP!nagler%olsen
From: nagler%olsen@unizh.UUCP (Robert Nagler)
Newsgroups: comp.lang.modula2
Subject: Re: M2 IO
Message-ID: <8804170859.AA18926@klaus.olsen.uucp>
Date: 17 Apr 88 08:59:42 GMT
Sender: daemon@ucbvax.BERKELEY.EDU
Reply-To: Info-Modula2 Distribution List <INFO-M2%UCF1VM.bitnet@jade.berkeley.edu>
Organization: The Internet
Lines: 64