Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am going to face a following issue:

I'm writing a program that manages some properties of my application. Each property is a pair of key and value. Application has general skin and also few customized ones (specific). There are two files with properties for each skin version. The general properties loads each time, specific only in case of corresponding version. The problem was that the properties was often duplicated in the same file (just because of mess) or between different files. It started to be hard and time-consuming to use it. My goal was to write a code that looks over all them and will delete duplicates, replace all properties that are general to general file etc. So there was many many conditions to consider during constructing it i.e: "If a property is placed both in general and specific file, than delete the specific only when the key and value are the same, leave both otherwise. If a property is duplicated inside the same file leave only that which has the largest line number etc...". A lot of if-and-else's and you're never sure that you have all combinations considered.

I think that this is more general problem. You have an objects with a few features and many conditions what to do with this object (state (?)) depending on values of those features (true or false). I am wondering if there is some way of resolving such problems (maybe by some graph, table or drawing) to be sure about taking into account all possible cases. Few years ago I've heard something about finite state machine and Mealy's/Moore's automats, maybe this is such issue?

I've managed with my task only because it was not very complicated by trial-and-error and tests. But my question is simple: what would you type in to google to search good solution or book with similar examples?

share|improve this question
3  
-1, the question is very unclear. For example, what do these things mean in your context: "register", "swap", "property exists somewhere in your system"? And overall, to give you a reasonable answer, IMHO you should tell us what goal you have in mind with your "dependency net". I guess this question has the potential to become a good one, but I think you should invest some more time in describing those things better. – Doc Brown Dec 17 '12 at 13:58
Ok, I'll make it more precise later. – embedd Dec 17 '12 at 14:08
2  
Simultaneously cross-posted on cstheory. Don't do that. – JeffE Dec 17 '12 at 15:14
1  
closed on cstheory as off-topic, so we could keep it here - given the OP invests some time to clarify it. – Frank Dec 18 '12 at 6:47

1 Answer

I would divide your question into 2 parts:

Specific Configuration Files Override General Ones

This is actually quite common, especially on a system where the general file represents system-wide defaults and other files represent per-user settings. I don't see a problem with that design in general. If it is overkill for your application, you could consider merging the general and specific files into one based on the rules your program currently uses for deciding which setting wins.

If someone set something to the default value, you have to presume that they thought about it and decided it was so critical that they needed it set to that value in case the default changes some time in the future. This is not a mess to be cleaned up, but a statement of necessary setup constraints that should be preserved.

Values Specified Twice in One File

You mention settings that are set twice in the same configuration file. Presumably, there is some rule that the last time a value is set overrides all previous settings. Or maybe the reverse is true (first setting within a file is the one that sticks). A better rule would be to exit with an error if a value is set twice in the same file because a human who set a value twice is clearly confused and needs to specify which one they meant!

Finite State Machine

All computers are finite state machines. I don't see what that has to do with this problem. Your issue is one of Inheritance or Overriding as it relates to configuration files. These issues are common in Object-Oriented design. Most of the literature applies them to the design of classes, but the same functionality works for configuration files. You might want to look up Dependency Injection.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.