Monday, February 27, 2012

My opinions on *BSD

BSD, the Berkley Software Distribution, is one of the least-used variety of Operating System in the world. BSD has been around for a very long time, even before the times of Linux. It is a version of Unix, the grandfather of most Operating Systems. Technically, Mac OS X is a fork of BSD, which is what allows OS X to be POSIX compliant.

There are a few choices to choose from with your distribution of BSD. Like with GNU/Linux, hundreds of them exist. The more popular ones are FreeBSD, OpenBSD, and PC-BSD. PC-BSD is the only one of the bunch that comes with a graphical desktop environment installed by default, so it is considered the "newbie" BSD. Debian is creating a variant of their OS with the BSD kernel and intends to turn it into a major project, but it is still in early development.

FreeBSD is know for its speed. Speed and performance are the two major selling points for BSD; it even claims to run more efficiently than Linux. FreeBSD is not for the feint of heart, however, because it will take some expertise to get it running properly and to install graphics if that is what you wish to do. You will also have to deal with some outdated repositories, since porting them to BSD takes time.

OpenBSD is focused on providing an extremely secure operating system. I can't vouch for its security personally because I never used it on a server, but it seems to be the choice for companies or individuals who want a secure desktop or server.

PC-BSD is the most user friendly version of BSD. It is criticized for coming with a lot of "bloat" preinstalled. Other lightweight versions of BSD do not come with a lot of features installed, usually just a compiler, a text editor, and a few other tools that can be used from the command line. PC-BSD on the other hand comes with X, a graphical desktop environment, and a few graphical tools that other versions do not have preinstalled. If you are new to BSD, I would greatly recommend PC-BSD as a starting point.

Above are my opinions on some of the various distributions of BSD, but I feel differently towards BSD as a whole. I feel that BSD is far behind Linux in terms of support, package updating, and user-friendliness. The first kernel panic I ever experienced was actually in the LiveCD of PC-BSD. Also, the BSD license allows others to edit the source and turn it into proprietary software, which I don't support morally.

In conclusion, *BSD is great for heavy server use, but for practical desktop usage you should go with another alternative, like GNU/Linux.

Saturday, February 25, 2012

Explaining Obfuscation

Obfuscation is the act of making computer programs more efficient by running through less processes. In this article I will explain how to obfuscate your computer programs. My code snippets are written in the Java programming language, but a lot of the functions are language agnostic.

1. Avoid variables
Variables are used to store information in RAM. RAM is very limited in how much it can hold, so making a lot of variables to store information is a bad idea. Below are two examples of avoiding variables.

boolean stopLooping=false;
bad
for(index=0; stopLooping==true; index++)
{
System.out.println(index);
if(index==5)
   stopLooping=true;
}
Your Computer Science professor will tell you that loops are controlled by the state of a boolean, so you might be tempted to do something like the above example. Instead, do something like this:
good
for(int index=0; index<5; index++)
System.out.println(index);
The above example still uses a boolean, but doesn't waste a variable on it. You could also use and if statement with a break, but since for contains functionality to do so it would waste processor resources.

2. Use centralized variables
 Imagine that you are looking at somebody's code and then have 5 variables.
int x, y, a, b, c;
now, you come across this:
bad
x=4;
System.out.println(x);
y=4;
System.out.println(y);
a=5;
System.out,println(a);
b=9 ;
System.out.println(b);
c=2;
System.out.println(c);
You will be deciphering this for a while, so you should use a centralized variable. A centralized variables provides one place to store information, and then it is overwritten after it has been used.
good
int temp;
temp=4;
System.out.println(temp);
System.out.println(temp);
temp=5;
System.out.println(5);
temp=9;
System.out.println(9);
temp=2;
System.out.println(temp);
In the above example, I could have just used System.out.println() with the number I wanted to display, but the point remains. It's better than initializing a bunch of variables to hold the information.
3) if-then-else cleanup
The last thing I will talk about is the reservation of using if-then statements. Let's say that you want to return true if x==4, or else return false.
bad
if(x==4)
 return true;
else
  return false;
This is actually a very common approach, but here is how it should be done:
good
return x==4;
This approach overall shortens up the code and makes it ever so slightly more efficient. You could also use a conditional operator, but this would be a much better way of doing it.