Comment On The Nightly Session Drop

“Shortly after joining my new company,” writes Rajesh Subramanian, “they introduced me to The Monster: a massive, incomplete framework written in C++. Its documentation consisted of a few sparse, often contradictory comments. It was designed to be multithreaded, but always crashed with more than one thread. It was expected to run on different operating systems, but never quite made it past Windows 2000 SP3. And naturally, it’s filled with friendly variable names like s, t, pp1, pp2, and so on.” [expand full text]
« PrevPage 1 | Page 2Next »

Re: The Nightly Session Drop

2008-04-28 08:02 • by dpm
I can't imagine what he's complaining about . . . after all, there is a helpful, accurate comment right on the line he's looking at. Score!

Re: The Nightly Session Drop

2008-04-28 08:04 • by S (unregistered)
Ok, not the best way of saying what an invalid session is, but at least the code was commented and it was clear what it did.

Re: The Nightly Session Drop

2008-04-28 08:04 • by m (unregistered)
Hmm by that logic: I was born in the early 1980's....that was last millennium....which means I've been living over 1000 years! Result!

Re: The Nightly Session Drop

2008-04-28 08:08 • by ParkinT
//A weekend has passed. This must be another Daily WTF
Post->write("new comment");

Re: The Nightly Session Drop

2008-04-28 08:09 • by NaN
I have a choice of:

This is a comment I wrote yesterday, it must definitely be invalid.

Or:

Eventually, bad things will happen in the following pieces of code:

//this is definitely [anything]

if(exp1)
{
//DO
}
else if(exp2)
{
//Do Something Else
}
else
{
//This condition will never be true
//Do nothing
}

Also seen while at was at university, one of my tutors provided the following "Infinite Loop":

System.out.println("I am going to loop.");
for(int counter = 0; counter => 0; counter ++)
{
//This will happen forever
}
System.out.println("You have now entered the twilight zone."); // This will never happen

I had to point that one out.

Re: The Nightly Session Drop

2008-04-28 08:27 • by Dave (unregistered)
191807 in reply to 191803
S:
Ok, not the best way of saying what an invalid session is, but at least the code was commented and it was clear what it did.


Perhaps this site needs a sister "Daily Hmmm" for bugs which take a few mins to fix.

> This would occasionally lead to ‘really bad things’ that
> could take all day to fix.

It could do, I guess. But a repeatable bug, caused by code accurately commented with text which should be amongst the first thing you'd grep for shouldn't take more than a few mins to fix. This wouldn't make a bad interview task for a company which wishes to weed out jumped up HTML hairdressers who think they can code because they know a bit of javascript from actual programmers.


Re: The Nightly Session Drop

2008-04-28 08:35 • by NaN
191808 in reply to 191807
Dave:

Perhaps this site needs a sister "Daily Hmmm" for bugs which take a few mins to fix.


How about "The Daily Oh... Fixed"?

Re: The Nightly Session Drop

2008-04-28 08:48 • by SlyEcho (unregistered)
191810 in reply to 191806
NaN:
I have a choice of:

System.out.println("I am going to loop.");
for(int counter = 0; counter => 0; counter ++)
{
//This will happen forever
}
System.out.println("You have now entered the twilight zone."); // This will never happen

I had to point that one out.


I got stumped on this one some time ago:

for (byte b = 0; b <= 255; b++)
{
// stuff
}

Re: The Nightly Session Drop

2008-04-28 08:49 • by snoofle
191811 in reply to 191808
NaN:
Dave:

Perhaps this site needs a sister "Daily Hmmm" for bugs which take a few mins to fix.


How about "The Daily Oh... Fixed"?

The Daily Oh-My! What-The-Fudge!?

Re: The Nightly Session Drop

2008-04-28 08:51 • by sdfdfsdfsqdf (unregistered)
191812 in reply to 191806
NaN:
I have a choice of:

System.out.println("I am going to loop.");
for(int counter = 0; counter => 0; counter ++)
{
//This will happen forever
}
System.out.println("You have now entered the twilight zone."); // This will never happen


But that will put everyone in the twilight zone! (2147483647 + 1 = -2147483648.)

Re: The Nightly Session Drop

2008-04-28 08:53 • by snoofle
191813 in reply to 191811
I just did a grep for the counterpart to "Disconnect" in the system I work on - 6 occurrences out of 400K + LOC - elapsed time: 30 seconds + 3 minutes to read each in context.

What, exactly, took Rajesh 1/2 day to figure out?

Re: The Nightly Session Drop

2008-04-28 09:04 • by mallard
191814 in reply to 191812
sdfdfsdfsqdf:
NaN:
I have a choice of:

System.out.println("I am going to loop.");
for(int counter = 0; counter => 0; counter ++)
{
//This will happen forever
}
System.out.println("You have now entered the twilight zone."); // This will never happen


But that will put everyone in the twilight zone! (2147483647 + 1 = -2147483648.)


Or, more generally, MAX_INT + 1 = MIN_INT. Not all systems have 32-bit integers.

Re: The Nightly Session Drop

2008-04-28 09:11 • by vt_mruhlin
191815 in reply to 191813
snoofle:
I just did a grep for the counterpart to "Disconnect" in the system I work on - 6 occurrences out of 400K + LOC - elapsed time: 30 seconds + 3 minutes to read each in context.

What, exactly, took Rajesh 1/2 day to figure out?



Well it was his first task on the job. Some codebases I've worked on, it takes half a day just to figure out where to grep.

Re: The Nightly Session Drop

2008-04-28 09:13 • by snoofle
191816 in reply to 191815
vt_mruhlin:
snoofle:
I just did a grep for the counterpart to "Disconnect" in the system I work on - 6 occurrences out of 400K + LOC - elapsed time: 30 seconds + 3 minutes to read each in context.

What, exactly, took Rajesh 1/2 day to figure out?



Well it was his first task on the job. Some codebases I've worked on, it takes half a day just to figure out where to grep.
Fair enough...

Re: The Nightly Session Drop

2008-04-28 09:24 • by Matt (unregistered)
191817 in reply to 191806
NaN:

Also seen while at was at university, one of my tutors provided the following "Infinite Loop":

System.out.println("I am going to loop.");
for(int counter = 0; counter => 0; counter ++)
{
//This will happen forever
}
System.out.println("You have now entered the twilight zone."); // This will never happen

I had to point that one out.


Was the intention to show what happens when ints overflow, or was he just being dumb?

while(TRUE){
// loop forever
}

Re: The Nightly Session Drop

2008-04-28 09:28 • by greyrat (unregistered)
If this is the Raj from my company, I'd add this question to this reseaarch on this code: "If you're a global company with offices in the US, Europe, India and Southeast Asia, just when _is_ midnight?

Re: The Nightly Session Drop

2008-04-28 09:45 • by Jon Skeet (unregistered)
191819 in reply to 191814
mallard:

Or, more generally, MAX_INT + 1 = MIN_INT. Not all systems have 32-bit integers.


True, but there are pretty good signs this is Java, where int is guaranteed to be 32 bits.

If we don't assume programming language, "int" could be unsigned by default, which would make the loop properly infinite (without contradicting your statement, of course).

Jon

Re: The Nightly Session Drop

2008-04-28 09:50 • by NaN (unregistered)
191820 in reply to 191817
Matt:
NaN:

Also seen while at was at university, one of my tutors provided the following "Infinite Loop":

System.out.println("I am going to loop.");
for(int counter = 0; counter => 0; counter ++)
{
//This will happen forever
}
System.out.println("You have now entered the twilight zone."); // This will never happen

I had to point that one out.


Was the intention to show what happens when ints overflow, or was he just being dumb?

while(TRUE){
// loop forever
}


Unfortunately, that was one of about 10 examples (Including the one you just gave) that were supposed to be infinite loops.
I did have to explain why it wasn't, although he did seem to understand the overflow thing, meaning that it was just an oversight, however, he did try and bluff his way out of it with "Well, it will last a very long time, it might as well be an infinite loop".

Re: The Nightly Session Drop

2008-04-28 09:51 • by NaN (unregistered)
191821 in reply to 191819
Jon Skeet:
mallard:

Or, more generally, MAX_INT + 1 = MIN_INT. Not all systems have 32-bit integers.


True, but there are pretty good signs this is Java, where int is guaranteed to be 32 bits.

If we don't assume programming language, "int" could be unsigned by default, which would make the loop properly infinite (without contradicting your statement, of course).

Jon


It was Java. C++ tutor.

Re: The Nightly Session Drop

2008-04-28 10:03 • by Anon (unregistered)
191824 in reply to 191810
SlyEcho:
I got stumped on this one some time ago:

for (byte b = 0; b <= 255; b++)
{
// stuff
}

Assuming Java, something as simple as:

for (byte b = 0; b <= 127; b++) { }

Is infinite. Bytes in Java are always signed. In fact, the only unsigned data type in Java is char, just to prove that Java abhors consistency.

Re: The Nightly Session Drop

2008-04-28 10:12 • by entropy (unregistered)
191828 in reply to 191810
SlyEcho:


I got stumped on this one some time ago:

for (byte b = 0; b <= 255; b++)
{
// stuff
}


actually, you only need b<=127 if that's a signed byte(which is the default in all of the languages I've dealt with so far)

Re: The Nightly Session Drop

2008-04-28 10:29 • by xtremezone
191836 in reply to 191820
NaN:
Unfortunately, that was one of about 10 examples (Including the one you just gave) that were supposed to be infinite loops.
I did have to explain why it wasn't, although he did seem to understand the overflow thing, meaning that it was just an oversight, however, he did try and bluff his way out of it with "Well, it will last a very long time, it might as well be an infinite loop".

The overflow didn't occur to me when I was looking at the code. My excuse is that I'm tired... I keep my infinite loops simple though. :)
while(true)

{
// Loop indefinitely.
}

There's also the following that I've seen suggested as a joke (wouldn't recommend it myself)...
#define EVER ;;

for(EVER)
{
// Loop indefinitely.
}

Re: The Nightly Session Drop

2008-04-28 10:40 • by Andy Goth
191839 in reply to 191836
xtremezone:
I keep my infinite loops simple though. :)
I like this one:
while (2) {...}

Re: The Nightly Session Drop

2008-04-28 10:41 • by Mirvnillith
191840 in reply to 191813
snoofle:
I just did a grep for the counterpart to "Disconnect" in the system I work on - 6 occurrences out of 400K + LOC - elapsed time: 30 seconds + 3 minutes to read each in context.

What, exactly, took Rajesh 1/2 day to figure out?



I think the time to fix was for the fallout of the dropped connections, not for fixing the disconnect issue.

Re: The Nightly Session Drop

2008-04-28 10:51 • by Gertjan (unregistered)
191850 in reply to 191802
dpm:
I can't imagine what he's complaining about . . . after all, there is a helpful, accurate comment right on the line he's looking at. Score!

Obviously the whole WTF is that the line does not check for a day 'passed', but a day 'wrapped'. So the comment is incorrect.

Re: The Nightly Session Drop

2008-04-28 10:53 • by GF (unregistered)
191852 in reply to 191813
snoofle:
I just did a grep for the counterpart to "Disconnect" in the system I work on - 6 occurrences out of 400K + LOC - elapsed time: 30 seconds + 3 minutes to read each in context.

What, exactly, took Rajesh 1/2 day to figure out?


Well, if he's any good, he would have cross-referenced that method/function to determine under which conditions it's being called, and from where. After doing that, he would have had to ensure that he tested (or ran unit tests) for all scenarios; including setting up the same border condition that caused the issue in the first place. Too, he should also be testing with a session that actually /is/ 23 hours old (or simulated as such) to make sure that there are no issues encountered.

Fixing a bug on the basis of one line of code/one comment can turn into a much larger WTF than the original issue ever was; especially in an application as reportedly complex as this one.

Re: The Nightly Session Drop

2008-04-28 10:56 • by mccoyn (unregistered)
If that comment wasn't there, he would be left wondering if this code did something important or was a blatant misunderstanding of time and space. With the comment it is clear.

Re: The Nightly Session Drop

2008-04-28 11:03 • by for(EVER) (unregistered)
Whenever I see a simple comment/piece of code like that in a monster system it makes me feel like it's a trapped door. Once you remove it other more monstrous issues are set free.

Re: The Nightly Session Drop

2008-04-28 11:12 • by NaN
191859 in reply to 191836
boolean paul = true, brilliant = true;

while(paula == brilliant)
{

}

Re: The Nightly Session Drop

2008-04-28 11:12 • by Iwan (unregistered)
191860 in reply to 191820
NaN:

Unfortunately, that was one of about 10 examples (Including the one you just gave) that were supposed to be infinite loops.
I did have to explain why it wasn't, although he did seem to understand the overflow thing, meaning that it was just an oversight, however, he did try and bluff his way out of it with "Well, it will last a very long time, it might as well be an infinite loop".


[iwan@10-70-8-41 ~]$ time java Test
I am going to loop.
You have now entered the twilight zone.

real 0m1.057s
user 0m0.990s
sys 0m0.023s

Yup, that's truely a very long time...

Re: The Nightly Session Drop

2008-04-28 11:16 • by Pope
191863 in reply to 191857
for(EVER):
Whenever I see a simple comment/piece of code like that in a monster system it makes me feel like it's a trapped door. Once you remove it other more monstrous issues are set free.


I know that if I saw a door trapped, I would set it free. "Run little door! The trappers are going to make a coat out of you!"

Re: The Nightly Session Drop

2008-04-28 11:17 • by jimlangrunner
191865 in reply to 191806
NaN:
snip
System.out.println("I am going to loop.");
for(int counter = 0; counter => 0; counter ++)
{
//This will happen forever
}
System.out.println("You have now entered the twilight zone."); // This will never happen

I had to point that one out.


My Mad Skillz is very rusty, but what does "=>" do? If it's a new-fangled assignment, it's going to loop forever. Otherwise, it will just give a compile warning and fail.

At least, I would hope.

Re: The Nightly Session Drop

2008-04-28 11:23 • by Pol
191866 in reply to 191813
snoofle:
I just did a grep for the counterpart to "Disconnect" in the system I work on - 6 occurrences out of 400K + LOC - elapsed time: 30 seconds + 3 minutes to read each in context.

What, exactly, took Rajesh 1/2 day to figure out?


So the REAL WTF is that he only works 9-11

Re: The Nightly Session Drop

2008-04-28 11:27 • by Jay (unregistered)
191868 in reply to 191813
snoofle:
I just did a grep for the counterpart to "Disconnect" in the system I work on - 6 occurrences out of 400K + LOC - elapsed time: 30 seconds + 3 minutes to read each in context.

What, exactly, took Rajesh 1/2 day to figure out?



If I was assigned to diagnose a problem like that, I don't think I'd start out with the assumption that there was a deliberate disconnect of all active sessions every day at midnight, and so just search for a disconnect call. I don't think it would even occur to me that a programmer would be stupid enough to write code like that. I'd start out looking for something complicated. So taking a half a day to find the stupid code doesn't sound bad to me at all.

It's difficult to make any system foolproof, because fool's are so creative.

Re: The Nightly Session Drop

2008-04-28 11:30 • by Jay (unregistered)
191872 in reply to 191820
NaN:

I did have to explain why it wasn't, although he did seem to understand the overflow thing, meaning that it was just an oversight, however, he did try and bluff his way out of it with "Well, it will last a very long time, it might as well be an infinite loop".


Besides, the latest chip from Intel is so fast that it can execute an infinite loop in 12 seconds.

Re: The Nightly Session Drop

2008-04-28 11:37 • by pitchingchris
191876 in reply to 191859
NaN:
boolean paul = true, brilliant = true;

while(paula == brilliant)
{

}


guess this will never execute.. paul is true, paula is undefined (probably false)

Re: The Nightly Session Drop

2008-04-28 11:45 • by hallo.amt
191880 in reply to 191865
jimlangrunner:


My Mad Skillz is very rusty, but what does "=>" do? If it's a new-fangled assignment, it's going to loop forever. Otherwise, it will just give a compile warning and fail.

At least, I would hope.


=> is used in C# for lambda expressions. You can write
sum(someList, i => i<=5);
Which would add all numbers in someList which is less or equal to five.

It's no good in Java so I think its a typo.

Re: The Nightly Session Drop

2008-04-28 11:58 • by Pretty Good Sign (unregistered)
191890 in reply to 191819
Jon Skeet:
mallard:
Not all systems have 32-bit integers.
True, but there are pretty good signs this is Java, where int is guaranteed to be 32 bits.
Such as the "written in C++" bit on the second line of the original post?

Re: The Nightly Session Drop

2008-04-28 12:11 • by Dwedit
191896 in reply to 191859
NaN:
boolean paul = true, brilliant = true;

while(paula == brilliant)
{

}


You misspelled "Brillant".

Re: The Nightly Session Drop

2008-04-28 12:20 • by Bobbo (unregistered)
191902 in reply to 191890
Pretty Good Sign:
Jon Skeet:
mallard:
Not all systems have 32-bit integers.
True, but there are pretty good signs this is Java, where int is guaranteed to be 32 bits.
Such as the "written in C++" bit on the second line of the original post?


I think that Jon's post was part of the discussion about 'infinite loops', rather than the original post. Come on, keep up!

Re: The Nightly Session Drop

2008-04-28 12:22 • by ClaudeSuck.de (unregistered)
191904 in reply to 191813
snoofle:
I just did a grep for the counterpart to "Disconnect" in the system I work on - 6 occurrences out of 400K + LOC - elapsed time: 30 seconds + 3 minutes to read each in context.

What, exactly, took Rajesh 1/2 day to figure out?



He didn't know what to grep for

Re: The Nightly Session Drop

2008-04-28 12:38 • by GettinSadda
191906 in reply to 191904
snoofle:
I just did a grep for the counterpart to "Disconnect" in the system I work on - 6 occurrences out of 400K + LOC - elapsed time: 30 seconds + 3 minutes to read each in context.

What, exactly, took Rajesh 1/2 day to figure out?

It only took 0.004 seconds to locate the bug, but that was after spending half a day merging all the source into a single file so his brillant search tool would work.

Re: The Nightly Session Drop

2008-04-28 12:54 • by KNY
191914 in reply to 191906
GettinSadda:
snoofle:
I just did a grep for the counterpart to "Disconnect" in the system I work on - 6 occurrences out of 400K + LOC - elapsed time: 30 seconds + 3 minutes to read each in context.

What, exactly, took Rajesh 1/2 day to figure out?

It only took 0.004 seconds to locate the bug, but that was after spending half a day merging all the source into a single file so his brillant search tool would work.

I hereby nominate this to be a featured comment. Brillant!

Re: The Nightly Session Drop

2008-04-28 13:10 • by Leak
191920 in reply to 191818
greyrat:
If you're a global company with offices in the US, Europe, India and Southeast Asia, just when _is_ midnight?

Mu.

Re: The Nightly Session Drop

2008-04-28 13:12 • by Leak
191924 in reply to 191836
xtremezone:
There's also the following that I've seen suggested as a joke (wouldn't recommend it myself)...
#define EVER ;;

for(EVER)
{
// Loop indefinitely.
}

There's nothing wrong with
for(;;)

{
// #+*@%&!
}
though...

np: Justus Köhncke - Molybdän (Safe And Sound)

Re: The Nightly Session Drop

2008-04-28 13:44 • by scottl (unregistered)
191927 in reply to 191914
KNY:
GettinSadda:
snoofle:
I just did a grep for the counterpart to "Disconnect" in the system I work on - 6 occurrences out of 400K + LOC - elapsed time: 30 seconds + 3 minutes to read each in context.

What, exactly, took Rajesh 1/2 day to figure out?

It only took 0.004 seconds to locate the bug, but that was after spending half a day merging all the source into a single file so his brillant search tool would work.

I hereby nominate this to be a featured comment. Brillant!

Ummm... you can run grep recursively on a top level directory... Or is that sound I hear a joke going over my head?

Re: The Nightly Session Drop

2008-04-28 15:12 • by dextron
Yes that was a whoosh. There's a person on the forums who write this VBScript (or something) program that performs searches, however you have to create a single file with everything concatenated into it.

For searching I would do something like

find . -exec grep -iH disconnect {} \;

YMMV

Re: The Nightly Session Drop

2008-04-28 15:33 • by shocked (unregistered)
The real WTF: an advertisement for scientology turned up on this page. So they are sick of actors now and going after programmers? Xenu help us.

Re: The Nightly Session Drop

2008-04-28 16:05 • by Franz Kafka (unregistered)
191949 in reply to 191820
NaN:

Unfortunately, that was one of about 10 examples (Including the one you just gave) that were supposed to be infinite loops.
I did have to explain why it wasn't, although he did seem to understand the overflow thing, meaning that it was just an oversight, however, he did try and bluff his way out of it with "Well, it will last a very long time, it might as well be an infinite loop".


It doesn't do anything in the loop, so it doesn't do anything at all. The proper way to halt in place (assuming that there even is one) is to call select() on an empty FD set. On java, you can just do wait().

Re: The Nightly Session Drop

2008-04-28 16:37 • by matt (unregistered)
191953 in reply to 191811
snoofle:
NaN:
Dave:

Perhaps this site needs a sister "Daily Hmmm" for bugs which take a few mins to fix.


How about "The Daily Oh... Fixed"?

The Daily Oh-My! What-The-Fudge!?

The Daily.... oh... that's easy enough. Well, That's Fixed.
« PrevPage 1 | Page 2Next »

Add Comment