phipps@fortune.UUCP (Clay Phipps) (07/19/84)
In regard to the suggestion that these predefined symbols ... ought to be chosen so that they are not likely to be accidentally used as variables in somebody's program. ... If predefined symbols were all to begin and end with underscore characters, and this fact were documented, then nobody would fall into the trap of inadvertently using one. Why do I continually run across the suggestion that prefixing names with underscores makes them unique, as if no one has used underscore characters for some special purpose before ? Sorry, the underscore has already been spoken for. The VAX C compiler uses that convention for external names, for example. Conventional VAX UN*X subroutines names, therefore, all begin with "_". Making names all upper case isn't adequate, either, at least for Berkeley Pascal under UN*X [no flames, please; some customers *do* want Pascal, and some want it *badly*; if this weren't the case, I might be able to get the shackle off my ankle and take some vacation], because the Berkeley Pascal runtimes' names are all upper case. Define a variable whose name happens to be the same as one of those routines, for example, "IN" (Pascal "in" operator), and watch the sparks fly ! What is really needed is a name qualification or prefixing convention that can be applied across all of UN*X, for example, <prefix> "_" <mnemonic name> The prefix would be the name of the program or routine package; for example, "cpp" for the C Preprocessor, "lp" for the Pascal Library, &c. Thus, "unix" would become, for example, "cpp_unix", "waterloo" would be "cpp_waterloo", and Pascal Library "IN" could be "lp_in". This isn't perfect, but it's much better than what we have now. Too bad that use of the UN*X subroutines with unqualified names, for example, "read", "write" is too well established to change now. -- Clay Phipps -- { amd hplabs!hpda sri-unix ucbvax!amd } !fortune!phipps { ihnp4 cbosgd decvax!decwrl!amd harpo allegra}
dmcanzi@watdcsu.UUCP (David Canzi) (07/23/84)
> If predefined symbols were all to begin and end with underscore > characters, and this fact were documented, > then nobody would fall into the trap of inadvertently using one. > > Why do I continually run across the suggestion that prefixing names > with underscores makes them unique, as if no one has used underscore > characters for some special purpose before ? The important part of my suggestion was that the convention used be documented. (I ought to have added that it should be mentioned in every document, manual page, or tutorial where it is relevant, so that no C programmer could help but know about it.) Whether the names should look like "_whatever_", or "cpp_whatever" doesn't matter. As long as there is a simple rule for avoiding names that may get magically predefined on you. Computer systems should not spring surprises on users. > What is really needed is a name qualification or prefixing convention > that can be applied across all of UN*X, [Why only UNIX? - DMC] for example, > > <prefix> "_" <mnemonic name> > > The prefix would be the name of the program or routine package; > for example, "cpp" for the C Preprocessor, "lp" for the Pascal Library, &c. > Thus, "unix" would become, for example, "cpp_unix", > "waterloo" would be "cpp_waterloo", and Pascal Library "IN" could be "lp_in". > This isn't perfect, but it's much better than what we have now. > Too bad that use of the UN*X subroutines with unqualified names, > for example, "read", "write" is too well established to change now. What you seem to be suggesting sounds horribly tedious. Well-known and frequently used routines like printf, or getchar should not have prefixes. Only things the typical programmer doesn't need or want to know about (eg. predefined preprocessor symbols, internal library routines, and perhaps system calls) should get prefixed. If I had to say things like "cl_printf(...)" or "cl_getchar()" all the time, I'd go looking for another programming language.