August 12, 2011

The Importance Of Learning Your Trade

I'm currently majoring in Computer Science, and I think it's fair to say I'm a pretty competent programmer (since I was about to obtain a graduate level developer position during my freshman year at college). And sometimes I hold my colleagues to some high expectations; as I'm sure a lot of my friends in computer science would testify.  However, while browsing the internet for interview related questions, it became apparent that many programmers can't program.



I was pretty shocked by this, especially when I found that many programmers can't write simple fizz-buzz programs.  What's a fizz-buzz program?  Well, in it's simplest form, it's a problem with following rules:
The goal of a fizz-buzz program is to print out all the whole numbers from 1 to 100.  However, if the number is evenly divisible by 3, print "fizz" instead of the number  If the number is evenly divisible by 5, print "buzz" instead of the number.  If the number is evenly divisible by 3 AND 5, print "fizzbuzz" instead of the number.

Seems pretty straight forward, right?  The sad thing is that "the majority of comp sci students can't."

I wondered if it was really that hard, so I wrote one in three minutes using Java:

public class FizzBuzz {
  public static void main(String[] args) {
    for (int i = 1; i < 100; i++) { 			
      if (i % 3 == 0) 				
        System.out.print("Fizz"); 			
      if (i % 5 == 0) 				
        System.out.print("Buzz"); 			
      if (i % 3 != 0 && i % 5 != 0) 				
        System.out.print(i);	 			
      System.out.print("\n"); 	 	
    } 	
  } 
} 


Easy, right? Well, I still wasn't satisfied, so I wrote it Javascript. But this time, I played a little Code Golf with myself; I tried to write it in as little characters as possible:


s=""
for(i=0;i++<100;){ !(i%3)?s+="fizz":+ !(i%5)?s+="buzz":+ i%3&&i%5?s+=i:+ s+="\n"} console.log(s);


It ended up being 96 characters long and took 10 minutes. I'm still a little unsure why this problem is so hard for some students. Maybe it's the modulus that many students are unfamiliar with? Maybe its the lack of practice?

I still have no idea.


5 comments:

Henry said...

At one point I considered switching to a Computer Science major.

Mr Jack House said...

good luck!

Joanna said...

Maybe it's the fact programming is learned as "do this to get this result" rather than learning concepts?

I don't know that you necessarily need to be able to program after getting a compsci degree anyway. Compsci is a pretty diverse field.

Though... if you're going for a dev job... yeah, being able to program kinda is important :)

E.R. said...

That's kinda sad. I've never heard of "fizzbuzz" before, but it only seems marginally harder than "Hello World". Where exactly do people mess up?

Anonymous said...

Shouldn't you be using elseIf in that first example?

FizzBuzz is a brilliant test of a comp-sci students capability, it tests knowledge of:
syntax
loops
branching
output
basic maths skills

as for it being easy, compare it to a test where I ask you to take a car on an empty street, and park it on the other side of the road. Easy, right? But only if you have basic driving skills.

Post a Comment