@Chris F said:
The code you pasted used an ordinal rather than an actual name from the resultset. That is usually inferior to value access by name, as it couples a value with position in a resultset - something that almost never has any semantic value whatsoever. Nevertheless, I don't find that line of code to be "unnecessarily complex". Unsafe, confusing, and silly yes. But not complex.
I did use a magic number in the example, which I agree is poor in practice, so I'll clarify. As with any constant value, I use constants to represent the columns. Should the columns be reordered, it's as simple as renumbering the constant. This is no different than having to change a string name for a column. This is also much more preferable than doing a GetOrdinal(name) every time.
As for unsafe and confusing.. it all depends on the wielder, I suppose. I find it to be "safer" than any other method discussed.
@Chris F said:
Your above statements are nothing more than fallacies of distraction that focus on external forces instead of the WTF code in question.
Focusing on the code in question, why would you believe it to be a WTF without taking external forces into consideration?
@Chris F said:
The best of processes will still yield code with bugs. You can not excuse poor code such as this no matter how fabulous your change process.
I'll wholeheartedly agree, starting from scratch, that this is a sloppy tactic to employ. I never said it was brilliant. So for the record, don't do it. There... we agree on that.
However, as I said from the start and in every post after that, I see the code as lazy, not insidious. I don't like it, I don't use it, but the level of risk it poses is minimal. I don't like explicit casts for that matter, which I've already covered. The simple point I was trying, and perhaps failed, to make before we began this long discussion is that when it comes to refactoring, you have to pick your battles. I think everyone that has been in software for a while has come across systems with sections of code that they would just love to rewrite for the sake of "purity". Giving in to this predilection every time makes for low productivity, especially given the fact that most of the time, it will not make a difference.