Hi all,
I'm trying to create a program that can convert text from one format to another, and a lot of rules are necessary in order to do this conversion. So, my idea to handle this was to hold all the conversion data in config files, read it into my program on startup, and then export out the converted text.
The problem I'm running into is this -- I can create as many key-value or key-tuple constructs in my config file as I want, but how can I access them from my program without duplicating them all?
For example, if I had the following line in a config file (assume all keys and values are text strings):
How could I check values without duplicating them in the code like this:
It seems like the only solutions I have are either:
1. Hard code all values inside the code itself
2. Use a config file, then repeat values all over the code
Neither of these things lend themselves well to extension or maintenance, so I think there must be a better way.
Does anyone have a better idea? I'd appreciate any input.
Thanks,
Zel2008
I'm trying to create a program that can convert text from one format to another, and a lot of rules are necessary in order to do this conversion. So, my idea to handle this was to hold all the conversion data in config files, read it into my program on startup, and then export out the converted text.
The problem I'm running into is this -- I can create as many key-value or key-tuple constructs in my config file as I want, but how can I access them from my program without duplicating them all?
For example, if I had the following line in a config file (assume all keys and values are text strings):
Key Value1 Value2 Value3
How could I check values without duplicating them in the code like this:
if( Key = Value1 ) {} else if( Key = Value2 ) {} else if( Key = Value3 ) {}
It seems like the only solutions I have are either:
1. Hard code all values inside the code itself
2. Use a config file, then repeat values all over the code
Neither of these things lend themselves well to extension or maintenance, so I think there must be a better way.
Does anyone have a better idea? I'd appreciate any input.
Thanks,
Zel2008