Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #3839
| Path | csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!gegeweb.org!newsfeed.kamp.net!newsfeed0.kamp.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
| Newsgroups | comp.programming |
| Subject | Re: Best practice for using constants outside of code? |
| Date | Wed, 02 Feb 2011 21:29:42 +0100 |
| Organization | Informatimago |
| Lines | 72 |
| Message-ID | <87oc6udvt5.fsf@kuiper.lan.informatimago.com> (permalink) |
| References | <Xns9E80A0F37DC9Cikkehierbe@69.16.176.253> <4d4970a7$0$81476$e4fe514c@news.xs4all.nl> <Xns9E80A59ADF9BFikkehierbe@69.16.176.253> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| X-Trace | individual.net RStZ6Ga/bgY/l6OldNR27AUZlESCODlG1l7jC9k2NJxNyck+nR |
| Cancel-Lock | sha1:NDZiZjVlMTNhMjZiNGUyMWQ5Mzc4M2JhZDAzMzYzNjQ3OGY0YjI0Nw== sha1:EjI0kGoxEs1aNFEwy6KVm/7qusg= |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== |
| X-Accept-Language | fr, es, en |
| X-Disabled | X-No-Archive: no |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
| Xref | csiph.com comp.programming:3839 |
Show key headers only | View raw
Ikke <ikke@hier.be> writes:
> <snip>
>> That can only be solved by adding another layer of constant/value
>> definitions.
>> How about a simple .INI file?
>
> Thanks for your suggestion!
>
> Unless I incorrectly interpreted your suggestion, that would leave the same
> problem I guess...
>
> The original ini file would be changed from:
> person.gender=1
> to:
> person.gender=ConstGenderMale
>
> The ini file holding the constants would define the constants as:
> ConstGenderMale=1
>
> And the constants in code would remain the same:
> ConstGenderMale=1
>
> As soon as anybody makes a change in either code or .ini, he/she will need
> to remember to change the counterpart in .ini or code as well, which is
> what I was trying to avoid.
Obviously, you will have to define your constants differently:
const
ConstGenderMale = "ConstGenderMale";
ConstGenderFemale = "ConstGenderFemale";
Then of course, since you will have to provide functions to read and
write these representations and convert them into these constant values,
you might want to define a class:
class: Symbol
slots:
name: String;
value: String;
function keyword(name)
new Symbol name=name value=name
function read:
token := parseToken();
if token.type = identifier then
return keyword(identifier)
else
...
method print (self Symbol)
write(self.value)
So you can define:
const
ConstGenderMale = keyword("ConstGenderMale");
ConstGenderFemale = keyword("ConstGenderFemale");
Of course instead of apply Greenspun's Tenth Law all the time, you could
also just use Lisp.
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
Back to comp.programming | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Best practice for using constants outside of code? Jongware <jongware@no-spam.plz> - 2011-02-02 15:56 +0100
Re: Best practice for using constants outside of code? Ikke <ikke@hier.be> - 2011-02-02 15:16 +0000
Re: Best practice for using constants outside of code? "Pascal J. Bourguignon" <pjb@informatimago.com> - 2011-02-02 21:29 +0100
csiph-web