Warning!

Warning. The following publications may induce intense reasoning.

Friday, July 24, 2015

Ordered Code Versus Efficient Code


Listen to this blogcast in MP3 Audio.

The less I say in a single short phrase, the more meaning I pass with less effort. This is also true about coding computer software & websites. Commands can be passed in a simple, very readable fashion, similar to how we would talk to another person.

Or, commands can be passed in sophisticated, complex, and convoluted ways, which logically give the same results. But these complex methods, while more efficient for a computer, are much harder for a human to follow and figure out.

Making voxels with colors, lights, and different selection modes.

I have spent the last few months working on a new project in Node.js, using a front-end library for WebGL, called THREE.js. I am creating a 3D virtual world that uses voxels - 3d particles, usually cubes, for all its objects.

Two choices were in front of me: One, put a keyboard key-press event where it happens, which would be efficient. Two, put the event in a fast loop, where all events are checked at a rate of sixty frames per second, which is not efficient, but very readable and orderly.

When checking the event in the fast loop, I use an IF statement that must be passed, in order to execute anything else. Not surprisingly, for a computer this is insignificant effort, so the performance is not impacted, at all.

If performance would be impacted, then I would choose efficiency over readability. But as long as it is not, then readability is always my priority. If you cannot quickly read through it, then it is too complicated to be practical!

Read 1 comment.

Add your comment:

Constructive, thought-out, and finely argued comments are encouraged.

All Time Popular Posts