DataRow currentStatusRow = DB.RtnRow(
@"SELECT TOP 1 ob.Status, obd.descr, obd.OutboxDetailID FROM OutboxDetail obd
JOIN outbox ob ON obd.OutboxId = ob.OutboxID
WHERE ob.OutboxID = @0 ORDER BY OutboxDetailID DESc", 0, outbox.outboxID);
if (currentStatusRow["Descr"].ToString() != "Attempting Resend"
&& (currentStatusRow["Status"].ToInt() != outbox.status.ToInt() ||
currentStatusRow["OutboxDetailID"].ToInt() > 0))
return;
So I have a question regarding the if
statement above. I'm trying to make sure that the condition doesn't return out/exit as long as the "Descr"
has a value of "Attempting Resend"
. If the "Descr"
column has that specific description, I want to continue with the code below.
My breakpoints are somehow unbound when testing this so, finding it hard to test. Does the condition look correct?
CodePudding user response:
I believe you should write the code to clearly express its intent, even if this sometimes results in an extra line or two. Unclear code is like a dark corner in a basement- hard to see where the bugs could be.
Some people may be able to parse the conditional given in the question easily (I am not one of them); however, given that you are asking about its behavior, you should consider that it's not clear enough.
You mention in the question that if the "Descr" column has the specific value of "Attempting Resend", then you want to make sure the method doesn't return. Consider writing the code below, which I think clearly shows what the expected path is:
// Don't allow possibility of returning if the status description is "Attempting Resend":
if (currentStatusRow["Descr"].ToString() != "Attempting Resend")
{
if (currentStatusRow["Status"].ToInt() != outbox.status.ToInt() ||
currentStatusRow["OutboxDetailID"].ToInt() > 0)
{
return;
}
}