Kurt Stephens

Nerd Up!

Recent comments

Random image

Latest image

Syndicate

Syndicate content

Browse archives

« November 2008  
Mo Tu We Th Fr Sa Su
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15
17 18 19 20 21 22
24 25 26 27 28 29 30

Data Transform Programming Style

Kurt on Sun, 2006-10-22 22:26.

Data Transform Programming Style is somewhere between imperative and functional programming.

Data representations flow towards the desired result, from least expressive to most expressive. This allows greater reuse of code on multiple data representations, greater locality of intent and more literal coding. The nested nature of functional application is flattened into an imperative style that reads more like pseudo-code, while retaining functional elements.

Imagine a Perl program that takes a list of URIs and turns them into HTML <a href> tags:

# Imperative Example 1:

sub format_uri_as_html
{
  my ($uri) = @_;

  $uri = qq{<a href="$uri">$uri</a>};

  $uri;
}

my $uris = [
  'http://kurtstephens.com',
  'http://google.com',
  'http://digg.com',
];

print map(format_uri_as_html($_) . "\n", @$uris);

Simple imperative programming; we side-effect $uri till we have HTML and return it.

Now requirements change…


links: add new comment | 1559 reads