5 ms·
That just leaves the code in a state where it's not clear what's wrong with it, because it works most of the time. There are just two types of code: obviously c
by iopq 3y ago
That just leaves the code in a state where it's not clear what's wrong with it, because it works most of the time. There are just two types of code: obviously correct, or not obviously wrong.
If you write some code and you don't know how it works, it's most likely not correct in some edge cases.
Code that is written to be so simple it's obviously doing the right thing is better than battle tested mess of if statements.
I've given interviews of fizzbuzz and even though developers usually recognize they need a separate case for 15, they don't always do the else ifs right (maybe test for the 15 case last when you've already hit the divisible by 3 case first, or similar silly mistakes). In that case, doing the string accumulation refactor makes it clear that the code has no mistakes because it for sure adds a Fizz first and a Buzz second in the 15 case. It's also a good refactor for extending to Bazz (divisible by 7) as well, so it's something you will want to do when you want to add that feature
- MichaelZuo 3y agoIf that's the typical performance on fizzbuzz, I can't even imagine what the performance would be like on more advanced questions.
- iopq 3y agoHumans are very bad on whiteboard interviews. I like giving people a laptop better now
- MichaelZuo 3y agoThe point is to make folks answer without the help of external tools, such as an IDE, on the basis that they will be able to reliable accomplish more advanced tasks with such tools in practice. Whether or not this theory is mostly reliable or barely, or not at all, depends on the viewpoint. If a more advanced question is posed, then the assumption is that the requirement is for the prospective employee to accomplish even more advanced tasks in practice.
- iopq 3y agoWould you rather get someone who can do fizzbuzz correctly on a board the first time in 7 minutes or someone who can write it in 1 minute on a laptop incorrectly, test it, and fix it in 30 seconds? I see no value in the "gotcha" of you made a logic mistake since we all make them and there's a reason why we test code
- MichaelZuo 3y agoIf they make 1 'logic mistake' on fizzbuzz then it's likely they'll make 10x, or more, 'logic mistakes' on their actual work. Even with a laptop and all the tooling that makes them 10x better, because the real work will be at least 100x more complex.
- iopq 3y agoI made a mistake in fizzbuzz the first time I did it on a whiteboard because I wrote it in "pseudocode" I wrote if (n % 15) print "fizzbuzz" ... I got away with it because my interviewer assumed it was some kind of shell which means 0 is true I should have written n % 15 == 0 to be absolutely clear what I'm doing note that in Rust this won't even compile: 3 | if n % 15 { | ^^^^^^ expected `bool`, found integer But I don't have the type checker to find mistakes for me when writing on a whiteboard which is not realistic. I can't commit this code because CI wouldn't merge a build failure anyway
- MichaelZuo 3y agoHuh? Did you accidentally share private notes?
- iopq 3y agoNo, I'm saying I've made a logic mistake in Fizzbuzz in an interview because I forgot to put == 0 in the condition. If you think that makes me a bad programmer, that's your problem, I just don't think whiteboard interviews are representative of the pull requests I do after working for several hours on something
- tuna74 3y ago"If you write some code and you don't know how it works, it's most likely not correct in some edge cases. Code that is written to be so simple it's obviously doing the right thing is better than battle tested mess of if statements." Only if it actually do the right thing in ALL cases. In a lot of refactors I have seen (and done myself) that has not been true.
- iopq 3y agoYes, but then the refactor value is dubious. To write simple code you actually need to understand the difficulty of the problem. Why is certain code easier to talk about than other type of code? Why is it better written this way and not another way? If you don't understand the problem enough you may hack at it in another wrong way.