Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!zephyr.ens.tek.com!uw-beaver!ssc-vax!dmg From: dmg@ssc-vax (David M Geary) Newsgroups: comp.object Subject: Re: named parameters and verbosity [was: Functions without side effects] Message-ID: <4211@ssc-bee.ssc-vax.UUCP> Date: 27 Jun 91 15:01:14 GMT References: <20445@alice.att.com> <1991Jun26.001847.24239@netcom.COM> <1991Jun26.185707.26149@visix.com> Sender: news@ssc-vax.UUCP Reply-To: dmg@ssc-vax.UUCP (David M Geary) Organization: Boeing Aerospace & Electronics Lines: 99 ]> Jim Showalter ] adam@visix ]> argl (4.5, 8, INCR, "bargl"); ] ]> Even with a more readable name for the function, the arguments remain ]> essentially content-free without a lot of surrounding context. The whole ]> point of named parameter association is to provide the missing semantics ]> at the point of call, to wit: ]> argl (Azimuth => 4.5, Inclination => 8, Mode => INCR, Options => "bargl"); ]I almost never put raw constants in my code, both because of the thin ]semantics and because changing the constants becomes a ridiculous ]hunt-and-kill exercise. ("Search-and-replace: 5 [CR] with: 6 [CR]"). ] ]I would write the above in C as follows: ] ]In a header file, perhaps argl.h: ] ]#define STANDARD_AZIMUTH 4.5 ]#define STANDARD_INCLINATION 8 ]#define STANDARD_OPTIONS "bargl" ] ]In the code: ] ]argl( STANDARD_AZIMUTH, STANDARD_INCLINATION, INCR_MODE, STANDARD_OPTIONS ); ] ]The primary motivation for all this is actually to provide a single maintenance ]point (the header file) for parametrizing the behavior of the code. The ]semantics I have worked exclusively with C programmers for 7 years in various software development environments in the real world, and have taught C for 5 yrs in a corporate setting. 3 points: 1. Defining constants as was done above is a standard C'ism. Anyone who has advanced past the first night of an introductory C course is aware of the mechanism for defining constants, and the value obtained by doing so. 14 pages into K&R, we find: "It's bad practice to bury "magic numbers" like 300 and 20 in a program; they convey little information to someone who might have to read the program later, and they are hard to change in a systematic way." 2. Anyone who has advanced past the first night of an introductory C course is also aware that one should name variables and functions with names that convey their meaning: 36 pages into K&R, we find: "It's wise to choose variable names that are related to the purpose of the variable ..." 3. In a posting a few months back, I posted some C code where I defined some functions to be static, which of course, as any C programmer knows, limits the scope of the function to the file that it is in. Jim, in a reply blasting my code did not seem to understand what the keyword static applied to a function meant. From the 3 points made above, I surmise: 1. Jim does not know that the vast majority of C programmers do not use raw constants in their code. 2. Jim does not know that the vast majority of C programmers do not use ridiculously terse names such as arg1() for function names. 3. Jim does not understand how to limit the scope of a function (in C) to the file it is in. 4. Jim does not understand the C language very well. 5. Jim is not qualified to criticize the C language, or it's users. Jim, go ahead and tell us how wonderful Ada is. Ada has some good points, and you can contribute something positive to this group by constantly referring back to the merits of Ada in a software engineering context. Avoid attacking the C language and it's users. You are not qualified to do so, and we are all tired of your exaggerated, absurd straw-man code fragments, and your backhanded insults to the C programming community. PS: Everyone else credits those whom they quote, why can't you? -- |~~~~~~~~~~ David Geary, Boeing Aerospace, Seattle, WA. ~~~~~~~~~~| |-----------------------------------------------------------------------------| |~~~~~~ Seattle: America's most attractive city... to the *jetstream* ~~~~~~| |-----------------------------------------------------------------------------|