Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am currently working on a rails project and have a requirement where I want to

ID: 651480 • Letter: I

Question

I am currently working on a rails project and have a requirement where I want to be able to map a country name's initial letters to its ISD code. eg: IND => 91, USA => 1, etc.

The broader question here being (notwithstanding which framework you work on), what should be the best practice to store these things. Should you be using a property file (yaml, in this case)? OR Should you just make a table in the database and read it from there? OR Should you just have a hash_map like structure in your ruby (or any other language) code?

Explanation / Answer

It depends partially on your requirements:

If the configuration is supplied/updated by third parties (e.g. multilingual text resources that translation agencies work on), use whatever they can use easily. If you can choose the format, a very simply text format like YAML or Java Properties is best (but code that consists just of constant declarations could also work).
If you need to be able to update the data while the application is running and via a UI (i.e. admin section of the app), a DB table may be best.
If the configuration is complex (has conditions, hierarchies, overrides, etc.), that's really programming logic and should be done in code. Avoid soft coding.
If none of these is the case, just use what is most popular in your language/framework/community/ecosystem, so other developers will be familiar with it. For Rails projects that seems to be YAML, for Java it's .properties files, etc.