a companion discussion area for blog.codinghorror.com

FizzBuzz: the Programmer's Stairway to Heaven


#1

Evidently writing about the FizzBuzz problem on a programming blog results in a nigh-irresistible urge to code up a solution. The comments here, on Digg, and on Reddit – nearly a thousand in total – are filled with hastily coded solutions to FizzBuzz. Developers are nothing if not compulsive problem solvers.


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2007/02/fizzbuzz-the-programmers-stairway-to-heaven.html

#2

I think you just managed to gracefully hit that button in each of us, that makes us want to prove ourselves.

Nicely done :slight_smile:


#3

I’m not going to lie… I didn’t do it as a chalange to your post, but I was afraid I couldn’t do it :-/… Let’s just say I was disappointed in myself. I couldn’t remember how to format strings for printf() nor could I remember how to use cout… and I program everyday, except sunday :).


#4

Comments were down yesterday when I went there. But the answer is: very few (java) folks code in the language’s syntax. Almost all code in some framework, and haven’t addressed FizzBuzz low level problems in years, if not decades. And won’t in any User Application. Doesn’t make them lousy programmers.


#5

In the guitar shop where I’m mostly buying stuff nobody is allowed to play “Seven nation army”. (or a Nirvana song I’ve forgot)
All the clerks roll their eyes if anybody starts playing that.


#6

First solution:

http://www.themathlab.com/music/stairway.mid

I win!


#7
using Codinghorror.Blog;

BlogPost post = Blog.LoadBlogPostByID("00781");

foreach (Comment comment in post.GetAllComments())
{
    if (comment.Index % 2 == 0)
    {
       comment.Tag = "Rockstar developer";
    }
}

sorry :slight_smile:


#8

This reminds me the temptation of trying so when people read “90% of people can’t touch one’s elbow with one’s tongue.”


#9

Jeff after this post i really respect you… really! :smiley:
buuuut i would like to read some articles about java sometime…
i know that properly is not ur field but surely with all your experience, you know alot about it… at least i think so.
Regards

ps. this post is a little off topic argh


#10

Donnie, here’s a good article on Java.

http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html


#11

(Arguing with Pete over hardcoded constants and cargo cult programming)

You got me exactly backwards. I don’t think readability is unimportant; I think it’s critically important. That was the whole point! Separating out definitions for 3 and 5 does nothing good for the readability or maintainability of the solution.

I know that avoiding hardcoded constants is a good guideline, for just the sort of reason you give. But when you turn down that candidate for not following it, is it because they’re a lousy programmer who doesn’t even know the guideline, or a really good programmer who knows it and also knows when it doesn’t apply?

For a really simple example of why it doesn’t apply here: how do you print “Hello World” in your favorite language? is it something like this (using Python 'cause it’s short):

print "Hello World"

or something like this:

import sys
destination = sys.stdout
string_to_print = "Hello World"
print destination, string_to_print

Would you really turn down a candidate who came up with the former instead of the latter?


#12

Writing article about hard drives: -2
Having Wayne’s World reference: +10

You have been redeemed, Jeff.


#13

"so…why not use this to the advantage of codinghorror. Wright a weekly challenge or something. One, it could be fun and two. It might be a good way to learn from other people. There is never just one way of doing things. It would be interesting to see how other people solve problems.

Bryan"

I wouldn’t mind seeing a weekly (perhaps monthly) small challenge like Bryan has suggested, it would be a good way to get responses from your readers. I have this blog on my google homepage so whenever I notice a new post I will read it if I have time (which I usually do between classes).

As a side note…did anybody solve it for their TI-83 plus?
It took me a while due to my lack of syntax knowledge as well as not knowing if there is a remainder function, but it runs.

GO TI-83 plus!

-Dana


#14

I stumbled on the FizzBuzz discussion by accident and enjoyed reading all the way to the bottom. I’m at the other end of the employment train (leaving rather than joining). Programming is just a hobby interest for me and I was delighted to see I had got the FizzBuzz sort-of right quite quickly after failing miserably with a series of non-programming trick questions yesterday.

My experience is that the problem identified by Jeff applies in all fields. Most people can do, by rote, what they have been trained to do but have no idea how to do stuff when a broader perspective is required. At an interviewing course years ago the teacher was adamant about asking interviewees “what do you think of that [experience], looking back?”. In other words, trying to see if they learned anything, or if they could stand outside their experience and look at the big picture. He also said “hire a learner”. [Of course most interviewers haven’t a clue :)]

On thing that was not mentioned was the issue of debugging. Maybe the various posters take that skill as a given. In my experience the ability to diagnose problems efficiently is the most elusive of human skills. It is a skill that is required in many walks of life - auto-mechanic, physician as well as programmer. However the ability to debug seems to have a much higher importance in computer programming.

There are lots of clever ways to solve problems in programming. But the choice of solution depends on the context and the specification - neither of which can be adequately explained in a short question. The solutions that simply printed out the answers line by line work, provided there will never be a change in the requirement. The need to swap to things seems to me to be an undesirable level of cleverness that would lead to problems - and some people identified that.

If I was hiring someone to jump in and write code tomorrow it might be more effective to give them a page of code (ideally on laptop) and ask them to fix it - together with explaining their thought process as they were going about the task.

If I was hiring someone who could grow into the task I would be content with a generic answer to the fizzbuzz problem - for example “loop through the numbers and check whether each number is divisible by 3 or 5. Then print the answer depending on that test” That could lead to another question “how would you know if it was divisible by 3?”. What I would like to know is whether the person was capable of conceiving a solution to a problem - it is easy to look up the details once you have a suitable plan. Indeed, with Google, programming is probably the “science” in which it is easiest to look up the details.

Another characteristic that is sadly lacking among computer geeks is the ability (or willingness ???) to understand the non-computer client’s needs, or to express back to the client his/her need in ways that enable the non-computer person to express the requirement better. I had a sharp experience of this recently where I was never once asked “what are you trying to achieve - maybe there is another solution?”. Personally I regularly find myself saying to someone “I don’t think I understand your question” - and I find it is better to let them struggle to explain themselves rather than to prompt them in what may be the wrong direction. If I was hiring someone who would interface with clients I would be looking for this skill as well as the ability to program. Getting the specification right solves 80% of the problem.

Finally, an interesting aspect of all the responses was the various languages that people use. I think it is 100% safe to say that they are all less comprehensible to the reader than the initial VBscript example. By comprehensible I mean how quickly could you figure out what the program snippet does after you have forgotten how you did it, or could you figure out what someone else wrote.


#15

Well of course.

I suspect that while there was a rapid digression into solution-space, there was also a perceived need to demonstrate that the responder was, through their ability to code a solution, competent to comment.

Guilty as charged, your honour.


#16

Thank you! Very reasonable.
And thank you again for sharing this, as you say it’s depressing but important.


#17

I suppose the article could be interpreted as a challenge; your recent posts about “some people just don’t/won’t get it” would no doubt strike fear into the hearts of aspiring developers who worry they might not “get it”. Perhaps the solutions are merely a self assurance that they are in the exclusive developer club, only for people who “get it”.


#18

As far as I’m concerned, the BrainF**k, Perl and Java solutions are the best. It’s all about the Factory Pattern being reapplied.

When I applied to a certain large software company, there was a timed test for programming certain things in their framework that I would have taken had I gotten to go up there and interview. I’m overall glad I didn’t get the job, but it was definitely interesting to see what they expected.

When I sent them in a really nice set of answers six hours later with quite a nice little GUI, I was pretty insulted to not get a full interview.

I think there’s a line to how many questions like this you should be able to ask. Honestly, it’s really expensive for me to spend four hours staring at a stupid problem. My first solution to this problem would be picked from the best I could find with Google or Experts Exchange with a freeware license. Any time I have a truly hard problem in the real world I get to go ask someone who knows or find an answer that doesn’t suck, so why would it be any different during a test?

“Build me a Wikipedia-style intranet in the next eight months.” Tends to make me think, “Why not just install the Wikimedia and spend a few weeks modding it?” Any other answer I consider silly beyond belief, and encouraging these answers is a cruddy way to do business.


#19

“The mechanical part of writing and solving FizzBuzz, however cleverly, is irrelevant. Any programmer who cares enough to read programming blogs is already far beyond such a simple problem.”

I’m sorry, but I disagree. I read about half the comments on the last post and didn’t see one genuinely good solution to the problem. None contained a single comment, all utilised hard coded constants and most were just plain obfuscated. I’d expect more from students, let alone graduates and professionals.

I think in an interview I’d hire a programmer who couldn’t quite get the problem right (okay maybe not for a problem this simple), but did so in a clear and readable way rather than someone who gets it right but all crammed into a few short unreadable lines.


#20

Looking at the comments to Phil’s post, it turns out some people can’t read at all…