I wonder what the programmer was going to do..
-
I just found this in some ancient C code:
if (number_of_records > 0)
{}
else
{}I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|
-
I just found this in some ancient C code:
if (number_of_records > 0)
{}
else
{}I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|
It's a long standing game of Code Tennis. You fill in the "if" part, and send it back for his move on the "else".
Never underestimate the power of stupid things in large numbers --- Serious Sam
-
I just found this in some ancient C code:
if (number_of_records > 0)
{}
else
{}I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|
-
I just found this in some ancient C code:
if (number_of_records > 0)
{}
else
{}I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|
Look at the bright side. There's nothing to undo with this code.
-
I just found this in some ancient C code:
if (number_of_records > 0)
{}
else
{}I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|
-
I just found this in some ancient C code:
if (number_of_records > 0)
{}
else
{}I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|
OP may just have built this piece of code to prevent a warning saying that variable 'number_of_records' has been declared but is never used. Quite brilliant, actually.
Women are composed of carbon, hydrogen, oxygen and nitrogen; men are also composed of carbon, hydrogen, oxygen and nitrogen, but in such proportions that force respect.
-
I just found this in some ancient C code:
if (number_of_records > 0)
{}
else
{}I'd love to know what the original programmer was intending to do here because I have to maintain this crap! X|
-
Looks like an incomplete sanity check. It should be:
if (number_of_records > 0)
{}
else if (number_of_records <= 0)
{}
else
{
// I segfault myself.
printf("%d", *(int*)666);
}Greetings - Jacek
It's always good to check whether a particular record is existing or not before accessing that record. Specially in collections, sometimes it maybe empty or less than the number of required records that you want to access. The following code will execute based on the records available
DataTable table = new System.Data.DataTable(); table.Columns.Add("ID"); table.Rows.Add("1"); string test = string.Empty; int num\_of\_records = table.Rows.Count; if (num\_of\_records > 0) { test = table.Rows\[0\]\[0\].ToString(); } else { return; }
The following code is directly trying to access a record which may or may not be existing though the code is syntactically correct it may throw error in the event of unavailablity of records.
DataTable table = new System.Data.DataTable(); table.Columns.Add("ID"); string test = string.Empty; test = table.Rows\[0\]\[0\].ToString();
IndexOutOfRangeException - There is no row at position 0.
-
It's always good to check whether a particular record is existing or not before accessing that record. Specially in collections, sometimes it maybe empty or less than the number of required records that you want to access. The following code will execute based on the records available
DataTable table = new System.Data.DataTable(); table.Columns.Add("ID"); table.Rows.Add("1"); string test = string.Empty; int num\_of\_records = table.Rows.Count; if (num\_of\_records > 0) { test = table.Rows\[0\]\[0\].ToString(); } else { return; }
The following code is directly trying to access a record which may or may not be existing though the code is syntactically correct it may throw error in the event of unavailablity of records.
DataTable table = new System.Data.DataTable(); table.Columns.Add("ID"); string test = string.Empty; test = table.Rows\[0\]\[0\].ToString();
IndexOutOfRangeException - There is no row at position 0.
I agree, and the original post was probably more of a question of what the developer intended to do inside the {} in both the if part and the else part; which of course could be anything. If anything it's just dead code the compiler would likely cut out.
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak