May 13, 2003

Light on, Light Off, Light On.. you get the picture

Ahhh, the power of the electron. Information is nothing more than 1's and 0's. On or off. Alive or dead. As a programmer I sometimes feel like an artist, sculpting binary data into a great work of art, designed to solve some sort of problem. Then again, some days I think all I am doing is welding a couple of beer cans together and calling it 'cultural art'. Other people do that for a living. They are typically called PHP scripters. You get the picture.

Anyways, today was a pretty good day at work. I finally got around to doing fast low level bitwise ops on raw memory to quickly be able to determine if an IP address is within a subnet range. I ended up with some clean, and somewhat easy to understand code that looks something like this:



mask = ( 0xFFFFFFFF ) << (32-bits);

network = raw_range & mask;

broadcast = network | ( 0xFFFFFFFF & ( 0xFFFFFFFF ^ mask ) );

if( ip > network && ip < broadcast )
[ ...]


You get the idea. Those three little lines save tonnes of iterations and function calls by simply accessing pointers to raw memory.. and is required since I don't have access to any user mode libs that do this for me. Then again, being that I rolled my own its also got the benefit of being faster, and smaller than some monolithic library or module.

I have to admit this has been kinda fun. It's nice when you accomplish something like this without the need for a vendors library or built in API. I think we rely to much on other people's code and use the blanket statement of 'code reuse' without really understanding the implications of it. Come on, I know some really bright developers who are perl module sluts (/me waves to Wim) and rely on stuff that is already out there. This is actually a great way to get things out fast, and has its place. But it doesn't mean that from a quality point of view that its better... or worse...

Atleast, not until you start writing kernel-mode code, and you realize you can't rely on such things, and you need to go back to the raw basics at the bare metal. Now I realize WHY operating systems, compilers and drivers are written in C, and C alone.

Yes, I am nuts. I just I hope I don't end up with any ticks or looking like many other kernel developers Alan has commented on recently.

Posted by SilverStr at May 13, 2003 06:31 PM