5 ms·
If I can have a word on FizzBuzz? There are a few programmers that have a proclivity towards "clean, perfect" solutions, but FizzBuzz is ugly. Making FizzBuzz
by GhotiFish 14y ago
If I can have a word on FizzBuzz?
There are a few programmers that have a proclivity towards "clean, perfect" solutions, but FizzBuzz is ugly.
Making FizzBuzz work at all is just stupidly simple; but the moment you ask yourself about the little details, you notice that you either have to make an if tree, a bunch of if-elseif's, or some other hinky thing that ruins the "purity" of this simple little program.
Alot of people take the perspective that if you go
if(i % 15) print "fizzbuzz";
else if(i % 5) print "fizz"; //or was it buzz?
else if(i % 3) print "buzz"; //or was it fizz?
else print i;
then you've found an optimal solution and you can wash your hands of it, until you think to yourself: "but an if tree would use less comparisons! Should I be readable? Or take the efficient route? But if I'm thinking about efficiency. wouldn't a lookup be faster and simpler?"
I suspect when presenting a problem like this, the interviewer filters out two kinds of people: the people who "can't code", and the people who are obsessive.
- papsosouid 14y agoThe entire point is "is this person capable of the most basic fundamentals of programming (conditionals, looping). That's it. We don't filter out obsessive people with it, they demonstrate that they understand conditionals and looping, what's the problem?
- GhotiFish 14y agoI think FizzBuzz does filter obsessive people. Someone who is obsessive wouldn't like their off the cuff solutions to FizzBuzz. They would think of a solution and stop themselves from writing anything at all. How would you tell the difference between someone who doesn't want to write their first three solutions, to someone who can't think of even one? Microsoft's "implement strcmp without the use of libraries" doesn't have this property. strcmp has an easy and clean solution.
- papsosouid 14y ago>I think FizzBuzz does filter obsessive people. FizzBuzz doesn't filter anyone, the people using it do. It is not difficult to explain the purpose of the exercise, and that easily resolves the problem for people looking for "clean" solutions.
- GhotiFish 14y agoIs this your experience? I've seen good programmers, people I know who are good programers, get stammered by FizzBuzz for lack of "clean" solutions.
- papsosouid 14y agoYes. I think you are seriously underestimating the intellectual capacity of those people. Telling them "it doesn't matter how nice it is, or clean it is, or generic, or reusable, or maintainable, it is just to see if you can do basic introductory level code" solves the problem. Anyone who still stands there like a moron writing nothing is useless as a developer, regardless of the reason they stand there.
- GhotiFish 14y agoFair point then. > I think you are seriously underestimating the intellectual capacity of those people overestimating?
- TillE 14y agoLots of practical problems don't have clean, elegant solutions. Maybe part of it will be a beautiful algorithm, but some of the logic will probably be fairly clunky. You have to be able to solve those problems too.
- run4yourlives 14y agoThe entire point of FizzBuzz is to filter out the people that say they can code but clearly cannot. This is a surprisingly high number of applicants, unfortunately.
- GhotiFish 14y agoI agree, I think FizzBuzz has this property, but I think it also has the property of filtering obsessive people as well. You might not want obsessive people either, in which case fizzbuzz is clearly a good choice.
- kragen 14y agoI have sometimes in the past been obsessive to the degree you're describing, and the consequence was that, practically speaking, I couldn't do the thing I was obsessing about.