4 ms·
So how would you answer my question? Would you really dock someone who could give all three of those implementations, but struggled to give a truly horrible imp
by dalke 11y ago
So how would you answer my question? Would you really dock someone who could give all three of those implementations, but struggled to give a truly horrible implementation? How bad does it need to be truly horrible?
I ask because I struggled coming up with a horrible implementation of FizzBuzz. My best attempt was to have Python create a sqlite table then use SQL to do the test. Such implementations occur all too frequently at http://thedailywtf.com/ http://thedailywtf.com/ .
But surely this would not be an example of great understanding of either Python or SQL. Therefore, I don't see how you can draw your conclusion.
Could you explain more fully?
- collyw 11y agoI got the impression the idea wasn't about writing the poorest code, but getting a chance to discuss what would make something better worse. I personally put readability and maintainability close to the top of my list.
- dalke 11y agoThe question was "Write the worst – but working – implementation of Fizz Buzz that you can think of." It is designed to 'bring up some good laughs, and takes some of the pressure off of the applicant' with the assumption that the candidate will respond "Write bad code? I can do that!". My question is, what if the interviewee is unable to produce bad code? Or even better, if the interviewee's worst code is better than the interviewer's best code. Does that inability to produce bad code on demand count as a negative?
- collyw 11y agoWell that's up to the interviewer. I would say it doesn't count as negative, but that's me. I am assuming the conversation around it is what is important. I recently got asked to do fizzbuzz in an interview. Then "fizzbuzz without the modulo operator". It's such an obvious way to approach the problem, that coming up with an alternative was surprisingly tricky. Caused a bit of a mental block for me.
- dalke 11y agoIf it's up to the interviewer then it isn't really a test of one's skills, is it? ("The worse the code is, the greater the understanding of the language in these cases") Instead, the interviewee needs to intuit what it is that the interviewer is looking for. Doesn't that restriction reduce to "how do you implement modulo?" def modulo(a, b): return a - a // b * b def modulo(a, b): while a > b: a -= b return a or pulling a hack from http://graphics.stanford.edu/~seander/bithacks.html#ModulusDivision http://graphics.stanford.edu/~seander/bithacks.html#ModulusD... , which is equivalent to casting-out-9s but in base 16: def mod15(a, b): while a > 15: b = 0 while a: b += a & 15 a >>= 4 a = b if a == 15: return 0 return a If it doesn't reduce to that, then it's another example of trying to guess what the interviewer is really asking, rather than trying to demonstrate one's expertise.
- collyw 11y agoAs I pointed out, I don't think the objective of the question is to test skills, but to start a discussion about what one values in "good code". It's an area that is partially subjective.
- dalke 11y agoYes, I understand your explanation. But you also said "The worse the code is, the greater the understanding of the language in these cases." My question is, what if the interviewee is unable to give an example of bad code? I don't see how failure to come up with bad code implies a worse understanding of the language. I can also easily see how people with poor understanding of the language can still produce horrible code. For example, at the end of this comment I write a simple assembly language interpreter in Python. That's a horrible solution to the problem. Explain to me how that shows I understand Python. Or for that matter, how it's a useful segue into a discussion of the factors that go into good code. If the point is to discuss what "good code" means, then why not a question which is better targeted towards that specific goal? For example, give four examples of FizzBuzz, ask the interviewee to discuss the pros and cons of each one, and ask for a preferred ranking. That's surely more like what happens in real life, doesn't have a failure mode where someone can't come up with really bad code, and actually leads to the discussion you want. import sys def execute(memory, code): lineno = 0 while 1: try: line = code[lineno] except IndexError: break if line[0] == "jeq": if memory[line[1]] == memory[line[2]]: lineno = line[3] continue elif line[0] == "inc": memory[line[1]] += 1 elif line[0] == "mod": memory[line[3]] = memory[line[1]] % line[2] elif line[0] == "print": sys.stdout.write(str(memory[line[1]])) elif line[0] == "load": memory[line[1]] = line[2] elif line[0] == "jmp": lineno = line[1] continue elif line[0] == "jz": if memory[line[1]] == 0: lineno = line[2] continue else: raise AssertionError(line[0]) lineno += 1 def fizzbuzz(n): memory = {"a": n+1, "b": 0, "c": 0, "d": "\n", "e": " "} code = ( ("inc", "b"), ("jeq", "a", "b", 1000), ("print", "b"), ("mod", "b", 15, "c"), ("jz", "c", 14), ("mod", "b", 5, "c"), ("jz", "c", 12), ("mod", "b", 3, "c"), ("jz", "c", 10), ("jmp", 17), ("load", "c", "Fizz"), ("jmp", 15), ("load", "c", "Buzz"), ("jmp", 15), ("load", "c", "FizzBuzz"), ("print", "e"), ("print", "c"), ("print", "d"), ("jmp", 0), ) execute(memory, code) fizzbuzz(100)