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?"
Thread beginning with comment 559121
To view parent comment, click here.
To read all comments associated with this story, please click here.
Member since:

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

lucas_maximus Member since:

My point was that bools tend to have names that when plugged into an if statement make it almost read like English.

//some code.

I tend to use similar in other programming languages. For example in a JavaScript.

//some code.

I know Microsoft's own variable naming schemes can be a bit iffy in places. But it better with the newer version on .NET IMHO.

Edited 2013-04-18 18:28 UTC

Reply Parent Score: 2