• Bogolese (unregistered)

    Buzzed coding IS fizzy!

  • Hanzito (unregistered)

    Learning to code in production. New WTF level unlocked.

  • Industrial Automation Engineer (unregistered)

    It only counts if the language of choice is Rockstar.

  • (nodebb)

    I love the comment, too...

    Above:

    public class VehicleConfigurationModel {
    

    we have a comment that says that this is class VehicleConfigurationModel. I would never have known otherwise...

    /sarcasm

  • TS (unregistered) in reply to Hanzito

    I think you mean:

    Conducting job interviews in production. New WTF level unlocked.

  • (nodebb)

    At least it's not the jizz-bizz artifact I've seen a few times in my life.

    (Sorry)

  • Chris (unregistered)

    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.

  • Barry Margolin (github)

    Not realizing that you need to use else ifis a common beginner mistake, I've seen it dozens of time on Stack Overflow.

  • Michael (unregistered) in reply to Barry Margolin

    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.

  • Yikes (unregistered)

    Tried my hardest, but couldn't jam the logic into a switch statement without repeating comparisons...

  • Andreas (unregistered)

    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

  • NotAThingThatHappens (unregistered) in reply to Yikes

    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 );

  • SG (unregistered)

    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.

  • Yikes (unregistered) in reply to NotAThingThatHappens

    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:

    else {
      if (isFizz) print "Fizz";
      if (isBuzz) print "Buzz";
    }```
    
  • Yikes (unregistered) in reply to Yikes

    Lost a couple lines (if this doesn't work, I give up!)...

    if not (isFizz or isBuzz) {
      print (counter);
    }
    else {
      if (isFizz) print "Fizz";
      if (isBuzz) print "Buzz";
    }
    
  • Ankit sikder (unregistered)
    Comment held for moderation.
  • (nodebb)

    The FizzBuzz problem is a classic test given in coding interviews. Maybe the developer was practicing for one.

  • Chatogaster (unregistered)

    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.

  • airdrummer (unregistered)

    var ans=""; if (counter % 3 == 0 ) ans = "Fizz"; if (counter % 5 == 0 ) ans .= "Buzz"; if (ans == "") print counter else print ans;

Leave a comment on “Fizzy”

Log In or post as a guest

Replying to comment #:

« Return to Article