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 559045
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[2]: Comment by lucas_maximus
by lucas_maximus on Thu 18th Apr 2013 13:04 UTC in reply to "RE: Comment by lucas_maximus"
lucas_maximus
Member since:
2009-08-18

For example With C#, Microsoft have pretty standard naming conventions for a reason.

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

I am sure similar practices are practiced in languages I am less familiar with.

Edited 2013-04-18 13:08 UTC

Reply Parent Score: 2

TempleOS Member since:
2013-04-03

The rules for 50,000,000 lines of code are different from 140,000 or 10,000 or 1,000.

I aspire to be more libertarian than hall-monitor. I stop myself when I get an impulse to make up rules to keep things extra tidy.

Clearly, there is no end to the number of policies you could invent to keep code tidy. Moderation, I guess. Don't pat yourself on the back because you can make-up lots of rules. It becomes the most important thing, if you're not careful. Even beginner programmers might want to develop an attitude like a manager and spend a lot of thought thinking about what the code accomplishes. Code which has no purpose is not good no matter how tidy.

Edited 2013-04-18 13:22 UTC

Reply Parent Score: 0

lucas_maximus Member since:
2009-08-18

The rules for 50,000,000 lines of code are different from 140,000 or 10,000 or 1,000.


Err no they aren't.

Reply Parent Score: 2

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

lucas_maximus Member since:
2009-08-18

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

if(!String.IsNullOrEmpty(myString){
//some code.
}

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

if(!isAnimating){
//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