Click here to Skip to main content
15,879,474 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Names Pin
grralph122-Apr-21 4:15
grralph122-Apr-21 4:15 
GeneralRe: Names Pin
Jörgen Andersson22-Apr-21 3:39
professionalJörgen Andersson22-Apr-21 3:39 
GeneralRe: Names Pin
grralph122-Apr-21 4:22
grralph122-Apr-21 4:22 
GeneralRe: Names Pin
User 991608022-Apr-21 4:36
professionalUser 991608022-Apr-21 4:36 
GeneralRe: Names Pin
grralph122-Apr-21 5:25
grralph122-Apr-21 5:25 
GeneralRe: Names Pin
honey the codewitch22-Apr-21 5:44
mvahoney the codewitch22-Apr-21 5:44 
GeneralRe: Names Pin
grralph122-Apr-21 14:05
grralph122-Apr-21 14:05 
GeneralRe: Names Pin
Mike Winiberg22-Apr-21 21:21
professionalMike Winiberg22-Apr-21 21:21 
This discussion is quite fascinating. Back in my youth (when dinosaurs roamed the earth), languages restricted both length of variable names and enforced type based on initial (or even only!) letters.

So, I to N would be integer, everything else floating point. This is, I believe the origin of the common use of i,j,k for integer loop variables etc, and x,y,z (also algebraic) for common floats.

Someone I once employed would have complex calculations etc using variables like x, xx, xxx, xxxx and y,yy,yyy,yyyy etc - write only code if ever there was any.

The advent of unrestricted variable names led to the opposite extreme, where variable (and function) names became so long and complex

eg:

doubleCalculateOffsetForWaveFunction(intScaleFactorForWaveFunction,floatWaveFunctionSeedValue)
doubleCalculateOffsetForInverseWaveFunction(intScaleFactorForWaveFunction,floatWaveFunctionSeedValue)

with variations on camelCase, "_" separators etc) that code became tedious to type correctly and especially to refactor before the rise of the modern IDE; impossible to read and understand because of the effort needed to parse the variable names, especially when lots were very similar in structure etc etc.

(How would you know from reading the two declarations above whether the parameters were the correct variables eg: you might indeed want to use the same seeds here, or it might need different ones, so why not just use 'seed' etc)

BUT, you have to beware of making anything other than throwaway variable names too specific to the algorithm rather than their usage - because this can make them ambiguous or misleading in meaning:

does 'intUserValue' indicate something entered by the user, some property of the user, the user's value to the organisation etc

Making up variable names can be one of the hardest parts of coding something especially if one coding house uses identical names differently to another. I recently dug myself into a hole migrating a business app from SAGE accounts to XERO, because in SAGE anything (Nominal ledger entries, customers, suppliers etc) can be in an 'account'. In XERO only nominal items go in 'accounts', customers go in 'contacts'. I only discovered this when I tried to post a customer invoice and found that I couldn't assign it to an 'account', only to a 'contact'.

Then there are the times when you use a library function return value in-line, there's a bug, and even your modern sophisticated IDE has no way to inspect the return value without dropping right down to assembler level code inspection - so you put the result into a variable which the compiler then helpfully removes again during optimisation so you still can't debug it easily.

After many years, I have come to the conclusion that KISS applies as much to variable naming as to code itself: Also if you are dyslexic, long variable names can be incredibly difficult to cope with too.

So, as simple as possible, don't bother with describing the type in the name (except possibly in languages that don't have or enforce types, and even then limit yourself to single letters if possible eg iRetVal, not integerRetVal).

Simple variable/function names along with careful, concise comments can make all the difference!

You have heard of comments, haven't you? 8)
GeneralRe: Names Pin
grralph122-Apr-21 23:56
grralph122-Apr-21 23:56 
GeneralRe: Names Pin
honey the codewitch23-Apr-21 2:01
mvahoney the codewitch23-Apr-21 2:01 
GeneralRe: Names Pin
Stefan_Lang2-May-21 3:02
Stefan_Lang2-May-21 3:02 
GeneralRe: Names Pin
Mike Winiberg2-May-21 5:32
professionalMike Winiberg2-May-21 5:32 
GeneralRe: Names Pin
Stefan_Lang4-May-21 1:41
Stefan_Lang4-May-21 1:41 
GeneralRe: Names Pin
Mike Winiberg4-May-21 5:12
professionalMike Winiberg4-May-21 5:12 
GeneralRe: Names Pin
Stefan_Lang4-May-21 8:48
Stefan_Lang4-May-21 8:48 
GeneralRe: Names Pin
Mike Winiberg4-May-21 10:38
professionalMike Winiberg4-May-21 10:38 
GeneralRe: Names Pin
Mike Winiberg4-May-21 11:11
professionalMike Winiberg4-May-21 11:11 
GeneralRe: Names Pin
Sander Rossel22-Apr-21 9:24
professionalSander Rossel22-Apr-21 9:24 
GeneralRe: Names Pin
grralph122-Apr-21 14:04
grralph122-Apr-21 14:04 
GeneralRe: Names Pin
Wizard of Sleeves22-Apr-21 20:52
Wizard of Sleeves22-Apr-21 20:52 
GeneralRe: Names Pin
grralph123-Apr-21 0:28
grralph123-Apr-21 0:28 
GeneralRe: Names Pin
Stefan_Lang2-May-21 3:17
Stefan_Lang2-May-21 3:17 
GeneralRe: Names Pin
Daniel Will22-Apr-21 21:22
Daniel Will22-Apr-21 21:22 
GeneralRe: Names Pin
grralph122-Apr-21 23:59
grralph122-Apr-21 23:59 
GeneralRe: Names Pin
Member 1068017923-Apr-21 2:56
Member 1068017923-Apr-21 2:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.