🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #6296

Never Assume ! (was Re: Union initialization)

#6296
From: Clay Phipps
Date: Tue, 28 Feb 1989 00:48
67 lines
3495 bytes
In article <867@jhunix.HCF.JHU.EDU>,
ins_balb@jhunix (Andrew Barnert (Smilin' Jack // ex-God // etc.)) wrote: 
>
>In article <11860@haddock> karl@haddock.ima.isc.com (Karl Heuer) asked:
>
>>Would [label format for array elements] be workable?
>Yes, but as arrays are inherently ordered, 
>there's no reason to ignore the ordering ...
         ^^ ^^^^^^
>... the comma-separated format is much better for small arrays ...
                                               ^^^^^
>In the case of unions and structures, on the other hand, [labelled format]
>makes sense, as they are ordered only because it is necessary.

As an illustration of the counterexample you might have anticipated,
consider an operator table in a compiler (naturally, I believe that my
somewhat different syntax is *better* :-) 

	union { int precedence; float cost; char *name; } opr_tbl[opr_upb] = {
		...			/* approx. 100 leading entries */
		multd:	{2,50.0, "dp_mult"},
		multf:	{2,20.0, "sp_mult"},
		multi:	{2, 5.0, "int_mult"},
		nandw:	{4, 1.0, "word_nand"},
		negi:	{1, 1.0, "int_neg"},
		norw: 	{4, 1.0, "word_nor"},
		notw: 	{1, 1.0, "word_not"},
		...			/* approx. 100 trailing entries */
	};

Although one could order the enumeration values alphabetically,
there are algorithmic advantages to *ordering* the enumerated values 
by operator category (e.g., logical vs. integer vs. floating-point), or
precedence, but it is preferable not to forfeit the potential readability 
advantages of *presenting* the operator table in alphabetical order.

>It would probably be best to allow any complex type to use
>either the labelled format or the comma-separated format ...

Allowing both provides both algorithmic and readability benefits,
so I agree that it would indeed be best to allow both alternatives 
on the condition that it did not impose an unacceptable cost to do so.

Language designers can't anticipate all of the ways in which features
they design can be put to beneficial use by a conscientious programmer.
*Please* do not preempt decisions by the programmer simply because *you*,
as language or feature designer, can't think of a reason to allow
something whose inclusion imposes little cost, or even *avoids* a cost
(i.e., checking to enforce a somewhat arbitrary restriction).

Bill Wulf and Mary Shaw wrote an informal paper about the preemption
problem a few years ago in SIGPLan (excuse errors in quasi-"refer" format):

	%A Mary Shaw
	%A William A. Wulf
	%T Toward relaxing assumptions in languages and their implementations
	%J SIGPLan Notices
	%V 15
	%N  3
	%D March 1980
	%P 45..61
-- 
[The foregoing may or may not represent the position, if any, of my employer, ]
[ who is identified solely to allow the reader to account for personal biases.]
 
Clay Phipps                         {ingr,pyramid,sri-unix!hplabs}!garth!phipps
Intergraph APD, 2400#4 Geng Road, Palo Alto, CA 93403              415/494-8800
Technical Details
Message-ID: <2571@garth.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!labrea!sri-unix!garth!phipps
References: <51116@yale-celray.yale.UUCP> <437@lakart.UUCP> <11860@haddock.ima.isc.com> <867@jhunix.HCF.JHU.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!labrea!sri-unix!garth!phipps
From: phipps@garth.UUCP (Clay Phipps)
Newsgroups: comp.lang.misc
Subject: Never Assume ! (was Re: Union initialization)
Message-ID: <2571@garth.UUCP>
Date: 28 Feb 89 00:48:21 GMT
References: <51116@yale-celray.yale.UUCP> <437@lakart.UUCP> <11860@haddock.ima.isc.com> <867@jhunix.HCF.JHU.EDU>
Reply-To: phipps@garth.UUCP (Clay Phipps)
Organization: INTERGRAPH (APD) -- Palo Alto, CA
Lines: 67