2 ms·
As 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 th
by collyw 11y ago
As 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)
- deleted 11y ago[deleted]