- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Buzzed coding IS fizzy!
Admin
Learning to code in production. New WTF level unlocked.
Admin
It only counts if the language of choice is Rockstar.
Admin
I love the comment, too...
Above:
we have a comment that says that this is class
VehicleConfigurationModel
. I would never have known otherwise.../sarcasm
Admin
I think you mean:
Conducting job interviews in production. New WTF level unlocked.
Admin
At least it's not the jizz-bizz artifact I've seen a few times in my life.
(Sorry)
Admin
I hope the lesson learned by the person who wrote it was that they were more suited to other jobs besides programming. I really hope this was the case.
Admin
Not realizing that you need to use
else if
is a common beginner mistake, I've seen it dozens of time on Stack Overflow.Admin
It's not just missing an else though. They obviously wanted it to print FizzBuzz on numbers divisible by 15, which is why they didn't use the else there. The issue is the wrong test for whether to print the number or not.
Admin
Tried my hardest, but couldn't jam the logic into a switch statement without repeating comparisons...
Admin
Prints buzz:
FizzBuzz 1 2 Fizz3 4 Buzz Fizz6 7 8 Fizz9 Buzz 11 Fizz12 13 14 FizzBuzz 16 17 Fizz18 19 Buzz
The misaligned braces does indeed make it hard to read
Admin
Eliminate the hefty part of the comparison by using valiables. Then (here is the trick) implement the logic in the reverse order of the specification.
-- this is kind of pseudo code, don't mock me. var isFizz = counter % 3 == 0; var isBuzz = counter % 5 == 0;
if( isFizz && isBuzz ) print ("FizzBuzz"); else ( isFizz ) print ("Fizz"); else ( isBuzz ) print ("isBuzz "); else print(counter );
Admin
My guess would be that the class was provided via email to a senior developer who was doing hiring stuff on the side, who copy-pasted it into a handy IDE window to check if it compiled and ran. And then forgotten about it and accidentally bundled it with one of their commits, and because it was a senior developer, the code reviewer wasn't paying particularly close attention and merged it without noticing.
I'm speculating, of course, but it certainly wouldn't be the first time I've seen something similar happen.
Admin
My comment was a reflection of the previous day's switch + if statement wtf mangling! I was hoping I could mangle something similarly ala a lovely wtf style for FizzBuzz, but alas, it didn't match the pattern.
btw the logic can be reduced to something clearer by going backwards, which minimizes print statements and tends to match how people think about it when playing the game in person:
Admin
Lost a couple lines (if this doesn't work, I give up!)...
Admin
The FizzBuzz problem is a classic test given in coding interviews. Maybe the developer was practicing for one.
Admin
Trying to jam it into a switch statement as somebody suggested/attempted is like trying to use a hammer to drive in a screw. Still, what the heck:
switch(n%5==0?n%3==0?3:1:n%3==0?2:0) { case 3: print "Fizz"; case 2: print "Buzz"; break; case 1: print "Fizz"; break; case 0: print n; break; }
I particularly like the absence of parentheses in the switched expression and the fall-through of the first case; that might just relieve the boredom of the interviewer somewhat.
PS: the editor doesn't allow me to apply formatting, so it'll probably look even worse than it actually is. If so, all the better, to hammer down the point that using a switch doesn't make sense.
Admin
var ans=""; if (counter % 3 == 0 ) ans = "Fizz"; if (counter % 5 == 0 ) ans .= "Buzz"; if (ans == "") print counter else print ans;