This past weekend I was trying to work on some code that makes use of math. Specifically, I was working on acceleration and velocity, but I didn’t necessarily need a heavy-duty physics engine. I just wanted some low-level C++ code for vector math.
I shouldn’t have to write it myself, right? It’s been done before, by myself and others, and I’m sure some publicly available code would be better tested and more functional than anything I would write. It should be easier to find some code online than to pull out the math books and write my own. There is no need to reinvent the wheel.
It spent about an hour and a half researching a Vector class. It was difficult to find because a number of hits were for imitators or enhancements of std::vector. When I finally found a good implementation, it was part of a small library, but it was fairly trivial to separate it out. I had to make some changes to adapt it to Doxygen, but it definitely beats creating a complete class definition from scratch over the course of a few days.
It was difficult to find code that was generic enough and well-written. Some were too specific or too unwieldy. I found one library that was a “tiny matrix and vector” library, only to discover that the vector was a small footprint version of std::vector. It was one of those WTF moments. I found one class that would have been fine except that the author didn’t bother to present his name or the date that it was created. How can I keep the author’s name in the source code if he/she didn’t bother put it in there in the first place?
I finally found some useful code through Koders, a source code search engine. I also learned about a few other code search engines that I may use in the future:
What do you do when you need some basic code that you know should be available as a library? Do you just take the time to write your own, or do you look for code online? Do you outsource it to someone, using a service like Rent A Coder?