62
\$\begingroup\$

It's not fair that 1% of the users hold 75% of the lolcode questions. #OccupyMatsMug
~ user2296177

I agree. Without further ado, here's the LOLCODE version of 99 bottles of beer on the wall:

OBTW
    PRINT TEH LOLCODE VERSHUN OV N BOTTLEZ OV BER ON TEH WALL.
TLDR

HAI 1.3

  HOW IZ I COUNTDOWN YR NUMAH
    I HAS A NAUW ITZ A NUMBR
    I HAS A LEZZ ITZ A NUMBR
    IM IN YR LOOPZ NERFIN YR COWNTR TIL BOTH SAEM COWNTR AN DIFF OF 1 AN NUMAH
      NAUW R SUM OF NUMAH AN COWNTR
      LEZZ R DIFF OF NAUW AN 1
      VISIBLE SMOOSH NAUW AN " LITTERS OV KITTEHS ON TEH NETZ" MKAY
      VISIBLE SMOOSH NAUW AN " LITTERS OV KITTEHS" MKAY
      VISIBLE "WAN FALLS DOWN AN BREAKZ PAH"
      VISIBLE SMOOSH LEZZ AN " LITTERS OV KITTEHS ON TEH NETZ" MKAY
      VISIBLE ""
    IM OUTTA YR LOOPZ

    VISIBLE "1 LITTER OV KITTEHS ON TEH NETZ"
    VISIBLE "1 LITTER OV KITTEHS"
    VISIBLE "WAN FALLS DOWN AN BREAKZ PAH"
    VISIBLE "NO MOAR LITTERs OV KITTEHS ON TEH NETZ"
  IF U SAY SO

  I IZ COUNTDOWN YR 99 MKAY

KTHXBYE

Disclaimer: No actual kittens were harmed while writing this program.

The number of iterations is held in the variable NUMAH. I know NUMBR is a more fitting name, but that's already claimed as a type.

The above is compiled using the latest lci using the 1.3 specification (thanks to Pimgd for the link). Since the 1.3 specification doesn't contain every feature of the language, see the 1.2 specification as well.

I don't think LOLCODE has templates or the likes, so getting all the output on screen is a bit tedious.

Output:

99 LITTERS OV KITTEHS ON TEH NETZ
99 LITTERS OV KITTEHS
WAN FALLS DOWN AN BREAKZ PAH
98 LITTERS OV KITTEHS ON TEH NETZ

etc.

1 LITTER OV KITTEHS ON TEH NETZ
1 LITTER OV KITTEHS
WAN FALLS DOWN AN BREAKZ PAH
NO MOAR LITTERs OV KITTEHS ON TEH NETZ

Is this idiomatic LOLCODE?

\$\endgroup\$
  • 8
    \$\begingroup\$ Before I clicked this when I saw it in the HNQ I was like "Aww, I'm sure some buzzkills are gonna change that title", but look, 31 votes and 25 on a great answer, holy cats! \$\endgroup\$ – cat Jul 13 '16 at 19:50
  • 6
    \$\begingroup\$ I thought this was PPCG at first, I was confused what was being asking for the longest time. Happy to see LOLCODE here! \$\endgroup\$ – Captain Man Jul 13 '16 at 21:03
  • 4
    \$\begingroup\$ @CaptainMan This is most definitely not PPCG, but we do know how to write great code :-) \$\endgroup\$ – Mast Jul 13 '16 at 21:07
  • 9
    \$\begingroup\$ "No actual kittens were harmed while writing this program." No, but I think my brain suffered some harm trying to read that. \$\endgroup\$ – Nathan Osman Jul 14 '16 at 6:14
  • 3
    \$\begingroup\$ "No actual kittens were harmed while writing this program." So this definitely isn't PPCG, where there is undefined behaviour killed my cat \$\endgroup\$ – trichoplax Jul 14 '16 at 20:42
46
\$\begingroup\$

Variable capitalization

IT IZ PRETTY GUD LOLCODE
HOWEVEZ ME THINKS THAT TEH LOLCODEZ R EZYR 2 READ IF TEH VARZ R lowercase
ZIS BECUZ ALL CAPS IS HARD TOO READ
(all spelling "mistakes" made by my cat, who assisted me in that part of this review)

More seriously, it is an issue that there are no good LOLCODE syntax highlighters. To be "stylish" and keep everything uppercase is a choice you can make, but personally I prefer to use lowercase or camelCase variable names whilst keeping the language constructs all caps. Similar to SQL, this allows you to see what parts of the code are variables, and what parts are language constructs.

Compare:

I HAS A NAUW ITZ A NUMBR
I HAS A LEZZ ITZ A NUMBR
IM IN YR LOOPZ NERFIN YR COWNTR TIL BOTH SAEM COWNTR AN DIFF OF 1 AN NUMAH
  NAUW R SUM OF NUMAH AN COWNTR
  LEZZ R DIFF OF NAUW AN 1
  VISIBLE SMOOSH NAUW AN " LITTERS OV KITTEHS ON TEH NETZ" MKAY
  VISIBLE SMOOSH NAUW AN " LITTERS OV KITTEHS" MKAY
  VISIBLE "WAN FALLS DOWN AN BREAKZ PAH"
  VISIBLE SMOOSH LEZZ AN " LITTERS OV KITTEHS ON TEH NETZ" MKAY
  VISIBLE ""
IM OUTTA YR LOOPZ

with...

I HAS A nauw ITZ A NUMBR
I HAS A lezz ITZ A NUMBR
IM IN YR LOOPZ NERFIN YR cowntr TIL BOTH SAEM cowntr AN DIFF OF 1 AN numah
  nauw R SUM OF numah AN cowntr 
  lezz R DIFF OF nauw AN 1
  VISIBLE SMOOSH nauw AN " LITTERS OV KITTEHS ON TEH NETZ" MKAY
  VISIBLE SMOOSH nauw AN " LITTERS OV KITTEHS" MKAY
  VISIBLE "WAN FALLS DOWN AN BREAKZ PAH"
  VISIBLE SMOOSH lezz AN " LITTERS OV KITTEHS ON TEH NETZ" MKAY
  VISIBLE ""
IM OUTTA YR LOOPZ

Variable naming

Regarding NUMAH, have you considered using NUMBAH? Similar meaning, but uses a more common mispronunciation.

Working around the spec

IM IN YR LOOPZ NERFIN YR COWNTR TIL BOTH SAEM COWNTR AN DIFF OF 1 AN NUMAH
  NAUW R SUM OF NUMAH AN COWNTR

This construct is non-obvious. You had to work around the spec to do something that you wanted to do, and I think it warrants explanation. Add a comment via BTW:

IM IN YR LOOPZ NERFIN YR COWNTR TIL BOTH SAEM COWNTR AN DIFF OF 1 AN NUMAH
  NAUW R SUM OF NUMAH AN COWNTR BTW workaround loop counters starting at 0

Correctness in corner cases

Your function doesn't check if the value passed in is greater than 0. This means that it falsely forces a KITTEH to break their paw when it wasn't necessary.

Add a guard clause at the top of the function; you can do an early return via GTFO.

DIFFRINT numbah AN BIGGR OF numbah AN 0
O RLY? YA RLY
    GTFO
OIC

Program definition

OBTW
    PRINT TEH LOLCODE VERSHUN OV N BOTTLEZ OV BER ON TEH WALL.
TLDR

HAI 1.3

Aside from the weird phrasing (does this code print the lolcode version of/and bottles of beer on the wall?), there's something else wrong here: Your comment is before the HAI 1.3. So any interpreter loading your file might not know what version you are using. Put your version number at the top.

Possible alternative dialects

VISIBLE "NO MOAR LITTERs OV KITTEHS ON TEH NETZ"

Did you make a typo here, is this an alternative kitty dialect that uses lower case 's' for certain plurals? I'm not sure.


Lastly, I think this version of 99 LITTERS OV KITTEHS ON TEH NETZ is not authentic, as anyone knows that when KITTEHS fall, they'll be alright. This version is sad, as all the KITTEHS just break their paws. Proper LOLCODE uses cats, it doesn't abuse them.

\$\endgroup\$
  • 2
    \$\begingroup\$ Definitely a typo there. Next time I'll try to write a more PG-themed poem. \$\endgroup\$ – Mast Jul 13 '16 at 15:46
  • 8
    \$\begingroup\$ This is how I saw PL/SQL when I started to learn it. Random CAPITAL WORDS and then some variables, all tidy up and stuff. \$\endgroup\$ – Mihai-Daniel Virna Jul 13 '16 at 16:12
  • 4
    \$\begingroup\$ U NAH NEED TEH MOAR SRS VERRSIN; LOLCODRZ GET IT ANYWAYZ! OMG SRS LOLCODE HEER! YAH "NUMAH" NAH A WORD HEER. \$\endgroup\$ – EKons Jul 13 '16 at 19:29
  • 2
    \$\begingroup\$ @QPaysTaxes either you do the validation, or you don't do the validation at all... I don't quite see why checking for >= 0 rather than != 0 makes for YAGNI?... \$\endgroup\$ – Pimgd Jul 13 '16 at 23:13
  • 1
    \$\begingroup\$ @QPaysTaxes the difference is DIFFRINT numbah AN BIGGR OF numbah AN 0 vs BOTH SAEM numbah AN 0 and this seems like a small difference to me. On the scale of "less than 30 seconds of work". I add such due diligence in my work where I can. \$\endgroup\$ – Pimgd Jul 13 '16 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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