Xref: utzoo comp.lang.modula2:767 comp.lang.misc:1424 comp.lang.c:9225 comp.lang.pascal:800 Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!uflorida!codas!pdn!alan From: alan@pdn.UUCP (Alan Lovejoy) Newsgroups: comp.lang.modula2,comp.lang.misc,comp.lang.c,comp.lang.pascal Subject: Re: Modula2's godawful IO. Message-ID: <2802@pdn.UUCP> Date: 12 Apr 88 15:29:16 GMT References: <764@ndsuvax.UUCP> <535@m10ux.UUCP> <96@lzaz.ATT.COM> Reply-To: alan@pdn.UUCP (0000-Alan Lovejoy) Organization: Paradyne Corporation, Largo, Florida Lines: 43 In article <96@lzaz.ATT.COM> bds@lzaz.ATT.COM (BRUCE SZABLAK) writes: >I like C++'s overloading of the << and >> operator's even better than >printf. It allows you to define custom print routines for each structure >(class) declared, and then to print (to stdout for example) you do: > cout << god_awful_structure_instance; >The advantage of this approach over using procedures in >modula2 or pascal is (besides previty) that you don't have to >remember the type of structure your variable is; the compiler figures it out. Overloading or procedure-name-abstraction is badly needed in Modula-2. However, it needs to be applicable to ANY AND ALL procedures and operators. For printing, I prefer: Print(object, fieldWidth); The programmer writes a Print procedure for each data type he defines and/or wants to print. Better yet, he writes a "BinToStr" procedure for each data type. Then Print can be defined generically once: PROCEDURE Print(object; fieldWidth: CARDINAL); VAR str: ARRAY [0..79] OF CHAR; BEGIN BinToStr(object, fieldWidth); Display.WriteString(str); END Print; Notice that this also requires the additional capability to define parameters of unspecified type. To compile this procedure, the compiler generates abstract pseudo-code which is data-type independent as its final output instead of object code. Object code for the procedure is generated each time the compiler discovers an actual call to the procedure, because only then can it know the data type of the typeless argument and generate the correct code. -- Alan Lovejoy; alan@pdn; 813-530-8241; Paradyne Corporation: Largo, Florida. Disclaimer: Do not confuse my views with the official views of Paradyne Corporation (regardless of how confusing those views may be). Motto: Never put off to run-time what you can do at compile-time!