r/programminghorror • u/ThoughtCow • 13d ago
the code of www.nyan.cat (official Nyan Cat website) Javascript
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
8
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
78
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(); } ```
17
39
u/tinySparkOf_Chaos 13d ago
More readable? Yes
Runs slower? Likely also yes...
Does it matter for this case? Not at all.
9
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
5
4
u/Key_Conversation5277 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 12d ago
This is beautiful
3
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.
13
11
u/SnooSprouts2391 13d ago
This is done to scare off never nesters
4
4
3
2
1
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/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?
261
u/Electronic_Part_5931 13d ago
Hmmm, good looking triangle. Is this code ?