|
Hi,
> We've all heard that you should use named constants in place of literals,
> but how far do you take this?
I only use named constants when it clarifies the code. I realize that
this makes it a bit subjective. :)
In your example, having a named constant called STATUS really doesn't gain
you anything over the literal '*STATUS'. Putting it in a named constant
in that case actually increases the work that the next programmer has to
do -- he has to search around to see what the constant contains.
Especially since the programmer won't know that it's a constant rather
than a variable -- and STATUS is a relatively common name for a variable.
On the other hand, x = open('/tmp/blah.txt': 74: 438) is not very
intutive. In that case, the constants clarify things:
x = open('/tmp/blah.txt': O_WRONLY+O_TRUNC+O_CREAT: M_RDWR);
Now, assuming that you're familiar with the parms of this API, you know
what the programmer intended... write only, truncate, and create -- and
grant read/write permissions.
In our shop, anyway, it's not so much a "standard" as it is a "use your
own judgement, just do your best" type of thing.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.