So I'm sort of looking for a job, not that my startup isn't fun and all, but cash flow is kind of a problem. So I was sent this programming test
( Read more... )
This is a classic interview-type exercise to see whether you're competent enough to write something absurdly simple but just nontrivial enough to trip up the stupid.
But it always drops me into morbid speculation about what is the best way because oh my God they're watching my every move. Treat the "Fizz", "Buzz" and "FizzBuzz" cases separately? That involves redundant checks! But putting them together means using some kind of flag to remember whether to print the integer! What if this guy is one of those people who says if you ever use a boolean flag you should refactor the code? WHAT THEN??
One of the Java examples on Rosetta Code uses string concatenation, and checks the string for non-null contents. But strings are immutable in Java, so... object churn???!
(Of course all of this worry is absurd premature optimization; with a code snippet like this you should probably write whatever looks simplest to you.)
Comments 4
Reply
But it always drops me into morbid speculation about what is the best way because oh my God they're watching my every move. Treat the "Fizz", "Buzz" and "FizzBuzz" cases separately? That involves redundant checks! But putting them together means using some kind of flag to remember whether to print the integer! What if this guy is one of those people who says if you ever use a boolean flag you should refactor the code? WHAT THEN??
Reply
Reply
(Of course all of this worry is absurd premature optimization; with a code snippet like this you should probably write whatever looks simplest to you.)
Reply
Leave a comment