Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hard-coded strings vs Resource file

Tags:

.net

asp.net

As the title says then the question is relative simple however I cant decide whether a resource file with strings in is better than hard-coded strings... Whats your opinion?

Thanks in advance

like image 719
ebb Avatar asked Jan 04 '11 20:01

ebb


2 Answers

Main advantage is in localisation. Performance wise resources have a little more overhead but really not much of an issue.

If I am not worried at all about localisation then I would use constants (and not hard-coded strings).

like image 165
Aliostad Avatar answered Sep 16 '22 19:09

Aliostad


Have a realistic look at your application.

Reasons for resource files:

  • Do you support multiple languages? If yes, you will use resource files.
  • You are using a mid-size or bigger application and want to use the same Strings all over your web application? => Use resource files and get strong typed access to all your strings application wide

Reasons for hard-coded strings:

  • Are you using a small application that will most likely not grow much more and localization is most certain not going to happen. => Hard-Coded Strings
like image 31
citronas Avatar answered Sep 18 '22 19:09

citronas