Everything2
Near Matches
Ignore Exact
Full Text
Everything2

Use meaningful variable names

created by memra

(idea) by memra (7.1 y) (print)   ?   (I like it!) Sat Nov 13 1999 at 9:00:15

Make your variable names meaningful. Don't use abortions like Hungarian notation. Avoid obscure abbreviations and when you do use them use standard consistent abbreviations so that everyone can understand your code.

Bad code: for(i=0;i < j;i++){ /*stuff*/}

Good code: for (ThisBox=0; ThisBox < TotalNumBoxes;ThisBox++){ /*stuff*/}


(idea) by Eos (1.4 y) (print)   ?   (I like it!) Fri Jun 14 2002 at 11:32:34

Well, it's all well and good to eschew Hungarian notation if you're developing on some flavor of Unix, or other non-MS OS (and good for you, I might add,) but if you do develop applications for Windows you're going to be forced to use Hungarian notation just to interface with the SDKs. And in this case, using standard and consistent abbreviations means using Hungarian notation, unless you want your code to look schizophrenic. With only a minor amount of acclimatization, Hungarian notation is much less intimidating and confusing. But writing a node about meaningful variable names that blasts Hungarian notation is a little bizarre. For example, given the following variables:

  • ThisBox
  • iThisBox
The second one is immediately recognizable as an integer value, wherever it is found, while you'll have to go to the variable definition for ThisBox if you ever forget. Maybe a better way to put this would be, use meaningful variable names that are consistent in style and composition with the rest of your code. This brings us to coding style. Please try to adapt your coding style to that of the other programmers/source code you are working with, or things get much more confusing. Conventions such as "all variables start with lower case letters" or "prefix all member variables with m_" become horribly confusing if used haphazardly throughout the code. Staying with conventions already established or agreed upon makes your variable names much more meaningful.

As a side note, the usefullness of Hungarian notation has diminished in this modern age of tolerable IDE's. It's not uncommon to be able to find the type of any kind of variable just by hovering the mouse over it. However, this doesn't reduce the importance of consistency, and it won't help you if you are looking over a printout of the code.


printable version
chaos

Hungarian notation "i" is a meaningful variable name reverse Polish notation feh
Linux Kernel Coding Style Kids' opinions: How does someone learn to kiss? "Manos" the Hands of Fate POSIX_ME_HARDER
In the privacy of your own home How to test if a ray intersects with a sphere What I do with my philosophy degree Under normal circumstances, the Jewish community does not seek converts
bitch Ransom Love Why "x"? I
printf() debugging Everything cheat codes How to do a mouseover Trace
SDK Acclimatization FreeBSD Freeman Dyson
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Just another sprinkling of indeterminacy
Fifteen minutes 'til Kyrie
Croque monsieur
Bag of Crushed Child
Charlie Chaplin
Tenskwautawa
Carnal Harvest
Staring down babies
Diary of a Cereal Killer
Holy Shit! You must die to preserve life on Earth as we know it!
Granny shot
Elizabeth I
Beastie Boys
Fake words and broken definitions in dictionaries
New Writeups
SwimmingMonkey
Conversations with Fo Fo- the Loneliest dog in Purgatory(fiction)
locke baron
lynx(thing)
Simulacron3
Reality, Dimensions and the Natural Ontology(essay)
SubSane
Making Love to a 9-Foot Woman(person)
Ouzo
Thoughts(idea)
antigravpussy
I fall silent, listening. The breadcrumbs are talking about us(person)
calgon
Buffalo Bill by the pool(poetry)
gate
Anarchy is Order(idea)
ushdfgakjasgh
Scribeling(thing)
XWiz
Trism(review)
artman2003
Briefcase Full of Souls - Part I(fiction)
Dreamvirus
Alan Ladd(person)
waverider37
Harold Holt(person)
The Debutante
Until death do us part(fiction)
Ysardo
a brother to a sister(personal)
This page courtesy of The Everything Development Company