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 559015
To read all comments associated with this story, please click here.
Comment by lucas_maximus
by lucas_maximus on Thu 18th Apr 2013 08:03 UTC
lucas_maximus
Member since:
2009-08-18

To them, a long named variable isn’t descriptive, it’s deceptive, because it is hiding the fact that NumberOfCoins represents an integer value with its long name and personification of the variable, as something more than just an integer. They’d rather see the variable named X or Number, because its confusing enough to remember what an integer is.


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

Reply Score: 2

RE: Comment by lucas_maximus
by r_a_trip on Thu 18th Apr 2013 10:01 in reply to "Comment by lucas_maximus"
r_a_trip Member since:
2005-07-06

I didn't get this either. What is so baffling about NumberOfCoins?

It's a Number. It represents Coins.

X or Number are far more confusing. What is X supposed to be? You'd have to look at the assignment itself (if it wasn't declared up front). Never mind what it represents.

Number is a bit better, but you'd still have to look elsewhere to find out what it represents.

Before anyone claims I'm a versed programmer, I'm fairly good at Excel automation with VBA scripting, but that's it.

Reply Parent Score: 3

RE: Comment by lucas_maximus
by Soulbender on Thu 18th Apr 2013 11:19 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

RE: Comment by lucas_maximus
by hhas on Thu 18th Apr 2013 22:47 in reply to "Comment by lucas_maximus"
hhas Member since:
2006-11-28

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


Actually, the fact that NumberOfCoins is declared as an Integer is itself outright misleading: it should actually be a whole number (i.e. an integer with a minimum value of zero and no upper bound) since you can't hold negative coinage in your pocket but in theory could have any number above that (tho' the US Mint and laws of physics might put a practical cap on that eventually).

(Also, I strongly believe any C*/Java developer who bangs on about the vast importance of Integer and Float needs to be locked in a room full of Type theorists and Haskell and Eiffel programmers until they learn what a real type system is.>:)


As for should or shouldn't be 'programming', there are lots of folks in the world who'd recognize the term 'number' or 'whole number' a lot easier than 'integer'. Consider any spreadsheet user, for example: they might be a domain expert in finance and accounting, but they're not what you'd call a 'conventional' programmer by any measure. For them, they don't care what a cell's 'type' is called, only that its contents adhere to their required rules and holds its exact value 100% reliably at all times.

While you're at it, consider the fundamental difficulty, not to mention overt danger, of handing Floating Point types to such users. Especially those that deal with precision-critical tasks like money management, where Very Important Folks like shareholders and IRS might not be so happy to take "just some FP rounding errors" as an excuse.

Frankly the only thing nastier than dealing with numbers in a computer program is dealing with text as (contrary to traditional programmer beliefs:) most of the planet does not speak ASCII, and many of those middle- and far-east scripts are crazy hard to handle correctly, and even quite unexotic ones can have a few nasty tricks up their sleeves.


So, y'know, while it's easy to say "Integer or GTFO", being able to recall what 'integer' means is only a small first step down the actual rabbit hole - and I think even experienced developers may easily overlook just how deep the devil really goes.

Reply Parent Score: 2

Soulbender Member since:
2005-08-18

since you can't hold negative coinage in your pocket


No, but you could be in debt.

Yes, that are things to watch out for with number in programming but none if has any relevance to the dubious claim that NumberOfCoins "hides" anything about the nature of the data it stores.

Reply Parent Score: 2