Saturday, April 24, 2010

How big is the internet

The internet is huge with over a billion users, approximately 150 million websites and approximately 75 million servers. How heavy would it be, well , not that heavy only 50 grams. That is the combined weight of moving each of the trillions and trillions of bytes through the internet.

Sunday, April 11, 2010

Real Programmers Dont Write Specs

Well, this is not my original content, I have given a link at the end of the article. They are like rules for judging how real a programmer is and I really found them interesting and funny but not necessarily true. I modified some of them a little to fit my context. Enjoy reading.

Real Programmers don't write specs -- users should consider themselves lucky to get any programs at all, and take what they get.

Real Programmers don't comment their code. If it was hard to write, it should be hard to understand and even harder to modify.

Real Programmers never work 8 to 5. If they are around at 8 AM, it's because they were up all night.

Real Programmers don't play tennis, or any other sport which requires you to change clothes. Mountain climbing is OK, and Real Programmers wear their climbing boots to work in case a mountain should suddenly springs up in the middle of the computer room.

Real programmers don't think they should get paid at all for their work, but they know they are worth every shilling they make.

Real programmers log in first thing in the morning, last thing before they sleep and many times in between.

Real programmers don't like the team programming concept, unless of course they are the chief programmer.

Real programmers have no use for managers.

Real programmers ignore schedules.

Real programers only curse to inanimate objects such as loops, variables and monitors.

Real Programmers spend 70% of their work day fiddling around and then get more done in the other 30% than a user can get done in a week.

Real Programmers don't do documentation. Documentation is for those who can't figure out the listing.

Real programmers are surprised when their cars' odometers dont turn from 9999 to 999A.

Real programmers think they know the answers to your problems and will happily tell them to you rather than answer your questions.

Real Programmers' programs never work right the first time. But if you throw them on the machine they can be patched into working in "only a few" 10-hour debugging sessions.

Real Programmers don't write in Visual BASIC. Actually, no programmers write in Visual BASIC... after age twelve.

Partly adopted from http://www.multicians.org/thvv/realprogs.html

Saturday, April 3, 2010

A window into Exceptions

A friend of mine asked me what exceptions are, and here is my reply in the English language of humans, as opposed to computer jargon.
I will discuss the concept of Exceptions in computer programming. Depending in the programming language you will use, it might come in a different keyword but the concept stands.

An Exception is an unexpected situation/state. When writing a computer program, you have to anticipate all possible states that the program might take during execution. For each possible state that the program would take, you have to tell it what to do. If a program takes a state which was not anticipated by the programmer, it doesn't know what to do and therefore it crashes, popularly referred as throwing an exception in some languages. For example, Lets take a program for dividing two numbers. The basic flow would be: request the user to enter the first number, then the second number, divide them and print the result on the screen. This program as described would be consist of sequential instructions, it assumes all inputs will be 'dividable' which is very wrong. In most circumstances it would run right, but there are two circumstances in which it wont:-
1. If the user entered a non-numerical input, the program would 'throw a fatal exception', in that it would crash with an error.
2. If the user entered a zero denominator, its not possible to divide a number by zero and this would result to a fatal exception too.

So whats the solutions. There are two ways of doing the program right:-

1. Validating input - after each input, the computer validates if the input is numerical, if its not, it doesn't perform the division but instead it prints an error message e.g "Error, invalid input". By doing this, the program does not crash on non-numerical input.
Once the program validates the inputs, it compares the second input (denominator) with zero, if they are equal, it reframes from the division and prints an error message.
If the denominator is not zero, the program may now perform the division and print the result.

2. Handling Exceptions - This means enclosing the program instructions which might throw exceptions in a 'Try...Catch' block. If anything fatal happens in the 'try' block, the program jumps into 'catch' block without crashing. Its therefore common to print an error message in the catch block, the message will be printed only if the program encounters an error. Not all programming languages support this, but most modern languages support it, it comes in differing keywords depending on the programming language.

For those who have a thing for programming, here is sample code in Java and python that demonstrates handling Exceptions, the second approach.

//In Java
import java.util.Scanner;
public class Example{
public static void main(String[] args ){
Scanner read=new Scanner(System.in);
int num1=0,num2=0, result=0;
System.out.println("This program divides two numbers and prints the result");
try{
System.out.println("Enter the numerator");
num1=read.nextInt();
System.out.println("Enter the denominator");
num2=read.nextInt();
}catch(Exception e){
System.out.println("You entered invalid numbers");
System.exit(0);
}
try{
result=num1/num2;
System.out.println("The result is "+result);
}catch(Exception e){
System.out.println("You cannot divide by zero");
}
}
}


#In Python
num1=0
num2=0
result=0
print"This program divides two numbers and prints the result"
try:
print "Enter the numerator"
num1=int(raw_input())
print "Enter the denominator"
num2=int(raw_input())
except:
print "You entered invalid numbers"
exit(0)
try:
result=num1/num2;
print "The result is ",result
except:
print "You cannot divide by zero"

There are different types of Exceptions and its possible to specify to the program on how to handle each type of Exception. For example, the Non-numerical input error would throw a 'NumberFormatException' in Java and a 'ValueError' in Python. A better version of the above program would specifically anticipate such exceptions.

Tuesday, March 30, 2010

If Jesus lived today ...

... Or rather if Jesus lived today, it would be great, Imagine saying today 'God the son is in Palestine( or Israel)'. I would watch him on TV, am sure he would be in 'plenty' on CNN News and have a programme on Family TV. If i happen to go to Israel and meet him, there is a photo of Me and God the Son. I would take his phone number and email address. I would add him as my Facebook Friend, If we happen to be logged on facebook together, we will chat and crack a few jokes here and there.

Jesus is God and has power over Nature, Stopping Earthquakes, Tsunamis and droughts will just be a phone call away. With all those miracles happening, what heart is stubborn enough to still think there is no God, Heaven and Hell? Maybe we will all be saved righteous people.

Jesus will definitely have his own website and although he was born poor, am sure he will drive a good SUV or even a private Jet, not for the prestige but the convenience, the goal is to reach masses here.

We don't crucify people who heal the sick, feed the hungry and raise the dead and those that try to entertain that will be sent to the Hague. The west will issue a statement offering Jesus maximum security and threatening any 'Pilate' of making a misstep,the 'Barabbas' will be crucified. Jesus will remain with us.

The Programmers Prayer

My code wherever you are, hallowed be thy syntax and semantics, thy bugs be not detected. Generate my daily income and forgive thy hosts insufficient speeds and memory. Lead the hosts not into crashing but catch all exceptions. Execute!