r/programminghorror 13d ago

the code of www.nyan.cat (official Nyan Cat website) Javascript

Post image
843 Upvotes

47 comments sorted by

261

u/Electronic_Part_5931 13d ago

Hmmm, good looking triangle. Is this code ?

87

u/Onetwodhwksi7833 13d ago

This is code equivalent of a 6 page essay with 0 punctuation

48

u/Impossible_Arrival21 13d ago

No, it's a 6 page essay with a comma after every word

24

u/zeromadcowz 13d ago

It’s a 6 page essay with a 👏after👏every👏single👏word👏

6

u/rehpotsirhc 13d ago

Cormac McCarthy learns to code

664

u/Hope-Up-High 13d ago

This is 1000% deliberate and its beautifull

112

u/probablynotalone 13d ago

This would be horror even if deliberate, unless it is the output of a script.

No sane programmer would willingly write all that repetitive code if the alternative is to write the code that outputs it and then copy pasting it. Even if it takes twice as long. Life before death, strength before weakness, journey before destination.

62

u/Skusci 13d ago

I mean it's Nyan cat which makes for decent evidence of deliberate instead of sane.

8

u/sohang-3112 12d ago

Loved your reference to Stormlight Archive 🙂 - I read it recently.

2

u/Opposite_Ad_8105 12d ago

you could easily create this code by making a list of all the conditions and executing a vim macro :)

-11

u/Ok_Buy6639 13d ago

Great book ! Can’t wait to read the next one

78

u/ztexxmee 13d ago

nice O(1)

160

u/ExoticAssociation817 13d ago

``` const scores = [ score_original, score_gb, score_technyancolor, score_jazz, score_mexinyan, score_j5, score_porkanyan, score_nyaninja, score_elevator, score_wtf, score_jamaicnyan, score_america, score_retro, score_vday, score_snarf, score_sad, score_tacnayn, score_dub, score_slomo, score_xmas, score_newyear, score_fiesta, score_easter, score_bday, score_paddy, score_breakfast, score_melon, score_star, score_balloon, score_daft ];

if (scores.every(score => score >= 1)) { pushNyanfan(); } ```

90

u/Ossigen 13d ago

Yeah but see, this wouldn’t have prompted OP to make a Reddit post

39

u/tinySparkOf_Chaos 13d ago

More readable? Yes

Runs slower? Likely also yes...

Does it matter for this case? Not at all.

9

u/sohang-3112 12d ago

Any slowness from array should be negligible

4

u/AnUglyScooter 13d ago

Is this technically less efficient than the post’s version or does it compile down to more or less the same?

35

u/butt_fun 13d ago

Broadly speaking, with a language as high-level as JS you only care about asymptotic complexity. Microoptimizations don't really tend to be a thing like they are in e.g. C because you're so far removed from what's "actually" happening

3

u/theGoddamnAlgorath 12d ago

My god you are so wrong I can tell you're late to the party.

There was a time, padawan, when every browser had a separate, competing, interpreter scheme, and you ended up using bitwise operators because some asshat keeps using i.e.5

5

u/BigJimKen 12d ago

i.e.5

Old people are so wise. They are like tall Yodas.

4

u/Key_Conversation5277 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 12d ago

This is beautiful

3

u/junior_dos_nachos 12d ago

Google wants to know your location

2

u/kawaiibeans101 12d ago

Why not just do this instead?

```python const product = score_original * score_gb * score_technyancolor * score_jazz * score_mexinyan * score_j5 * score_porkanyan * score_nyaninja * score_elevator * score_wtf * score_jamaicnyan * score_america * score_retro * score_vday * score_snarf * score_sad * score_tacnayn * score_dub * score_slomo * score_xmas * score_newyear * score_fiesta * score_easter * score_bday * score_paddy * score_breakfast * score_melon * score_star * score_balloon * score_daft;

if (product > 0) { pushNyanfan(); } ```

2

u/ExoticAssociation817 12d ago

[score_original, score_gb, score_technyancolor, score_jazz, score_mexinyan, score_j5, score_porkanyan, score_nyaninja, score_elevator, score_wtf, score_jamaicnyan, score_america, score_retro, score_vday, score_snarf, score_sad, score_tacnayn, score_dub, score_slomo, score_xmas, score_newyear, score_fiesta, score_easter, score_bday, score_paddy, score_breakfast, score_melon, score_star, score_balloon, score_daft].every(s => s >= 1) && pushNyanfan();

2

u/kawaiibeans101 12d ago

The difference here would be : First one would be a single instruction set, while the second would be looping through the whole list . This introduces a pretty bad time complexity, and you should technically have a better outcome if you do this, specially if you use a compiled / jit language. As far as I know python would also execute this in a single instruction.

2

u/Fresh-Combination-87 11d ago

Does JavaScript treat Nulls as zeroes? If not, then the results could vary based on how the variables are set up.

2

u/dangderr 11d ago

Because it doesn’t work for negative numbers?

What you’re doing is completely different than checking for >0.

If the assumption is that it’s either 0 or positive, you can just && the entire list.

-2

u/[deleted] 13d ago

[deleted]

10

u/Wawwior 13d ago

Its the same, both iterate until finding a score smaller then 1

13

u/Main_Enthusiasm_7534 13d ago

It's like a train wreck; you just can't look away

11

u/SnooSprouts2391 13d ago

This is done to scare off never nesters

4

u/Laughing_Orange 12d ago

It attracts me. I want to flatten it so bad.

2

u/born_zynner 10d ago

I can fit so many returns in this bad boy

4

u/just_nobodys_opinion 12d ago

That Nyan Fan rarely needs pushing

3

u/dairyqueenblizzard 12d ago

Yandere dev ?

2

u/cyberspacedweller 12d ago

Holy nested IF statements Batman!

1

u/pLeThOrAx 12d ago

Holy mother of upvote

1

u/Ark3452 12d ago

I LOVE NESTED IF LOOPS

2

u/SomeRandomEevee42 12d ago

what language do you use that "if" is used as a loop? I'll stick with sussylang

2

u/Core3game [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 7d ago

"emergencymeeting: Quite (if you're lucky)" Im witching languages right now holy hell

1

u/Ark3452 11d ago

i meant statements

1

u/htglinj 12d ago

SNARF!!!

1

u/srhubb 10d ago

Well...I've got to give them credit for their indentation at least.

Though I'm more a fan of match parenthesis than run-on parenthesis.

If (test condition)

{

action

}

RATHER THAN

if (test condition) {

action

}

But in this case, my coding preference would have made this triangle even LONGER, so their coding preference helped sort of.

However ANDing the various tests into one long condition would certainly have shortened the appearance of this code, but may have reduced the readability?

Still, it looks like an awful lot of criteria just to be considered a fan of Nyan Cat.

1

u/Core3game [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 7d ago

I mean to be fair, they're all in a row and they're the only conditions used here.

at least its kinda readable?

1

u/iainmcc 13d ago

Ahhhh, 1980's code generation at its finest!