129
\$\begingroup\$

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
\$\endgroup\$
3
  • 53
    \$\begingroup\$ I was expecting CHEEZE and BURGER, not FizzBuzz. \$\endgroup\$
    – h.j.k.
    Aug 29, 2014 at 6:01
  • 40
    \$\begingroup\$ A serious code review about code written in a joke language? And asking about the idiomaticity of said code? Sometimes I wonder about this place. \$\endgroup\$
    – fluffy
    Aug 30, 2014 at 3:17
  • 4
    \$\begingroup\$ @fluffy I'm starting to wonder too, and we have a meta question about the matter. \$\endgroup\$ Aug 30, 2014 at 20:05

3 Answers 3

72
\$\begingroup\$

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!

\$\endgroup\$
5
  • 21
    \$\begingroup\$ It is oddly appropriate for you to answer this question given your name. \$\endgroup\$
    – user22048
    Aug 29, 2014 at 23:02
  • 4
    \$\begingroup\$ 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. \$\endgroup\$ Aug 30, 2014 at 13:15
  • \$\begingroup\$ I had to check and make sure that fim++ still didn't exist. Whew. Safe for another year. \$\endgroup\$
    – RubberDuck
    Dec 15, 2016 at 10:43
  • \$\begingroup\$ @RubberDuck What is fim++? \$\endgroup\$ Apr 27, 2017 at 21:17
  • \$\begingroup\$ @user00001 Dear Princess Celestia... esolangs.org/wiki/FiM%2B%2B \$\endgroup\$
    – RubberDuck
    Apr 27, 2017 at 21:45
52
\$\begingroup\$

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 its 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
\$\endgroup\$
33
\$\begingroup\$

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.

Indentation - Comments

  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.

\$\endgroup\$
4
  • 6
    \$\begingroup\$ What else would you call the number 100? HUN? \$\endgroup\$
    – RubberDuck
    Aug 29, 2014 at 14:31
  • 4
    \$\begingroup\$ @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? \$\endgroup\$
    – Pimgd
    Aug 29, 2014 at 14:53
  • 4
    \$\begingroup\$ Just making sure you weren't suggesting this. codereview.stackexchange.com/q/44047/41243 \$\endgroup\$
    – RubberDuck
    Aug 29, 2014 at 14:55
  • 22
    \$\begingroup\$ I would humbly suggest the variable name STAHP \$\endgroup\$
    – Mike G
    Aug 29, 2014 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.