Peter Stuifzand

Programming pattern: Temporary data

Temporary data is a simple pattern that I use while I’m trying to get some code working. The inverse of Temporary data is that you get the data, for example, from a database.

The code you have to write to get the data from the database is often many times as long as the code you need to specify the data structure.

my $languages = [
    { code => 'nl', name => 'Nederlands' },
    { code => 'en', name => 'English' },

If you would like to get this same data structure from your database you have to do a lot of work before this works. You need to design and create a table, fill the table with example data and write code to retrieve the values from that table.

By using this small data structure you can easily start prototyping the interface and the design of page you’re working on.

After you’re done prototyping, designing and coding you can refactor these four lines and replace them with:

my $languages = $db->get_languages();

Related to the simplest thing that could possibly work.

© 2023 Peter Stuifzand