Thursday, 2 February 2012

Back to Basics

Back in September, I had some words to say about Java. Now I'm gonna say a few about C++.

While I've never been a big fan of templates, I'll admit that I use the STL from time to time just to get things done. On a recent project, I had a need for string-based maps, and as we all know, C/C++ just barely acknowledges strings as a data type. I used the examples, but was running into all kinds of memory errors. Eventually I came to the conclusion that I just don't have the template-fu to do this properly.

Fuck it, I'm a programmer, I should be able to just make something that works for me. So I did. And while I was at it, I made my map keyable on integers as well (I needed to search via two different criteria, and maintaining two containers is wicked error-prone). I learned a lot about searching, and hashing, and a bunch of other miscellanea that I wouldn't have otherwise had the opportunity to explore.

While I'm the first guy to say, "Look around for a library, somebody's probably already done this" - and they usually have - I'm wise enough (I hope) to know when it's time to roll my own. It's a little extra effort, but sometimes it's the only way to go. If you need a Swiss Army knife, but everybody's making plasma torches, make your own knife.

No comments:

Post a Comment