If you asked me a year ago if I’d ever return back to C development, I’d probably laugh at you. I mean we have wonderful languages now like Ruby, why would one ever want to use C again? Yeah, if you’re writing a virtual machine, an operating system or video game, C makes good sense. But for a database application? Sounds pretty nuts right? Yes, and no.
I’m going to be consulting on a project soon that is written in .NET (gasps). The CEO of Urbis, Steve Spurgat, devised an interesting, and semi-unique credibility and ranking system that we’re licensing to another company. This system requires some heavy mathematical calculations, on a large set of data. So it was my bright idea to write the calculation engine in C. This provides the following benefits:
- It’s uber fast
- We can use the same code on our Linux servers for urbis.com when it’s done.
So I started researching the MySQL C API, and found it fairly straightforward, but not very streamlined. I wanted a simple wrapper around it to shield some of the complexity and make issuing queries more straight forward.
To issue a simple select query with the API, you have to do something like this .
Not really terrible, but imagine writing code like that every time you want to get some records. The following code is more like it:
if (conn = do_connect("localhost", "root", NULL, "urbis_development")) {
if (res = find("bars", "id, name", "id = 1", conn, NULL, NULL)) {
while ((row = mysql_fetch_row(res)) != NULL) {
printf("%s \n", row[1]);
}
}
}
And out of this, the old_school library was born. It’s still in its infancy. I haven’t even started using it on a real project yet, but I think it’s a really good start. I’m definitely looking for committers, comments, suggestions, or whatever you can offer.
Wow, I haven’t written a line of C code since college (circa 1998), but it feels pretty good to go back to my roots.
What's next? Fortran? COBOL? PL/1?