Tuesday, March 13, 2007
Is SQL Manual Memory Management?
This is a stark contrast to the experience of programmers from the C/C++ generation, as well as (obviously) anybody who works with those languages today. I've never learned a thing about pointers in my life, except during a brief exploration of C and C++ out of curiousity, inspired by friends who worked in video games. It's never been necessary knowledge. Garbage collection is so pervasive today that many, many programmers have never written a line of code without it.
One of the most awesome things about Rails is ActiveRecord, and the near-seamless experience of writing all your migrations in Ruby, so that you can easily code tons of different complete, fully-fledged applications without ever even seeing a single line of SQL. This prompts the question, is SQL essentially the same thing as manual memory management?
Anybody who's ever wrestled with SQL -- especially anybody who had to do it by hand in Perl in the mid-90s, before Perl even had its DBI library -- is going to find the idea that auto-generating SQL is the same thing as garbage collection very appealling and intuitive because the obvious implication is that SQL is, in some sense, garbage. The counterargument is that there are still plenty of cases, even in Rails apps, where you need all sorts of direct access to the database, because there are so many advanced database features that Rails doesn't even make the slightest effort to address. But this counterargument just gives credibility to the main idea -- I'm sure that when C reigned supreme, there were a lot of limitations to using garbage-collected languages, and that these languages had disadvantages which forced even their biggest fans to use C for certain things, until the garbage collection got good enough that it was no longer necessary.
This is kind of programming language sci-fi, but maybe one day people will look back on Rails not as the best Web framework ever, but as the first SQL-collected language. Maybe one day the idea that database management should be part of the language will seem as obvious and basic as the idea that programmers shouldn't have to do memory management by hand. Maybe a language which doesn't handle SQL for you is like an operating system with no sockets model. Maybe an object which can't write itself to the database is a primitive thing. (For that matter, maybe an object which can't generate a URL to itself is a backward thing too.)
I don't know, but it's an interesting idea.
Update: maybe I have used pointers after all.
Posted by Giles Bowkett at 6:38 PM