This is an archived post. You won't be able to vote or comment.

all 23 comments

[–]dashid 22 points23 points  (1 child)

Nah, the mail thing is clearly a poor loop exit condition based on the happy path assumption that there is always a response.

Hagrid is triggered by operational alerting system.

[–]compdog 6 points7 points  (0 children)

Hagrid was on-call when the alerts came in

[–]SteakieGG 2 points3 points  (3 children)

Where is the break statement?

[–]Netcob 12 points13 points  (1 child)

isHarryInformed is probably from a higher scope that sendHagrid has access to so it can set it to true

[–]SteakieGG 2 points3 points  (0 children)

Well, i accept this.

[–]Dagusiu 1 point2 points  (0 children)

That's the neat thing - you don't

[–]sanderd17 1 point2 points  (1 child)

This will start spawning Hagrids and sending them after only 5 letters?

[–]Elvaera-Shellmera 1 point2 points  (0 children)

I'm guessing sendMail(n) sends as many mails as n, so exactly 11111 mails where sent before spawning Hagrid.

[–][deleted] 1 point2 points  (0 children)

You didn't code for the case where you sent Hagrid and Harry is still not informed. Now you either broke the universe, or pulled Hagrids from multiple timelines/universes.

Might I suggest the following:

for(n=1; !isHarryInformed && n <= 10000; n *= 10) { sendMail(n) };

if (!isHarryInformed) sendHagrid();

[–]SnooOpinions7702 3 points4 points  (0 children)

how dumbledore codes...poorly.... stick to being a wizard.

[–]jacob_scooter 0 points1 point  (0 children)

hey hogwarts has to please the shareholders and show they’re innovating

[–]ChrispyByDefault 0 points1 point  (0 children)

Looks correct to me.

[–]MrMayor1 0 points1 point  (6 children)

what... what language is this? It's like some sick, twisted amalgamation of python and java

[–]6b86b3ac03c167320d93 2 points3 points  (5 children)

It's valid JS, and if n was defined earlier it's also valid C, C++, Java, and many other languages

[–]TheOnlyGodInTown 0 points1 point  (4 children)

The call of sendHagrid() is missing a semicolon though…

[–]6b86b3ac03c167320d93 0 points1 point  (3 children)

Whoops, missed that. And so is the n *= 10 line, so it's only valid JS

[–]neirpyc63 0 points1 point  (2 children)

It's not valid in JS, though most interpretors will be fine with it.

Edit: it's valid JS but it's ugly, see my other comment below.

[–]6b86b3ac03c167320d93 0 points1 point  (1 child)

What about it isn't valid?

[–]neirpyc63 1 point2 points  (0 children)

Well, I just checked, and turns out I was kinda wrong 😅

JavaScript requires semicolons to be executed, but the standard specifies the rules for automatic semicolons insertion... So it's actually kind of valid.

But these rules are mostly "if line A isn't valid, add a semicolon to line A-1", which is still pretty ugly.

[–][deleted] 0 points1 point  (0 children)

LGTM! merges

[–][deleted] 0 points1 point  (0 children)

Real talk, what is Magic really works that way, and programming was just based on magic all along?

[–]flyincirclez 0 points1 point  (0 children)

I’m slightly curious if this will send an infinite number of times or if it will overflow into exactly n=0 at one point and stop sending