Ovid (publius_ovidius) wrote,

  • Mood:
  • Music:

Geek Alert

Today has been a geek day for me. I finished my Java homework (mind-bogglingly dull and easy, but time-consuming). I also spent a lot of time thinking about what are referred to as "domain specific languages" and "code generators." What most developers do is take specifications and write a bunch of code that reflects them. That's common, but it's impractical if it can be avoided. The right thing to do is to take specifications and find a way to turn them into the code. Thus, writing the specs is writing the program. To be fair, even though many experienced programmers acknowledge that this is a superior way of doing things, it's rarely done. I once started building a system that did that, but I didn't follow up on it. As it turns out, my new boss has very similar goals for our work. What a pleasant coincidence

Just to give you an idea of how this works, let's say that a movie distributor wants to know how his films are doing on a state-by-state basis. To determine that we might issue an SQL command like the following:

    SELECT   states.name, titles.name, xtns.revenue
    FROM     titles,
             releases, -- e.g., US or Canadian release
    WHERE    titles.id               = releases.title_id
      AND    releases.id             = xtns.release_id
      AND    xtns.theater_id         = theaters.id
      AND    theaters.state_id       = states.id
      AND    releases.distributor_id = 'SONY'
      AND    releases.country_id     = 'US'
    GROUP BY states.name, titles.name
    ORDER BY states.name, xtns.revenue

(This isn't quite how our database is set up, and I've deliberately hidden some things, but you get the idea.)

Is that SQL correct? Who knows? It might be. It might not be. The customer, of course, is in no position to answer that question. All the customer wants to know is the revenue per title per state. And that, actually, gets to be rather interesting. What if that was my program and in a domain specific language?

    DECLARE report IS revenue PER title PER state

Can you really make things that easy? Instead of trying to figure out how to join together five database tables (and deciding which five you need), we simply skip that step. In my example above, it is possible to do, but it takes a lot of work up front. However, that work pays off once you get the benefit of having code that is this easy to write. Of course, some of you may protest that this is what fourth generation computer (4GL) languages were intended to do and those sucked. However, what if, instead of being a 4GL, it generated 3GL code that was easy to manipulate? That's what we do at my current employer and that's what we may do with my new employer. This is what programming is really about: have the computer do what the customer wants instead of having the programmer do what the customer wants. By cutting out the middle-man, as it were, you improve productivity by orders of magnitude. Unfortunately, finding the programmers who can build that system is tough. It's very hard work.

I can't say that I don't find Liv Tyler that
attractive, can I? What if I, like, meet her and
discover I'm wrong and she's read this and
hates me forever, huh? That would suck.

And for the record, soulfulspirit is incredibly aggravating. I want to strangle her while shaking her head violently back and forth. Of course, she wants to do the same to me. I think that's why we get along so well.

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 1 comment