Greater Than WTF SOD
-
Quickie SOD. I'm trying to be very forgiving of the older codebase I'm wading through at the moment. Passing over the rookie mistakes and minor wtfs you expect to see in a 2005 .Net codebase.
Except for this line, because the comments show that it was written in 2013. How can you check if there are rows in a dataset? Obviously, the answer is:
@sigh said:
If dtDataTable.Rows.Count + 1 > 0 Then ' Do stuff End If
-
@Lorne Kates said:
Except for this line, because the comments show that it was written in 2013.
So are you now looking for a new job due to workplace violence?
-
What if the database has a negative number of rows? How you gonna check for that, Mr. Smarty Pants?
-
@Lorne Kates said:
Quickie SOD. I'm trying to be very forgiving of the older codebase I'm wading through at the moment. Passing over the rookie mistakes and minor wtfs you expect to see in a 2005 .Net codebase.
Except for this line, because the comments show that it was written in 2013. How can you check if there are rows in a dataset? Obviously, the answer is:
@sigh said:
If dtDataTable.Rows.Count + 1 > 0 Then ' Do stuff End If
Ok, so he's a little too lazy to refactor and change it to >= 0. Unless there's some weirdness about .NET that I'm missing, what's the huge WTF here?
-
@Lorne Kates said:
My diagnosis: this codebase uses zero-based indexing, with the convention that Count fields are not actually counts but maximum indexes, because the designer with the VB background was determined to stick it to the other designer with the C background and "prove" that zero-based indexing is just impossibly confusing.Quickie SOD. I'm trying to be very forgiving of the older codebase I'm wading through at the moment. Passing over the rookie mistakes and minor wtfs you expect to see in a 2005 .Net codebase.
Except for this line, because the comments show that it was written in 2013. How can you check if there are rows in a dataset? Obviously, the answer is:
@sigh said:
If dtDataTable.Rows.Count + 1 > 0 Then
' Do stuff
End If
-
@Snooder said:
Ok, so he's a little too lazy to refactor and change it to >= 0. Unless there's some weirdness about .NET that I'm missing, what's the huge WTF here?
It is possible for the Rows collection to be Nothing (or NULL) which would cause an Object Reference error. The only time I've seen the Rows collection empty is when an asshole creates a proc with an IF statement in it that results in no recordset at all being returned.
I was certain there was a property on the datatable called HasRows, but that appears to be on DataTableReader instead. Huh.
-
There was a bit of anonymization. The code was wrapped in a "If dtDataTable Is Not Nothing". And the inner "if" block refers to dtDataTable.Rows(0), so the posted if statement SHOULD be checking .Rows.Count > 0.
I have no idea. But at least the whole thing was wrapped in a Try/Catch block, so no one noticed for half a year.
Whiskey time.
-
@Snooder said:
>= 0
Y u mad?
-
@Zecc said:
@Snooder said:
>= 0
Y u mad?Imagine this:
If AbsoluteValue(someInteger) <font size="36">+ 1</font> >= 0 Then
-
@Lorne Kates said:
@Zecc said:
@Snooder said:
>= 0
Y u mad?Imagine this:
If AbsoluteValue(someInteger) <font size="36">+ 1</font> >= 0 Then
Obviously we just need to find an integer whose absolute value is less than -1, then.
-
@Ben L. said:
@Lorne Kates said:
@Zecc said:
@Snooder said:
>= 0
Y u mad?Imagine this:
If AbsoluteValue(someInteger) <font size="36">+ 1</font> >= 0 Then
Obviously we just need to find an integer whose absolute value is less than -1, then.
[code]
Math.abs(parseInt(NaN)) + 1 >= 0
[/code]
[code]false[/code]
Javascript is weird.
-
@flabdablet said:
My diagnosis: this codebase uses zero-based indexing, with the convention that Count fields are not actually counts but maximum indexes, because the designer with the VB background was determined to stick it to the other designer with the C background and "prove" that zero-based indexing is just impossibly confusing.
0-based indexing. So easy my project managers can do it.I'm still working on getting them to deal properly with lists written like this, though:
0) foo
1) bar
2) baz
3) quux
4) quuux
5) quuuux
6) quuuuux
7) quuuuuux
8) quuuuuuux
9) quuuuuuuux
A) quuuuuuuuuxetc. and correct refer to "Item #A"
-
quuuuuuuuuuuuuuuuuuuux
-