Saturday, December 10, 2011

Endless looping

One of the worst errors you can manage to drum up in programming is that of the endless loop.  It's not the worst in it's difficulty to track or fix (usually) but in that it is a common pitfall that the "get-some" programmers like myself who charge into projects with guts and not a much else fall into.  I'm not saying other programmers who are more careful or intent don't find these nasty errors awaiting for them, but they happen, quite often.  A slip of the fingers while typing or a momentary lapse in logic is all that it takes for your program to decide that it's going to sit and keep doing the same thing over and over and over again because it said so.  Or rather, because I said so.

It breaks your program, without fail, and depending on the location of this error or what your loop was trying to preform, it eats up a heck of a lot of memory on you processor and slows everything else down.

The solutions to these endless loops should be evident.  You forgot to add a good ending condition to your loop, such as saying

do {
//stuff
} (while true);

That, while a very simple case, is usually what happens.  But then you get the times where the solution is not clear, and you spend hours searching through what looks like perfectly good code for a tiny error that renders all of your hard work obsolete.

Especially in the case of linked lists (which is a list of objects that know where the previous object and the next object are in memory, and nothing else) if you don't manage your memory correctly then you can lose your place in the loop, and it will never complete, sitting idle, lost in the maze of your computer's heap memory, unable to find the next link and move on.

That's a bit dramatic, but if you couldn't tell I'm attempting to relate this endless loop to something more than programming.

Endless loops don't just occur within the realm of the nerds, geeks or computationally-proficient-yet-socially-ineffective.  They occur in real life, too.  And they are every bit as bad, if not worse, as the kind that I run into while jumping feet-first into programming hell. (a.k.a. my creative process)

It would seem I'm prone to all kinds of ceaseless loops.  Making the same mistakes, acting in the same manner and preferring to stay in what I know as comfortable instead of stepping out of the hovel I've made for myself in life and doing what I haven't dared to do, and speaking when I have made myself err on the side of caution and kept my words and feelings to myself.

This is what happens when I try and program late into the night, logic leads way to philosophy and pragmatism melts into introversion.  At least let me say I envy the man who can claim to live without regrets, for he must be able to sleep much better than I, or he's a filthy liar but at least he exudes confidence, a point for him.


I guess while I'm here I should also update as to what I've done programming-wise, since this is the purpose of the blog, after all.

Part of the reason why I'm in the melancholy and reflective endless-loop mood is because today I spent far too much time trying to debug some of my old camera code, which I did not comment well and took me forever to add and extra feature.  It was something I had always planned on adding, camera rotation, but I had never gotten around to until David mentioned he would like to use such a feature in his up-and-coming project.  So I got it done.  There's still some stuff to iron out, but that's for tomorrow.  That and trying to finally get my stupid Kinect working with my computer.

Oh, technology.  I just couldn't have been an athlete, could I?
But then, I wouldn't be Kevin, I guess.




-Kev

No comments:

Post a Comment