Obfuscation vs clarity

15 08 2008

There is a time and a place for obfuscation. But unless you’re writing hardware drivers, or embedded systems, and therefore have a need to write your code in the smallest amount of bytes possible, there’s really no need for it. Obfuscation reduces flow. The reader can not adequately grasp the obfuscated code as quickly as clear and concise code. Sure if it’s a quick throw away script, obfuscate to your hearts content if you want to. But if the code is ever going to be maintained by anyone, including yourself then never obfuscate. Flow comes from knowing what the code is doing and being able to see where the code as going. Without flow there is no understanding. And without understanding there is no knowledge. And knowledge will help a lot more in the long run than slightly less bytes being used.

As a side note compilers are extremely good at optimising code these days, significantly better than they were just a few years ago. As optimisation is often given as a reason for writing obfuscated code it’s clearer no longer needed in the majority of cases.





The use of Objects and OO techniques

13 08 2008

One of the rules that new coders should learn as early as possible in their training is to not make objects unnecessarily. The over use of objects is one of the many downfalls of the modern coder. Over objectifying your code leads not to re-use (as you’d hope for) but for obfuscation. Objects have there place in the agnostic coders arsenal of tools. But as with all tools, their use is limited, and definitely should be limited to the part of the problem domain that the use of objects can solve.

To take an example, the Java main function is an object. It has to be, the language demands it. But it doesn’t need to be that way. I’m not just picking on Java, but it’s the easiest example to take it’s needed for the simple “hello, world” that every text book will take you through.

But of course this isn’t restricted to Java, other OO languages are the same. But others are not. Take Python for example, a simple example is ‘print “hello world”‘, not complicated is it? And yet it’s in a language whose whole structure is OO based. So clearly using the best tool for the job is of paramount importance.

Most dynamic/scripting languages give you the option of pure OO or pure procedural, or a mix of both. Then again you can code like that in C++ too, so it’s really a matter of choice, which is one of the basic tenets of the agnostic way.

However, as long as you’re using objects for a reason, and that reason relates directly to the problem at hand, then use them, they are there for a reason, to be used. Just make sure you have a reason to use them, just like every other piece of code you build. If it’s not needed, dump it.