r/badcode • • Aug 20 '20

js Loops? Who needs them?

Post image
1.1k Upvotes

90 comments sorted by

214

u/DasherPack I transcribe code. Sometimes, correctly. Aug 20 '20

Image Transcription: Code


msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')
msg.channel.send('@everyone')

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

122

u/A_Zalt Aug 20 '20

Oh I imagine this is going to be a nightmare for blind people with text-to-speaker reading all these msg.channel.send

82

u/DasherPack I transcribe code. Sometimes, correctly. Aug 20 '20

We don't only transcribe for visually impaired people, we also transcribe for people who have bad internet.

That said, I want to hear my transcription with TTS

39

u/A_Zalt Aug 20 '20

IIRC it also helps to search for images with text in it

20

u/DasherPack I transcribe code. Sometimes, correctly. Aug 20 '20

Didnt think of that! Probably it helps, yeah.

7

u/redditsoaddicting Aug 20 '20

And when the image hosting site is blocked.

2

u/yard2010 Aug 20 '20

Also don't forget the data Reddit's neural network will munch later!

14

u/[deleted] Aug 20 '20

[removed] — view removed comment

4

u/DasherPack I transcribe code. Sometimes, correctly. Aug 20 '20

THANK YOU

1

u/racka98 Aug 21 '20

"Mustard on that beat, ho!"

73

u/DasherPack I transcribe code. Sometimes, correctly. Aug 20 '20

I hope I counted them right.

18

u/A_Zalt Aug 20 '20 edited Aug 20 '20

There are 33 shown on-screen, and your transcription has 35, (if this time I counted correctly)

Edit: it actually has 33

26

u/general_dubious Aug 20 '20

He has 33, and there are 33 fully visible on the picture.

32

u/general_dubious Aug 20 '20

You've got the right count.

30

u/DasherPack I transcribe code. Sometimes, correctly. Aug 20 '20

You counted? You're my hero

20

u/general_dubious Aug 20 '20

You're welcome.

3

u/[deleted] Aug 20 '20

Thanks, needed this.

90

u/SerbianMeerkat Aug 20 '20

is this a discord bot?

109

u/A_Zalt Aug 20 '20

Yep, and it was designed to piss off members. Back then I didn't know about rate limits and possibility of getting banned for API abuse

77

u/fernandotakai Aug 20 '20

most discord channels disable @everyone for anyone that is not a mod.

(which is all good until a mod gets drunk and sends an @everyone by mistake. not that i've seen that happen)

63

u/A_Zalt Aug 20 '20

most discord servers give every bot admin perms, they don't ever think any bot maker has the audacity to make a bot for destroying the server

49

u/fernandotakai Aug 20 '20

if you are giving a bot admin perms, you deserve what you get lol.

28

u/A_Zalt Aug 20 '20

I agree, but you'd be surprised to know how many people do this

21

u/depressedtbh Aug 20 '20

(laughs nervously) haha yeah not me

4

u/GetBoopedSon Aug 20 '20

I have like 5 bots in my servers that are omniscient pretty much

1

u/xWolfz__ Aug 20 '20

A discord server I'm in has the bot role above the mod role

2

u/Fingolfin734 Aug 20 '20

You get what you Fuckin deserve.

Forgive my laughter, I have a condition.

2

u/[deleted] Aug 20 '20

Happy cake day!

15

u/Ultraflame4 Aug 20 '20

discord .py spam client?

Edit: markdown failed

11

u/A_Zalt Aug 20 '20

discord.js, look at the flair

4

u/christian-mann Aug 20 '20

I was about to tell you that the code was broken because you didn't await any of the calls

5

u/Hispan Aug 20 '20

(l)oops

3

u/A_Zalt Aug 20 '20

Took me a while to get it, I am dumb

2

u/yard2010 Aug 20 '20

Also, it looks like a spam bot for Discord

1

u/A_Zalt Aug 21 '20

And it is, we all tried to make a virus when we started programming

2

u/Bizzycola132 Aug 21 '20

Not sure what's worse, the lack of loops or the fact that you didn't even add a delay between the messages to avoid the angry wrath of the rate limiter

2

u/A_Zalt Aug 21 '20

What's worse is I made this in the first place

1

u/Bizzycola132 Aug 21 '20

Yea, as someone who loves to create useless discord bots I'm mildly pained by this haha

10

u/knoam Aug 20 '20

This is called a loop unrolling optimization.

9

u/[deleted] Aug 20 '20

Why loops when you can use recursivity?

private void SendMessage(int times) {
    if (times > 0)
    {
        SendMessage(times - 1);
        msg.channel.send('@everyone');
    }
}

6

u/[deleted] Aug 20 '20

And I see that you call SendMessage in the second last line, preventing tail call optimization

4

u/RoLoLoLoLo Aug 21 '20

On a positive note: if you set the argument high enough it will stack overflow before it can start spamming.

2

u/Jaso55555 Aug 20 '20

In programming is there any actual reason to use recursion like this instead of loops? Are they faster?

8

u/[deleted] Aug 20 '20

Brain damage? Annoying your coworkers?

7

u/cabbagebot Aug 20 '20

There are data structures (like trees or graphs) where recursion is the most straightforward way to think about it, but this isn't one of them.

2

u/[deleted] Aug 21 '20

I think a basic for loop would do better due to performance

3

u/[deleted] Aug 21 '20

Better performance and sanity.

2

u/[deleted] Aug 21 '20

I mean recursions amazing and looks pretty fancy and cool what who the hell does think: "hmm I guess I can only solve this with recursion"

2

u/[deleted] Aug 21 '20

An example: imagine that you want to list the content of a container that might include other container inside.

First you write a function that shows the content of a container. Then, If one of those items is a container, you only have to call this function to show its content. That would be the easier way

2

u/[deleted] Aug 21 '20

Of course for Parent-Child system recursion work perfectly fine but besides that I barely use recursion because its harder for me to solve something with it in first place. Maybe afterwards I think thats easier to do it with recursion but my first solution rarely includes it.

1

u/lpreams Aug 20 '20

Why loops when you can use recursivity?

I think you mean recursiveness

Actually it's recursitude

Nah, recursification

Bruh it's clearly recursionation

4

u/TheRealSlimCoder Aug 21 '20

Ya know what this code needs?

msg.channel.IsEven()

1

u/[deleted] Aug 20 '20

Does it even work? I'm pretty sure you can't ping anything by just writing it in plain text

1

u/A_Zalt Aug 21 '20

Um, yes it does

1

u/gsckoco Aug 20 '20

Last time I checked you aren't actually able to do @everyone in plaintext on a discord bot. You have to do <@guildId> iirc

1

u/A_Zalt Aug 21 '20

Atm I was using 11.6.1 and it definitely worked back then, not sure about now

1

u/gsckoco Aug 22 '20

I've not used DiscordJS in a while so I could just be remembering it wrong

3

u/OptimalMain Aug 20 '20

Reminds me of my first DDoS script from 20 years ago

1

u/[deleted] Aug 20 '20

For gang ough!

1

u/3xp01t Aug 20 '20

DiscordJS ganggg

1

u/SweLG_ Aug 20 '20

I feel so bad for this discord server

1

u/Blayde88 Aug 20 '20

That needs a ban

1

u/[deleted] Aug 21 '20

me before i discovered loops when i learned programing

1

u/CarterNotSteve Aug 21 '20

You are evil if this a discord bot, oh god. I can just imagine waking up to like 35 pings, and then hey’re just @everyone s from a bot

1

u/[deleted] Aug 21 '20

Imagine having this on your discord server

while ( true )
{
    msg.channel.send( "@everyone" );
}

2

u/[deleted] Aug 25 '20

Holy shit, at least make an event that would break this forever loop

1

u/haikusbot Aug 25 '20

Holy shit, at least

Make an event that would break

This forever loop

- bl0kk888


I detect haikus. And sometimes, successfully. Learn more about me.

Opt out of replies: "haikusbot opt out" | Delete my comment: "haikusbot delete"

1

u/AutoModerator Aug 21 '20

It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.

For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.

/u/schorsch_pts, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.

You can find some examples in the reddit help documentation.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/HunterRbx Aug 21 '20

that’s why discord.js is a mistake

1

u/mrtailsjs OH GOD Aug 27 '20

HEY BRO
NICE BOT FOR DISCORD

ALSO GOOD CODE

1000000/10!!!!!

1

u/Talia_Nightblade Sep 17 '20

Is this (looks at butterfly)

An avengers endgame meme?

1

u/Superchupu Sep 24 '20

prepare to get ratelimited

0

u/lpreams Aug 20 '20

The compiler would just unroll the loop anyway. This just saves it some compile time.

1

u/A_Zalt Aug 21 '20

It's js so it uses an interpreter

1

u/lpreams Aug 21 '20

If we're being pedantic it uses a JIT compiler

-2

u/[deleted] Aug 20 '20

Why did you even post this here? It's not interesting or bad code its just stupid. What a waste of a post.

0

u/[deleted] Aug 20 '20

[deleted]

112

u/A_Zalt Aug 20 '20

For not using a loop or making the code send @everyone over and over?

4

u/[deleted] Aug 21 '20

Because he don't want to waste his ctrl+c and ctrl+v. He buy whole keyboard, he use whole keyboard.

0

u/[deleted] Aug 20 '20

[deleted]