physics90
physics90

Reputation: 961

Store Values in a Database or Hardcode them

I have a general programming question I’m sure you all have been confronted with at some point. I am working on an app for iPhone/iPad, although this isn’t really an iOS or Objective C question, that needs a few values for identifying and describing certain aspects of the application. For example, I might have shirts for sale as small, medium and large. Should these values just be enumerated in hard code inside of the application or is it better to put them into a database and use a relationship to the other database properties.

PS I’m not selling shirts.

Thanks in advance.

Upvotes: 2

Views: 1830

Answers (2)

ryan1234
ryan1234

Reputation: 7275

From my experience I classify data into three areas:

  1. Hard code a value/make an enumeration etc.
  2. Put a value in a configuration file.
  3. Put data in the database.

If I think a value is going to never change (if it's an array, never have a value added), then I'm ok hard coding it.

If a value will need to be changed often - or I'd like to change it without recompiling - and it's a single value, then I'll put it in a config.

If the data has the potential to change a lot and grow (more and more values added), then I'll put it in a database.

Most of my decisions are driven by laziness. You need to think about the future and what will be the easiest thing to maintain.

As you said though, if the data is needed by other queries in your database, then put it in the database.

No matter what, make sure you have the data in one place. Don't put a value in a config file and the database.

Upvotes: 4

vep temp
vep temp

Reputation: 267

I guess putting them in database would be convenient since it will be easier for you to update the lists in the future.

Upvotes: 2

Related Questions