# Down with FizzBuzz… LOL

This post is the result of reading through and following the LOLCODE Specification 1.2 ("smoking the manual", right?), and writing and executing my code on compileonline.com.

My "hello world" was going to be a . I like it because it nicely illustrates the basics of a language - variables, operators, looping, conditionals, and the likes.

As far as naming goes, the specification allows for a wide variety, so I decided to go PascalCase all the way, so as to ease up the reading a bit - otherwise the language is a bit harsh on the eyes, to say the least.

I'm curious about how idiomatic my code is - this is my very first and probably last program. Did I overlook language constructs that would help readability? How's naming? Indentation? Any issues?

HAI 1.2

I HAS A Fizz ITZ 3
I HAS A Buzz ITZ 5

IM IN YR FrootLoopz UPPIN YR Frootz TIL BOTH SAEM Frootz AN 100
BTW Frootz runs 0 through 99

I HAS A Froot ITZ SUM OF Frootz AN 1
BTW Froot will run 1 through 100

BOTH SAEM 0 AN MOD OF Froot AN PRODUKT OF Fizz AN Buzz
O RLY?
YA RLY
Froot R "FizzBuzz"
NO WAI
BOTH SAEM 0 AN MOD OF Froot AN Fizz
O RLY?
YA RLY
Froot R "Fizz"
NO WAI
BOTH SAEM 0 AN MOD OF Froot AN Buzz
O RLY?
YA RLY
Froot R "Buzz"
OIC
OIC
OIC

VISIBLE Froot

IM OUTTA YR FrootLoopz

VISIBLE "DOWN WITH FIZZBUZZ LOL"

KTHXBYE

-
I was expecting CHEEZE and BURGER, not FizzBuzz. –  h.j.k. Aug 29 '14 at 6:01
@h.j.k. Or, in line with the title, LOL and CATZ –  WernerCD Aug 29 '14 at 13:17
WHAT U MEAN WIF HARSH 2 EYEZ?? IZ PERFECTLY READABLE!! –  Philipp Aug 30 '14 at 12:26
@fluffy I'm starting to wonder too, and we have a meta question about the matter. –  Simon André Forsberg Aug 30 '14 at 20:05

I like how you have declared the Fizz and Buzz 'constants'. It makes the code more readable.

The comments are useful too, though, for consistency, the second comment should be changed from:

BTW Froot will run 1 through 100


to

BTW Froot runs 1 through 100


The idea of generating Froot from Frootz is also good, because it reduces the computations later in the code.

I only wish you used a better name than Frootz because it conflicts with Froot. The similarity is.... uncanny.

I would suggest the name Loopz:

I HAS A Loopz ITZ SUM OF Frootz AN 1


This will reduce the ambiguity, and improve the readability and maintainability.

Finally, it is good that you put the Fizz modulo check before the Buzz check because that improves performance. Many people put buzz first, but that means the modulo-5 check happens, and that fails more often than the modulo-3 check, so people who do the Buzz-loop first tend to do about 20% more conditional checks.

All in all, for a first go, I am very impressed with your result. I can't wait until you implement a interpreter in . Till then!

-
It is oddly appropriate for you to answer this question given your name. –  MichaelT Aug 29 '14 at 23:02
Tough decision here, I'm giving you the checkmark on this one.. but I'm surprised nobody mentioned that I'm doing 3*5 at every iteration, could have used a I HAS A FizzBuzz ITZ PRODUKT OF Fizz AN Buzz outside the loop. –  Mat's Mug Aug 30 '14 at 13:15

I really can't believe I'm reviewing right now...

• The specification does allow for variables to be any case, but all existing documentation uses lower case for variables. So, lowercase variables would be more idiomatic, but I'd go with camelCase for readability.
• Frootloopz is creative and idiomatic, but Froot is meaningless beyond it's relation to Frootloopz. Loopz would still be idiomatic and counter would be more meaningful.
• As @Pimgd noted, you can reduce the nesting by putting O RLY?, YA RLY on a single line.
• The code both calculates and prints. LOLCODE supports functions. I would use it to separate the concerns. Particularly since this is an exercise in learning the language.

A function is demarked with the opening keyword HOW IZ I and the closing keyword IF U SAY SO. The syntax is as follows:

HOW IZ I <function name> [YR <argument1> [AN YR <argument2> …]]
<code block>
IF U SAY SO

-

## Indentation

You've gone with a structure like this:

O RLY?
YA RLY
Froot R "Buzz"
OIC


I don't really like it. It has an extra indentation level. Instead, I'd opt to do this:

O RLY?, YA RLY
Froot R "Buzz"
OIC


You do get multiple statements on one line, but I'd see the IZ WIN (== true for those who are LOLCODE-inexperienced) as a part of the if statement.

  I HAS A Froot ITZ SUM OF Frootz AN 1
BTW Froot will run 1 through 100


Why is this comment indented? I think it should be like so

  I HAS A Froot ITZ SUM OF Frootz AN 1
BTW Froot will run 1 through 100


Because there's no indentation level by variable assignment.

## Magic numbers

100 should be a constant with a name that describes its meaning. Something like FIZZBUZZLIMIT or MAXFIZZBUZZNUMBR. Or even STAHP... but that might be less descriptive than the other names.

-
What else would you call the number 100? HUN? –  RubberDuck Aug 29 '14 at 14:31
@RubberDuck Limit, MaxLines, Amount... It's not about the value, it's about the context. That 100 could be 1000 or 250 or 1337. When do you want FizzBuzz to stop? –  Pimgd Aug 29 '14 at 14:53
Just making sure you weren't suggesting this. codereview.stackexchange.com/q/44047/41243 –  RubberDuck Aug 29 '14 at 14:55
I would humbly suggest the variable name STAHP –  mikeTheLiar Aug 29 '14 at 18:31
No. @Pimgd, STAHP..... –  RubberDuck Aug 29 '14 at 21:23