Benefit of the Doubt
So I genuinely try to give other developers the benefit of the doubt; if I don't get why they wrote/designed something the way they did, I'll try my hardest to accept it and say "they probably had there reasons". And I do this no matter who the author is: internal/group or even Corporate shops...like Microsoft...I'm giving them the benefit of the doubt on this one...to an extent...
I was "pairing", very informalily (though I guess that's the point), with a coworker and we got into a discussion regarding the file he was working on. He was building a screen to manage a M-to-M relationship between two entities (you know, an "select one, select all, deselect one, deselect all" interface?)* and had to filter the selected items out of the "available" and also return a list of the selected items. His code consisted of something like the following:
I informed him that he produced some pretty smelly code since the ASP.NET ListBox control exposes FindByValue() and FindByText() methods. He pointed out to me that these method probably just perform an O(n) iteration of the Items collection to find the desired item. I said "NO WAY! Microsoft is sooo much smarter than that. They probably used an IDictionary implementation that's specialized for such a collection, making it really easy to find the values"
Um...No. They didn't. I even checked Framework 2.0 B2. See for your self:
Why in the world would they do it this way?! I can't imagine it's because of ViewState and persistance. On top of that, there's duplication between FindByValueInternal and FindByTextInternal that I'm sure could've been avoided, especially by using an IDictionary implementation of some sort.
I still, to a degree, feel the need to give Microsoft the benefit of the doubt as they wrote the Framework and I'm sure they had a really good reason for not approaching this problem differently. Needless to say, I was seriously saddened by my discovery...
* The same developer asked me earlier in the day, in reference to the multi-select interface: "so what's the order of the buttons?" Lacking a better answer, I said (with jestures) "it's over, over-over, over, and over-over...OR...over, over-over, over, and over-over, depending on your perspective"...He knew exactly what I meant too...
I was "pairing", very informalily (though I guess that's the point), with a coworker and we got into a discussion regarding the file he was working on. He was building a screen to manage a M-to-M relationship between two entities (you know, an "select one, select all, deselect one, deselect all" interface?)* and had to filter the selected items out of the "available" and also return a list of the selected items. His code consisted of something like the following:
Public Property Selected as IList
Get
return selectedValues
End Get
Set(value as IList)
for each item as ItemType in value
for each availableItem as ItemType in Available
if item.Id = availableItem.Id then
available.Remove(item)
end if
next
next
End Set
End Property
I informed him that he produced some pretty smelly code since the ASP.NET ListBox control exposes FindByValue() and FindByText() methods. He pointed out to me that these method probably just perform an O(n) iteration of the Items collection to find the desired item. I said "NO WAY! Microsoft is sooo much smarter than that. They probably used an IDictionary implementation that's specialized for such a collection, making it really easy to find the values"
Um...No. They didn't. I even checked Framework 2.0 B2. See for your self:
Why in the world would they do it this way?! I can't imagine it's because of ViewState and persistance. On top of that, there's duplication between FindByValueInternal and FindByTextInternal that I'm sure could've been avoided, especially by using an IDictionary implementation of some sort.
I still, to a degree, feel the need to give Microsoft the benefit of the doubt as they wrote the Framework and I'm sure they had a really good reason for not approaching this problem differently. Needless to say, I was seriously saddened by my discovery...
* The same developer asked me earlier in the day, in reference to the multi-select interface: "so what's the order of the buttons?" Lacking a better answer, I said (with jestures) "it's over, over-over, over, and over-over...OR...over, over-over, over, and over-over, depending on your perspective"...He knew exactly what I meant too...
0 Comments:
Post a Comment
<< Home