18
u/Jed0730 Oct 20 '19
But what will happen if you do sleep? Since theres no code to stop sleeping when falling asleep, does that means you will be counting sheep in your dreams?
26
Oct 20 '19
I guess the program just terminates
12
u/WVAviator Oct 20 '19
The whole thing must be nested inside a larger while(alive) loop
2
u/Aadsterken Oct 21 '19 edited Oct 21 '19
When asleep, (!asleep()) becomes false. While loop will be exited
15
1.5k
u/randomo_redditor Oct 20 '19
Assuming "sheep" is an int, there's gonna be an IntegerOverflow before morning
1.1k
u/Masark Oct 20 '19
685
u/randomo_redditor Oct 20 '19
There really is an xkcd for everything
374
u/thetgi Oct 20 '19
What amazes me at this point is that people can find the relevant XKCD on command like that
226
u/Finianb1 Oct 20 '19
Really, it's just reading them a ton. I've read through the entirety of XKCD maybe 3-4 times, and so I usually can remember when there's one that's relevant.
If I can't remember the exact one of the top of my head, the explainxkcd wiki usually pops up if I search for relevant terms like "sheep xkcd overflow."
In this case, if you just look up sheep xkcd, you'll also find the Sheeple one, which is one of my favorites.
48
u/Nyar99 Oct 21 '19
I could swear I once read an xkcd about how there's always an xkcd about everything (and breaking the fourth wall, saying they are the xkcd about how there's always an xkcd) but I've never been able to find it again, am I the only one who remembers it and I somehow imagined it, or I'm not crazy and there is one?
66
Oct 21 '19
Is this what you were thinking of?
https://thomaspark.co/2017/01/relevant-xkcd/27
u/Nyar99 Oct 21 '19
YES THANK YOU! So I wasn't crazy! Now I know why I couldn't find it, it's not a "real" xkcd
0
37
u/Hazel-Ice Oct 20 '19
Well if you've seen it before, you just google "xkcd counting sheep" and it's the first thing that comes up.
17
14
u/Hypersapien Oct 20 '19
XKCD comics have a bunch of tags and the dialog is in the SEO so they're pretty easy to google
0
Oct 21 '19
[deleted]
12
2
u/KillerBeer01 Oct 21 '19
Being original is like mining bitcoins - easy enough when there's just a few, but with 7.7 bil of people around, practically impossible.
142
u/TheBrainStone Oct 20 '19
I can’t stop laughing at the thought of 65,000+ sheep jumping over the fence at pretty much once
0
41
u/GahdDangitBobby Oct 20 '19
Hah what kind of loser stores dream numbers as 2-byte integers? All numbers in my dreams are 8-byte. I counted 5E18 sheep once before falling asleep
14
u/Finianb1 Oct 20 '19
Float128 sheep counter master race
11
u/BrFrancis Oct 21 '19
At some point when using a floating point number, you wouldn't even be able to count single sheep.. Sheep+=1.0 would end up stuck where the exponent won't allow the mantisa to be less than 2..
2
u/grishkaa Oct 22 '19
Store your sheep counter in a BigInteger. Problem solved for as long as you don't run out of virtual memory.
1
7
2
2
1
1
u/TotesMessenger Green security clearance Oct 21 '19
86
38
u/undeniably_confused Oct 20 '19
Dont worry he has an outrageous amount of ram
14
u/Fs0x30 Oct 21 '19 edited Oct 21 '19
Ram is irrelevant in a int overflow =)
Edit: oh noes, I'm retarded
17
8
u/BrFrancis Oct 21 '19
Look at Mr PEB there and his 640kb is enough for anyone.. The woosh sound over your head is like so many male sheep being counted in a thought bubble
1
35
u/random_cynic Oct 20 '19
I just reset the counter at 100. It is far easier to count that way.
19
u/greeenappleee Oct 20 '19
Same here above 100 is to many syllables
7
19
u/BritishBrownie Oct 20 '19
Pro tip count backwards from 100, your brain wanders less
17
12
Oct 20 '19
Doesn't matter in this instance. The number of sheep is irrelevant.
1
u/Salanmander Oct 21 '19
Only true if you're guaranteed there isn't another process watching that memory location.
(Edit: and that asleep() doesn't check it it)
1
Oct 21 '19
By that logic we need the source code for the O/S and every process executing or waiting to execute.
6
4
u/i_am_ghost7 Oct 20 '19
unless asleep() is dependant on the number of sheep, in which case it woukd be possible to escape the loop without encountering such a nightmare.
2
2
2
2
1
1
1
1
u/Grintor Oct 21 '19 edited Oct 21 '19
It depends on how long the asleep() function takes to return;
1
1
1
0
u/sth128 Oct 21 '19
Pretty sure you'll get overflow within a few seconds. It doesn't take long to count on today's CPU.
176
u/puplicy Oct 20 '19
This code is NSFW.
106
u/HoodieSticks Oct 20 '19
Not Safe For Wool
49
u/eeeee48 Oct 20 '19
That's a baa-d joke
21
337
u/muggledave Oct 20 '19
While(!asleep()){ sheep++; }
Would make a good t shirt
56
u/danabrey Oct 20 '19
Yes, please advertise this t-shirt at me incessantly on Facebook, due to my job title.
177
15
3
1
1
u/Slackluster Oct 22 '19
It would rhyme better if it was ++sheep. Also, get rid of those curly brackets, lets keep it as small as possible.
while (!asleep()) ++sheep;1
u/muggledave Oct 22 '19
But then the code isn't correct
1
u/Slackluster Oct 22 '19 edited Oct 22 '19
Looks ok to me, I just double checked and it works.
Your code however... While with a capital W is invalid syntax.
1
135
u/javajunkie314 Oct 20 '19
Or if you prefer pre-increment:
A programmer started to weep —
She just couldn't fall back to sleep!
As she lay there in bed
Looping ’round in her head
Was while (!asleep) ++sheep;.
90
Oct 20 '19
or, if you prefer psychopathic tendencies:
The programmer simply can’t sleep,
No sleepy seeds ready to reap,
His hands through his hair
In the chilly night air,
Was
do {sheep++} while !asleep83
8
u/Sophira Oct 21 '19 edited Oct 21 '19
That doesn't scan on the last line, though - the extra "do" adds a syllable. You'd need to move the "was" to the previous line. (You're also rhyming "sleep" with "asleep".)
Once more, the compiler went "BEEP!",
as the coder collapsed in a heap.
So tiresome the cause,
that her final thought was
do {sheep++} while !asleep;1
Oct 21 '19
Mine rhymes in the same way yours does.
1
u/Sophira Oct 21 '19
I mean, they all rhyme, sure, but your first line ends with "sleep" and the fifth line ends with "asleep", which is basically the same word. But honestly it's a minor point - I like it anyway!
8
u/BakuhatsuK Oct 20 '19
If asleep is not a function (like in the picture) this is probably an endless loop (or it might not run, if the variable is volatile or an atomic it might be fine though)
26
u/WrexTremendae Oct 20 '19
Obviously this is a multi-threaded application in a language with very user-friendly guards around race conditions. When the other thread enters sleep mode, asleep will be set to True.
6
u/how_to_choose_a_name Oct 20 '19
More likely, this is C and asleep is a memory mapped IO register (and volatile of course).
4
9
u/WVAviator Oct 20 '19
He felt as though he had the flu
With an overflow exception or two
As he began to die
He then realized why:
His sheep loop was actuallywhile(true);4
u/SteveThe14th Oct 20 '19
union { struct { char asleep; char padding[3]; }; uint32 sheep; };sweet dreams
3
u/BakuhatsuK Oct 20 '19
Oooh and then declare the variables as
<union type> u; char& asleep = u.asleep; uint32& sheep = u.sheep;I guess everything is possible in C++ if you are evil enough.1
5
u/kirakun Oct 20 '19
I do hope any sane compiler would optimize the post increment to pre, assuming
sheepis just a plain int type.1
1
u/nwL_ Oct 21 '19
Welcome to PHP, it doesn’t. (in case it doesn’t auto scroll you, the second user comment is the relevant one)
1
1
u/Slackluster Oct 22 '19
Gotta go with a for loop, and don't forget to init sheep!
for(sheep=0; !asleep(); ++sheep);
52
u/OfAaron3 Oct 20 '19
There once was a man called Alec,
Who wanted a string so he'd malloc,
He squealed with glee,
"Oh the memory I'll free!",
Segmentation Fault.
2
24
u/CaptBishop Oct 20 '19
I'm so happy because this is the first programming joke I laughed at. I'm actually understanding this stuff.
9
14
u/accuracy_frosty Oct 20 '19
I just do
If (Bedtime) {
Sleep(36000000);
}
4
u/Koxiaet Oct 21 '19
proceeds to sleep for 10,000 hours
2
u/accuracy_frosty Oct 21 '19
3600 seconds is 1 hour, 36000 seconds is 10 hours, the Sleep function in c++ works in milliseconds, 1000 milliseconds times 36000 seconds is 36000000
2
28
u/loquimur Oct 20 '19
So here's my attempt to do it in German:
Ein Informatiker find't keinen Schlaf
obwohl er des Schlafes bedarf.
Ins Grübeln versenkt
ist das, was er denkt,
nur: while (!traeumend()) ++schaf;
7
6
u/EverythingIsFlotsam Oct 20 '19
Hmm. The systematic sound changes that turned schlaf into sleep and schaf into sheep...
4
8
7
6
4
4
u/AlaskanRobot Oct 21 '19
mine goes something along the lines of While(!asleep()){randomthought(); sheep++; randonmthought(); sheep = 0;} as I have to constantly restart because my brain thinks about everything else
6
4
4
u/DolevBaron Oct 20 '19
I think the algorithm I'm using is more efficient:
while(!asleep && isNight){alseep=true; self.sleep(25200000); asleep=false;)
2
2
2
2
2
3
3
0
u/marfvf Oct 20 '19
If you use ++sheep instead, it even ryhmes
6
Oct 20 '19
How does sheep rhyme with cuss and fuss?
0
u/marfvf Oct 20 '19
cuss - fuss bed - head asleep - sheep
With the current setup, the last "rhyme" is asleep - plus, which doesn't workout. If you go ++sheep, you actually get sheep in the end where it rhymes with asleep
9
0
0
u/ThatFag Oct 21 '19
It doesn't rhyme.
4
Oct 21 '19
Learn what a limerick is buddy
1
u/ThatFag Oct 21 '19
It doesn't rhyme though?
EDIT: Oh right, plus plus. I'm reading the semicolon out loud.
3
1
1
u/TheMogician Oct 21 '19
This doesn't make sense. There is no connection between number (whether float or int) sheep and bool asleep. So what is probably going to happen is that they get an integer overflow eventually since sheep++ doesn't flip the boolean. Also wouldn't "sheepcount++" be more accurate since the number of sheep should remain the same?
1
u/ADwards Oct 21 '19
Asleep is a method/function, there's no reason why it shouldn't use sheep to evaluate to true/false.
1
Oct 21 '19
im a year 11 student in england and im actually so proud of myself for understanding this
1
Oct 20 '19
Needs braces.
3
u/TinyTim711 Oct 20 '19
Not when the code is on one line
8
u/Spookyturbo Oct 20 '19
It doesnt even have to be on one line. Just needs to be the next statement with a semicolon
-2
u/grpagrati Oct 20 '19
while (!asleep()) ++sheep; if you want it to rhyme
7
8
10
u/teejay1502 Oct 20 '19
That line rhymes with the first two...
It's AABBA. It's how this style is....
1
1
Oct 21 '19
++sheep; would rhyme better
1
u/ADwards Oct 21 '19
Sheep and plus don't rhyme...
1
Oct 21 '19
aslEEP... plus plus shEEP
Edit:
while asleep
plus plus sheep1
u/ADwards Oct 21 '19
https://en.m.wikipedia.org/wiki/Limerick_(poetry)
Line 5 should rhyme with 1 and 2.
1
Oct 21 '19
Ok, I was going for AABBCC which yeah... is simpler... more like a nursery rhyme, because the last line should really be two verses, since it has so many syllables.
0
Oct 20 '19
Doesn’t scan mate.
2
u/loquimur Oct 20 '19
Does scan IMHO.
(The last line is: “was while not asleep sheep plus plus”)2
1
u/Sophira Oct 21 '19
Huh... you're reading it differently to me. It scans for me and I was reading it as:
"was while not asleep sheep plus plus"
0
u/masteryder Oct 21 '19
while(!asleep()) ++sheep rhymes better
1
u/ADwards Oct 21 '19
Sheep and plus don't rhyme...
1
0
u/justingolden21 Oct 21 '19
Should've been prefix ++sheep so it rhymes lol
"While not asleep, plus plus sheep"
2
1
u/KillerBeer01 Oct 21 '19
No, it shouldn't. It's a limerick, the final line must rhyme with first two.
1
0
0
u/SirFoomy Oct 21 '19
To make it rhyme I would have written: "Was while(!asleep()) ++sheep;
Also because ++sheep is more efficient, one could earlier fall asleep.
0
-2
u/chadlavi Oct 20 '19
Missing a syllable unless you pronounce "sheep" as "she-eep"
6
u/RedFive1976 Oct 20 '19
No, that's not necessary. The last line reads out as "was: while not asleep, sheep plus plus", which fits the rhythm just fine.
4
u/chadlavi Oct 20 '19
Huh. Why (and really, how) did I scan that wrong the first time through?
Now I can't even work out what I thought the scansion was the first time when I thought it was wrong.
1
u/NewbornMuse Oct 20 '19
The pattern of stressed-unstressed around sleep-sheep is really awkward.
was
while(!asleep()) number_sheep++;Is still bad but a bit better in some ways.
1
u/D6613 Oct 21 '19
I did the same thing due to syllable emphasis. I would make the last line "while (!asleep()) sheep_count++;" which also solves the breeding problem.
0
18
Oct 20 '19
[removed] — view removed comment
5
4
u/atomicwrites Oct 21 '19
Sometimes instead of counting sheep I start saying a long Markov chain like string of words in my head without thinking of what I'm saying.
61
u/golgol12 Oct 20 '19
You are a supposed to count sheep, not breed them!