4 ms·
I think that generally "how to write bad code" is a great interview topic as you probably get a positive fun response from those are know and get a nice insight
by aw3c2 11y ago
I think that generally "how to write bad code" is a great interview topic as you probably get a positive fun response from those are know and get a nice insight what things they might be caring about.
- dalke 11y agoJust how useful is it as a test? Suppose the "good" code is: for (1..100) { my $fizz = ($_ % 3 == 0) ? "Fizz" : ""; my $buzz = ($_ % 5 == 0) ? "Buzz" : ""; ($fizz ne "" || $buzz ne "") ? print "$fizz$buzz\n" : print "$_\n"; } and the "bad" code is the one-liner: print ( ((($_ % 3) ? "" : "Fizz") . (($_ % 5) ? "" : "Buzz")) || $_, "\n") for (1..100); or is the following: #!/usr/bin/perl @v=(0, "Fizz", "Buzz", "FizzBuzz"); for($v[0]=1;$v[0]<=100;$v[0]++){ $k = ($v[0]%3)?0:1; $k += ($v[0]%5)?0:2; print($v[$k]."\n"); } (All three from http://c2.com/cgi/wiki?FizzBuzzTest http://c2.com/cgi/wiki?FizzBuzzTest .) What does that reveal about the interviewee that makes this a great interview topic? To my eye, I prefer #1, #3, and #2, but it starts to get into personal preference rather than anything seriously indicative. Do you want to dock someone for not being able to give a seriously bad implementation?
- collyw 11y agoThe worse the code is, the greater the understanding of the language in these cases.
- dalke 11y agoSo 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.
- aw3c2 11y agoI meant talking critically about code during the interview, discussing things that can make code bad or good.