Who’s Your Data?

I’ve worked on a lot of different projects and products over the years.  Most of these have been PC-based, file-based storage, applications.  The latest project I’ve been working on has been similar, except that its data is stored in a database.  My colleague, Steve, and I were talking about global data recently, and it got me to thinking about the some of the more horribly structured projects I’ve worked on in the past.

Now, envision that you’re new to a project that’s been in the works for a few years.  There have been a couple of revisions released to the public.  The code has patches scattered around it, copied and pasted code, sparse comments, and data and operation code are intermixed.  In order to write new code, you not only need to understand the data, but the hierarchy of objects that contain the data.  Storing this in files is a recursive process that filters through object after object.  Touch something and something else breaks.  Sounds like most code you’ve worked on, doesn’t it?

Again, envision this code, but with the data stored separate from the operations on the data.  Sounds a bit like Model-View-Control doesn’t it?  Well, even if you aren’t working on something that’s well laid out in a nice, interface-based, MVC pattern, or you want to build something that’s quick and less painful, or you want to migrate some of your code to something similar, a global data area might solve your problem.

I’m not talking about a wad of global variable strewn all over the place (that’s a mess).  I am talking about an in-memory database, with structured information.  In other words, the information that you need to save could be stored in a set of arrays, classes, or structures, that do nothing but hold the information.  All of the other work would be done by other classes.  Think how easily you could write new code to operate on the data without interfering with the other classes that operate on it.  Think how easy it would be to find data.  Think how easily you can implement persistence (save and load).  This could be a simple step in cleaning up some of the spaghetti that’s already in your code-base.