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 559028
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE: Comment by lucas_maximus
by Soulbender on Thu 18th Apr 2013 11:19 UTC in reply to "Comment by lucas_maximus"
Soulbender
Member since:
2005-08-18

Sorry if someone has a problem understanding what a whole number is, they shouldn't be programming.


Seriously, who *doesn't* know what a whole number is? Other than Tarzan?
And how would NumberOfCoins hide the fact that it's an integer value? The word Number is even there.

They’d rather see the variable named X or Number

Oh I see.
Hey, I have an idea; why not use int1, int2, int3 ... intXXXXX? That way there's no "confusion" regarding the type of the variable and obviously your code would be much more readable...

Reply Parent Score: 3

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

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