Programming practice
uche.ogbuji at fourthought.com
uche.ogbuji at fourthought.com
Thu Apr 1 08:43:22 BST 1999
> >The good programming practice of replacing "magic numbers" with
> descriptive
> >constants is even older than the structured programming movement, and any
> >programmer who writes
>
> But that's not really the point I don't think. The point isn't "if you are
> as macho a programmer as me you don't need any help".
This is a pretty silly representation of what I wrote.
> The point is that we
> work in a commercial environment and every single semantic that can be
> expressed in the code itself, so that the compiler can tell you when break
> them, is a Very Goode Thinge.
It is, of course, a question of degree. A little help from the compiler is
useful, but the compiler cannot hold a programmer's hand and make him adopt
every common-sense good practice. I happen to believe that interface
constants are simple enough to "get right" that it is unnecessary to introduce
complexity and slow performance with such schemes as singleton object
representations.
> It does no good at all to have a named constant if you can accidentally
> pass that named constant to 150 other things for which its not intended and
> the compiler cannot catch it. Its a fundamental lacking in Java that makes
> me shudder to think that people actually want to do serious work in it.
I don't see the disaster you are pointing out:
module Spam{
interface Egg{
const unsigned int SUNNY_SIDE_UP = 1;
const unsigned int SCRAMBLED = 2;
const unsigned int POACHED = 3;
void process(in unsigned int processType);
}
interface Foo{
const unsigned int A = 1;
const unsigned int B = 2;
const unsigned int C = 3;
void bar(in unsigned int param);
}
}
So as I write the code, I simply use the proper constants for the proper interface.
Spam.Egg.processEgg(Spam.Egg.SCRAMBLED);
and later
Spam.Foo.bar(Spam.Foo.B)
No quantum chromodynamics there.
Now why would I ever use a constant that was meant for the Egg interface in the context of Bar, even though Bar happens to have a constant of the same value? I wouldn't mix things up in even the above simple example, so it boggles my mind to think that anyone in their right mind would commit such folly 150 times. Is this the "machismo" to which you allude? I call it basic training, and no compiler or mechanism can prevent a project from the lack of same.
--
Uche Ogbuji
FourThought LLC, IT Consultants
uche.ogbuji at fourthought.com (970)481-0805
Software engineering, project management, Intranets and Extranets
http://FourThought.com http://OpenTechnology.org
xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)
More information about the Xml-dev
mailing list