views:

28

answers:

2

In terms of strings I understand the need to have strings am going to reuse overname wrapped away somewhere in an XML file or configuration section for strings such as Company Name.

The problem am having with this is where to draw the line on using configuratioh or locally expressed strings?

What decides whether to have the string content wrapped away in a configuration file or to just have the string assigned there and then in a method?

Where am corporate branding a site then yes any corporate aspect strings I will put in a configuration file. Other aspects such as file locations etc will also go in a configuration file.

However, I have found myself discussing with others when I do this as oppose to having an explicit string defined within a method.

Do you have certain criteria that define when to use strings from a configuration section as opposed to being explicitly defined in a method?

A: 

Use configuration when you need to be able to change functionality without redeploying/recompiling.

If your string is reused within your application but the functionality involved is not something you want to be configurable, use a constant.

Oded
If am required to change copyright information in the footer of an aspx page for instance. Would this not require a redeployment regardless of whether it is functionality or a text change in your organisation? Working in a larger org this would require a redeployment regardless.
Gary Thorpe
@Gary Thorpe - If this was information that was only in a `.config`, there would be no need to redeploy the whole web application.
Oded
A: 

I'm thinking that deployment and compilation are a minor consideration. More important is code maintainability. The extremes of a continuum would be on the one hand UI Strings for an international public web site would definitely want to be in a config file, but on the other hand program documentation strings obviously would not. Clearly there is a lot in between that requires judgement. Also in the spirit of maintainability a config file that just contains 2 or 3 strings is more trouble than it's worth and you might as well hard code them. (with the exception being security info -- hashkeys, passwords, etc.) But if you already have a config file set up and some reasonable tools and standards for using the strings, you might as well take advantage of it, and throw all you're potential user facing strings in it.

mjhm

related questions