Comment On Configuration Disfiguration

In .NET, there are generally two types of information in config files: application-specific and environment-specific. The problem with this setup, though, is managing changes to configuration parameters; it's up to the developer to remember to update config files for each environment. [expand full text]
« PrevPage 1 | Page 2Next »

Re: Configuration Disfiguration

2007-05-17 14:10 • by Adam Petaccia (unregistered)
Man, I hate it when I have to hard code values into configuration files. If only there were some way to have them read in from an external source...

Re: Configuration Disfiguration

2007-05-17 14:29 • by frost (unregistered)
137385 in reply to 137373
Actually, if you implement your configuration classes so the runtime image is a separate dll, you don't need to check everything out and do a full rebuild.

This comment doesn't address the WTFness of the post, of course.

Re: Configuration Disfiguration

2007-05-17 14:33 • by OneMHz
Of course, if the software product is sold to a client and installed on their system, and they need to configure things... then the developer has to compile a version just for them. And probably keep track of each client's version. And any changes would also have to go through the developer team, instead of on-site IT staff. Great model.

Re: Configuration Disfiguration

2007-05-17 14:34 • by mrprogguy
We have a configuration file compiler for our systems; it allows individual contributors to create sections of the final config file that will be distributed with the product, but it's mostly just an exercise in catenation.

(For example, if the host command to perform a given operation is "4LT-*", that's how it is in the subset config file; if that needs to change for whatever reason [to the much clearer "4L3-$," perhaps], then the module owners can just update the subset config item and the next release of the entire product inherits that config item automatically during the build.)

I can't imagine what kind of insane minds think that configuration items ought to be built into the code. That I can't do so is probably a good thing.

Re: Configuration Disfiguration

2007-05-17 14:37 • by whalemangler
So you are saying that just because its a config change in the web.config, you can skip the "test" step. That makes no sense.

Re: Configuration Disfiguration

2007-05-17 14:38 • by jkndrkn (unregistered)
Reminds me of a co-worker that wrote a huge class to output HTML because he didn't like having to write it out by hand. Now not only is it impossible for non-programmer web designers to work on pages he has touched, but even programmers have to scratch their heads when they want to make a simple unordered list.

Re: Configuration Disfiguration

2007-05-17 14:44 • by htg (unregistered)
Oh for the days when configuration files were in the format:

MailServerName=mail.somerandomcompany.com

and you could read them once at the beginning of the application into a singleton settings hashmap that could be accessed from any part of the application when required without having to initialise and run a whole set of XML libraries (during application startup too, thus further delaying the load process).

Configuration files should be simple, and easily alterable without have to invoke a compiler or do any shenanigans apart from !wq and an application restart after your edits.

Re: Configuration Disfiguration

2007-05-17 14:46 • by rmr
It seems like they might be trying to solve a problem I've run up against in the past: having several applications that need to share the same configuration data. Since programmers don't like to have duplicated data, having several similar copies of web.config files is annoying.

I maintain about 12 asp.net applications that all share about 80% of their configuration data. What I've taken to doing is to create a configuration table in the database, which all of the applications load data from. Then I store just the connection string in the web.config files.

Re: Configuration Disfiguration

2007-05-17 14:53 • by joe_bruin
137403 in reply to 137397
htg:
Oh for the days when configuration files were in the format:

MailServerName=mail.somerandomcompany.com


Well, the problem with the key-value pair config files is that they are not Turing complete and therefore cannot be extended until they consume all of the program logic.

Re: Configuration Disfiguration

2007-05-17 14:59 • by Tom (unregistered)
When someone notices that the configuration class has hardcoded the string, they'll demand that it be read in from an XML file? And then someone will notice that the string was hardcoded in the XML file...

Re: Configuration Disfiguration

2007-05-17 15:04 • by Doug (unregistered)
137406 in reply to 137397
htg:
Oh for the days when configuration files were in the format:

MailServerName=mail.somerandomcompany.com

and you could read them once at the beginning of the application into a singleton settings hashmap that could be accessed from any part of the application when required without having to initialise and run a whole set of XML libraries (during application startup too, thus further delaying the load process).

Configuration files should be simple, and easily alterable without have to invoke a compiler or do any shenanigans apart from !wq and an application restart after your edits.


What a surprise, then, that .Net automatically reads these configuration file settings into the singleton hashtable Configuration.AppSettings, which you can access from any part of your application without having to initialize or run any XML libraries.

And, as a bonus, the config file is parsed the first time you access it, rather than on application startup, so that the load process is not delayed.

The real WTF!

2007-05-17 15:04 • by maht (unregistered)
Is XML.

No excuses, no comebacks. A solution to a non-problem.

Re: Configuration Disfiguration

2007-05-17 15:15 • by nobody (unregistered)
Although I do not agree with using dlls for something that should obviously be added to a config file, the only extra step I can see that this adds ( I don't agree that finding the file is an extra step) is to run the unit tests.

I would say that was a benefit, but what do I know :-)

Re: Configuration Disfiguration

2007-05-17 15:30 • by lrb
137422 in reply to 137400
rmr:
It seems like they might be trying to solve a problem I've run up against in the past: having several applications that need to share the same configuration data. Since programmers don't like to have duplicated data, having several similar copies of web.config files is annoying.

I maintain about 12 asp.net applications that all share about 80% of their configuration data. What I've taken to doing is to create a configuration table in the database, which all of the applications load data from. Then I store just the connection string in the web.config files.


You could use Machine.config for the 80% and individual Web.config for the other 20%.

Re: Configuration Disfiguration

2007-05-17 15:33 • by boldtbanan (unregistered)
Damn, I think I worked with these guys at A-B

Re: Configuration Disfiguration

2007-05-17 15:41 • by dpm
137427 in reply to 137406
Doug:
And, as a bonus, the config file is parsed the first time you access it, rather than on application startup, so that the load process is not delayed.


When do you think the first access will occur? During application startup, perhaps?

Re: Configuration Disfiguration

2007-05-17 15:48 • by Scott (unregistered)
Not that it was being used this way here, but I can see a valid use for this type of "compiled config". Your application is still relatively easily reconfigured for different installs, but it prevents the end user from mistakenly (or purposely) viewing and/or changing configuration data.

Yes, there are alternative ways of accomplishing that, but having config in a separate compiled DLL isn't so bad, especially since the creation of these DLLs can be automated and created without ever cracking open the source code (such as CodeDom in .NET).

Re: Configuration Disfiguration

2007-05-17 16:08 • by tpinkney
137436 in reply to 137387
OneMHz:
Of course, if the software product is sold to a client and installed on their system, and they need to configure things... then the developer has to compile a version just for them. And probably keep track of each client's version. And any changes would also have to go through the developer team, instead of on-site IT staff. Great model.


Yeah - my company we have a policy where developers cannot touch the QA servers, UAT servers or PROD servers. We put all code on a buildbox with config changes etc. and a network support person does the build. Xcopy Deployment.

Re: Configuration Disfiguration

2007-05-17 16:14 • by cvi
137440 in reply to 137403
joe_bruin:

Well, the problem with the key-value pair config files is that they are not Turing complete and therefore cannot be extended until they consume all of the program logic.


Which must be the reason OpenAL uses LISP in config files (on linux anyway)...

Re: Configuration Disfiguration

2007-05-17 16:22 • by Bry (unregistered)
"So there you have it; a shining example of a common trend in software development. Solving a problem that doesn't exist with the worst possible solution."

Hey - I think my company has the patent on that ... I am going to sue your infringeing ass...

Re: Configuration Disfiguration

2007-05-17 16:54 • by Squiggle
137460 in reply to 137444
Prior art notwithstanding.

http://en.wikipedia.org/wiki/Reinventing_the_square_wheel

"This is an anti-pattern which occurs when the engineer is unaware or contemptuous of the standard solution and also does not understand the problem or the standard solution sufficiently to avoid problems overcome by the standard. It is mostly an affliction of inexperienced engineers."

Re: Configuration Disfiguration

2007-05-17 16:56 • by J. (unregistered)
There's certain advantages to doing things this way. For example, configuration values are type-checked and you can enforce certain properties, ensuring the correctness of the configuration.

The extra build-step can be avoided too if the code is loaded dynamically rather than expecting an explicitely built assembly.

Still, there's no reason doing this in a language with such a (relatively) complex syntax as C# which on top of things already have a prefectly good solution provided for handling configurations. Then there's the problem with code injection..

Re: Configuration Disfiguration

2007-05-17 16:58 • by Dirk (unregistered)
137463 in reply to 137403
joe_bruin:
htg:
Oh for the days when configuration files were in the format:

MailServerName=mail.somerandomcompany.com


Well, the problem with the key-value pair config files is that they are not Turing complete and therefore cannot be extended until they consume all of the program logic.


Says who? It all depends on what's parsing them. For instance,

ins1=mov $eax, $ecx
ins2= .....

assembler.readProgram(file).compile().run()

Re: Configuration Disfiguration

2007-05-17 17:30 • by lrb
137472 in reply to 137461
J.:
There's certain advantages to doing things this way. For example, configuration values are type-checked and you can enforce certain properties, ensuring the correctness of the configuration.

The extra build-step can be avoided too if the code is loaded dynamically rather than expecting an explicitely built assembly.

Still, there's no reason doing this in a language with such a (relatively) complex syntax as C# which on top of things already have a prefectly good solution provided for handling configurations. Then there's the problem with code injection..


.NET 2.0 introduced typed-checked configuration values. So unless running on a pre .NET 2.0 framework, I don't see any advantage.

Re: Configuration Disfiguration

2007-05-17 17:35 • by Doug (unregistered)
137476 in reply to 137427
dpm:
Doug:
And, as a bonus, the config file is parsed the first time you access it, rather than on application startup, so that the load process is not delayed.


When do you think the first access will occur? During application startup, perhaps?


Not necessarily. In the example from this article, the config setting is a mail server address. So you probably wouldn't read it until you needed to send an email. If a given session of your application doesn't send any email, you never need to load the configuration file.

Re: Configuration Disfiguration

2007-05-17 17:50 • by exaxe (unregistered)
137482 in reply to 137400
Where do you store the db connection string?

Re: Configuration Disfiguration

2007-05-17 17:58 • by SomeCoder (unregistered)
137485 in reply to 137461
J.:

The extra build-step can be avoided too if the code is loaded dynamically rather than expecting an explicitely built assembly.


Loading an Assembly dynamically is a very expensive operation. I've struggled with the piece of crap that is the default .NET assembly loading rules and ended up having to load some assemblies dynamically.

Along these same lines, if you don't load the assembly dynamically and put an assembly reference in your application, then any time you change a configuration, EVERYTHING has to be recompiled. I believe this was listed in the original WTF post.

Bottom line: Don't do this. You are indeed reinventing a square wheel.

Re: Configuration Disfiguration

2007-05-17 18:16 • by chrismcb
137490 in reply to 137461
J.:
There's certain advantages to doing things this way. For example, configuration values are type-checked and you can enforce certain properties, ensuring the correctness of the configuration.

The extra build-step can be avoided too if the code is loaded dynamically rather than expecting an explicitely built assembly.

Still, there's no reason doing this in a language with such a (relatively) complex syntax as C# which on top of things already have a prefectly good solution provided for handling configurations. Then there's the problem with code injection..


Config files are the bomb (am I allowed to use that word anymore?)
Especially for values that might potentially change, like say your mail server.

But for values that will never change, like maybe your domain name (no one ever changes your domain name, right?) hardcoding values is ok. But use const's or at least make the readonly's static!

Re: Configuration Disfiguration

2007-05-17 18:41 • by JRoyale (unregistered)
I really hate editing config files too and I just wish I could put arbitrary code in my config files so they could self modify themselves as needed.

Re: Configuration Disfiguration

2007-05-17 18:49 • by poochner
137501 in reply to 137490
chrismcb:

But for values that will never change, like maybe your domain name (no one ever changes your domain name, right?) hardcoding values is ok. But use const's or at least make the readonly's static!


Companies get bought, merged, whatever. We had a healthcheck on a stock system that used our company symbol. The comments in the check code were something like "if this goes away, we have more important problems than the quote system." Needless to say, due to a merger our symbol changed...

And what about java package names? That can get messy real quick. Part of a company gets sold off, so the web service names do what? Change to the new domain? All your customers / clients have to rebuild their code? gah!

Re: Configuration Disfiguration

2007-05-17 18:58 • by someone (unregistered)
137505 in reply to 137490
chrismcb:
J.:
There's certain advantages to doing things this way. For example, configuration values are type-checked and you can enforce certain properties, ensuring the correctness of the configuration.

The extra build-step can be avoided too if the code is loaded dynamically rather than expecting an explicitely built assembly.

Still, there's no reason doing this in a language with such a (relatively) complex syntax as C# which on top of things already have a prefectly good solution provided for handling configurations. Then there's the problem with code injection..


Config files are the bomb (am I allowed to use that word anymore?)
Especially for values that might potentially change, like say your mail server.

But for values that will never change, like maybe your domain name (no one ever changes your domain name, right?) hardcoding values is ok. But use const's or at least make the readonly's static!


Then there is still the problem with code injection...

There is a place for everything. This is a bad solution to a simple problem, but if this is a place where "They really are after me"-style paranoid security is an issue, then it could be seen as a good thing.

Then again, I've got no problems with a quick recompile of my window manager to change a hotkey set...

Re: Configuration Disfiguration

2007-05-17 19:06 • by lua (unregistered)
137508 in reply to 137440
Of course this is actually the problem which the Lua language is supposed to solve (of course it's now been 'borrowed' by everyone else as it's a nice lightweight scripting system...)

Re: Configuration Disfiguration

2007-05-17 19:36 • by Bob (unregistered)
137512 in reply to 137482
Always keep it on paper.

Re: Configuration Disfiguration

2007-05-17 19:36 • by Bob (unregistered)
137513 in reply to 137482
Always keep it on paper.

Re: Configuration Disfiguration

2007-05-17 20:59 • by peon (unregistered)
137517 in reply to 137482
exaxe:
Where do you store the db connection string?

The last place I worked, the guy kept it in a table in the database itself.

YA RLY

Re: Configuration Disfiguration

2007-05-17 21:04 • by Ernest (unregistered)
137518 in reply to 137490
chrismcb:

Config files are the bomb (am I allowed to use that word anymore?)
Especially for values that might potentially change, like say your mail server.

But for values that will never change, like maybe your domain name (no one ever changes your domain name, right?) hardcoding values is ok. But use const's or at least make the readonly's static!


Bah! My company recently acquired another company. The massive, home grown order entry system that runs said company is completely tied to the original company's domain name and user name convention.
CAPTCHA ewww ... Ewww is right!

Re: Configuration Disfiguration

2007-05-17 23:14 • by Jon Limjap (unregistered)
137520 in reply to 137400
rmr:
It seems like they might be trying to solve a problem I've run up against in the past: having several applications that need to share the same configuration data. Since programmers don't like to have duplicated data, having several similar copies of web.config files is annoying.

I maintain about 12 asp.net applications that all share about 80% of their configuration data. What I've taken to doing is to create a configuration table in the database, which all of the applications load data from. Then I store just the connection string in the web.config files.


Ever heard of machine.config?

Re: Configuration Disfiguration

2007-05-18 00:46 • by Dotnetter (unregistered)
Hmmm both are wrong actually. the correct way to store email settings with asp.net is

<system.net>
<mailSettings>
<smtp>
<network host="mail.contoso.com"
userName="email@contoso.com" password="password" />
</smtp>
</mailSettings>
</system.net>

Re: Configuration Disfiguration

2007-05-18 02:53 • by exaxe (unregistered)
137545 in reply to 137400
Where do you store the db connection string?

Re: Configuration Disfiguration

2007-05-18 03:45 • by TheBigYin
137548 in reply to 137392
The company I'm working for at the moment (no names no packdrill) insist I write every JavaScript function as an injection function in a .NET class. Not only does this make incremental development of the Javascript a PITA (since I have to do a compile-build-deploy cycle every time I change the JS) it also makes it almost impossible for any subsequent JavaScript sepcialist to change or add to the code without the whole development solution being available a full knowledge of the .NET Helper pattern.

Why not just put it in the aspx file? If it needs to be reused, include the JS file?

Why am I complaining, it ekes out my (per hour) work to a week instead of a day :)

Re: Configuration Disfiguration

2007-05-18 04:12 • by Watson (unregistered)
137551 in reply to 137406
Doug:
What a surprise, then, that .Net automatically reads these configuration file settings into the singleton hashtable Configuration.AppSettings, which you can access from any part of your application without having to initialize or run any XML libraries.
Where .NET, obviously, uses some desperate Perl hacker's collection of regexps.

Re: Configuration Disfiguration

2007-05-18 06:41 • by java.lang.Chris;
137558 in reply to 137397
htg:
Oh for the days when configuration files were in the format:

MailServerName=mail.somerandomcompany.com

and you could read them once at the beginning of the application into a singleton settings hashmap that could be accessed from any part of the application when required without having to initialise and run a whole set of XML libraries (during application startup too, thus further delaying the load process).

Configuration files should be simple, and easily alterable without have to invoke a compiler or do any shenanigans apart from !wq and an application restart after your edits.


Ah, the Java way. However you have to remember this is the .Net way where XML is king (MicroSoft gave us the disaster known as SOAP lest we forget). I'm sure there's something in this wonderful .Net IDE I keep on hearing about that hides the XML format behind a nice table widget that lists name value pairs. If not, then when faced with XML format then the originators of the compiled class of configuration options probably thought they were just replacing one WTF with another.

Re: Configuration Disfiguration

2007-05-18 06:47 • by java.lang.Chris;
137559 in reply to 137551
Watson:
Doug:
What a surprise, then, that .Net automatically reads these configuration file settings into the singleton hashtable Configuration.AppSettings, which you can access from any part of your application without having to initialize or run any XML libraries.
Where .NET, obviously, uses some desperate Perl hacker's collection of regexps.


Yes, because
"([^=]+)=(.+)"
is so desparate and such a huge collection ...

Re: Configuration Disfiguration

2007-05-18 07:38 • by exaxe (unregistered)
137563 in reply to 137400
Where do you store the db connection string?

Re: Configuration Disfiguration

2007-05-18 07:58 • by Mcoder
137566 in reply to 137461
J.:
There's certain advantages to doing things this way. For example, configuration values are type-checked and you can enforce certain properties, ensuring the correctness of the configuration.

The extra build-step can be avoided too if the code is loaded dynamically rather than expecting an explicitely built assembly.

Still, there's no reason doing this in a language with such a (relatively) complex syntax as C# which on top of things already have a prefectly good solution provided for handling configurations. Then there's the problem with code injection..

That's why I like when people use the simple Perl language to store their settings... That way, we get no extra complexity while still getting all type safety of Perl itself.

Should I mark it as ironical? Or is it clear enough? If I wan't to ensure correction of a setting at runtime, I check it, it is not only the compiler that can do that.

Re: Configuration Disfiguration

2007-05-18 08:25 • by DH (unregistered)
Although no excuse, one of the reasons some developers need configuration classes like this is if any environment-detection or other code needs to be executed at the configuration level.

IMO, one of the flaws with using web.config is that it offers nothing in the way of environment detection - each time a web application is deployed, the developer needs to make a conscious effort to exclude this file, or if changes have been made to it, then merge the changes.

Personally, I use a custom configuration library with environment detection, but something like this should be built into the .net framework.

Re: Configuration Disfiguration

2007-05-18 08:26 • by Rank Amateur
I don't see a problem hard-coding configuration parameters in the code files. That's what constants are for. However, I'm sick of hard-coding my code in the code files. That's why I developed a generic RunIt() function that takes as a parameter a string of code stored in the config file.
--Rank

Re: Configuration Disfiguration

2007-05-18 08:39 • by _js_ (unregistered)
There is a big problem with storing configuration values in a file: updating them centrally.

Config files are fine for personal use apps, but if an app is for business use, then configuration should be in the registry, so it can be updated in an AD integated way using Group Policies.

And with .Net being meant for business applications, I can't understand why they started using xml files other than hype.

Re: Configuration Disfiguration

2007-05-18 08:41 • by TheBigYin
137573 in reply to 137568
Rank Amateur:
I'm sick of hard-coding my code in the code files.


Yeh, me too. I prefer to code them somewhere else.

Re: Configuration Disfiguration

2007-05-18 08:48 • by K Williams (unregistered)
We overcame that problem in our systems by having a web.config.template file - when you run the build script, the .template file is compiled into the final .config file, depending on whether you're compiling for dev, test or release. So, eg. running "build release" creates a web.config using the production values, whereas "build dev" will build one using the developer's local database.

Shell scripting combined with .NET is the way forward!
« PrevPage 1 | Page 2Next »

Add Comment