Over the last couple of days I have been working on a simple converter for COLLADA (.dae) files to the .uwsm model format originally created by Daniel Livingston at UWS, and built upon by Neil Finlay to be a multi-mesh format complete with a loader for openGL based projects. Neil has also built an exporter for 3D Studio Max so my simple little program has limited value now.
However it wasn’t a complete waste of time as the process taught me a few lessons about programming generally.
- Just because it works once doesn’t mean it will work next time.
- Just because it works on this compiler doesn’t mean it will work on another one.
- If saving files, create a separate directory for them. That way you can easily find them.(To be clear, I mean working with files within code, for example in this project one particular collada file generated 178 separate .uwsm files, so creating them within their own folder kept my project folder tidy.)
Fairly simple things really, but as students I think that we forget that at some point we are going to be writing code for other people to use . With that comes the fact that we have to write code that works every time and which is easy to follow. While working on this little project I was switching between my desktop pc and my laptop, and with only one file in the whole project I didn’t see any real problems, however I am running VS2008 on the laptop and VS2010 on the desktop. To be fair there weren’t any big issues, just some small problems with trying to pass a string (<string>) in as a parameter, when the function apparently required a c-string.
in.open(file_name); // the offending function call.
this seemed to work in VS2010, but VS2008 took the huff and threw errors. Like I said fairly obvious to solve, and really my own fault as I should of just stuck to c-strings as most of the parameters for ifstream and ofstream calls specify them. I will always use strings however as I find them generally easier to work with and find them more intuitive to pass around a program. If a third party really insists on c-strings then you can always use ._str() when you pass it in. In the above example however this was only necessary in VS2008.
“What’s the problem” you ask, “any idiot could fix that.” or even “only an idiot would write that code in the first place.”, but this is just a simple example of a number of similar but more complex incidents I’ve faced recently. At its worst it can lead to hours wasted as you try to get a program to run, and the frustration is worse because you’ve seen it run already on another computer.
The most common one I’ve been having recently is that any project created on another computer complains about not being able to freeglut.dll and I have to put a copy of the .dll in the project folder to get it run. I still don’t understand this as all my own projects seem to mange just fine without doing this, but I do it anyway and that’s fine but I always have this niggling feeling that I should really check it out in more detail.
I seem to have gone slightly off-topic (although I never really had a clear subject in mind when I sat down to write this) so I’ll finish by restating the general gist of the post. Test your programs, and then test them again, then test them, then test them, then test them on another computer, then test them some more. If it still works give it to a friend to test and you can be pretty sure that the first thing they do will be to break it, proving that you didn’t test it enough to begin with.