Linked by MOS6510 on Wed 17th Apr 2013 21:20 UTC
General Development "You often hear about how important it is to write 'readable code'. Developers have pretty strong opinions about what makes code more readable. The more senior the developer, the stronger the opinion. But, have you ever stopped to think about what really makes code readable?"
Permalink for comment 559121
To read all comments associated with this story, please click here.
henderson101
Member since:
2006-05-30

Bools begin with Has, Can, Is. E.g dataReader.HasRows, String.IsNull etc.


That is a property, not necessarily what the field will be called. I had occasion to have to write some code a while back to remove event handlers programatically (clean up code from a bit of legacy code) and to do that I needed to remove the "TextChanged" event handler on a generic Control instance. Guess what Microsoft called the private member variable? "EventText". Oh, joy. every other event is called pretty much "Event<EventName>", so "ValueChanged" would be "EventValueChanged" and "SelectedValueChanged" would be "EventSelectedValueChanged"... so this is extremely inconsistent!!

As for your example, that is SqlDataReader, the IDataReader interface has no HasRow property, which is a complete PITA when it comes to sharing code between different database back-ends. What you end up doing is calling Read(), and if it returns true, you know you're cooking with gas. This works well for loops, because you will end up with : while(reader.Read()) {...}, but if you have occasion to be using a IDataReader with a single row**, it's a bit of a bind. (I'm not a great fan of ADO.Net, I think it's pretty poorly designed and pretty much use EF Code first now for everything.)

** Using a IDataReader for a single row is an edge case, but as I generally cache all data in class instances regardless, DataTables are mostly complete overkill.

Reply Parent Score: 2