Thoughts from Dan Miser RSS 2.0
 Friday, January 28, 2005
I came across this post today, talking about names as viewed from an intercultural perspective. It was a good read, but it triggered something in me that I knew I had to blog about, namely a quote that bites me time and again: "Writing the code is easy. Naming it properly is hard.".

I'd say this problem is pervasive, based on my experience. How many times have you seen code that does "for i:=0 to Count-1 do"? OK, maybe that's a stretch. Counter variables don't exactly require great names. But still, the point remains. Badly named variables, methods, components, etc. are very common. I find that when this happens in my code, it's due to a failure in my understanding of exactly what the code is meant to do. In the old days, you just had to change things around until they make sense. Today, it's called Refactoring. :-)

My advice is that when you find yourself starting to have to do mental gymnastics to keep track of what a variable/method/etc. is used for, it's time to immediately change either the purpose or name of the variable (or both). It may be a minor inconvenience now, but it will pay major dividends the next time that code is looked at.

Friday, January 28, 2005 1:30:00 PM (Central Standard Time, UTC-06:00)  #    Comments [3] -

Tracked by:
http://9nc-information.info/98237255/index.html [Pingback]
http://9nr-information.info/57359221/house-of-champagne.html [Pingback]
http://9ns-information.info/65219429/index.html [Pingback]
http://9nj-information.info/10145168/business-bank-of-skagit-counyt.html [Pingback]
http://9nr-information.info/43362073/denver-zoo-lights.html [Pingback]
http://9ng-information.info/33262724/index.html [Pingback]
http://9ns-information.info/48513696/creating-book-reports.html [Pingback]
http://9nt-information.info/43865688/index.html [Pingback]
http://9nt-information.info/71436764/index.html [Pingback]
http://9ny-information.info/93823286/index.html [Pingback]
http://9qk-information.info/79507873/presidente-ai-tempo-rivoluzione-cubana.html [Pingback]
http://9os-information.info/90210263/index.html [Pingback]
http://9qf-information.info/87438849/toshiba-p30-129.html [Pingback]
http://9os-information.info/16625695/sony-dvd-recorder-rdr-gx300-inputs.html [Pingback]
http://9om-information.info/05230485/index.html [Pingback]
http://9ov-information.info/74572862/index.html [Pingback]
http://9rq-information.info/72383976/the-royal-paridise-hotel-in-phuket.html [Pingback]
http://9rb-information.info/67959985/taos-ski-valley-summer-new-mexico-vacation.... [Pingback]
http://9re-information.info/20686192/index.html [Pingback]
http://9rw-information.info/26774665/index.html [Pingback]
http://9sm-information.info/87528860/index.html [Pingback]
http://9uafk-le-informazioni.info/57147456/codice-gratis-the-sim-2-pet.html [Pingback]
http://9uafe-le-informazioni.info/19178532/larry-sims-boxe.html [Pingback]
http://9uafb-le-informazioni.info/73501546/index.html [Pingback]
http://9uafh-le-informazioni.info/90341285/index.html [Pingback]
http://9uafe-le-informazioni.info/37987069/index.html [Pingback]
http://9uafb-le-informazioni.info/34098319/index.html [Pingback]
http://9uael-le-informazioni.info/36261645/offerta-speciale-chianciano-terme.htm... [Pingback]
http://9uafk-le-informazioni.info/76186030/index.html [Pingback]
http://9uaef-le-informazioni.info/49482065/download-kaspersky-in-italiano.html [Pingback]
http://9uagp-le-informazioni.info/41947164/index.html [Pingback]
http://9uagf-le-informazioni.info/28371828/hddfor-evox.html [Pingback]
http://9uahf-le-informazioni.info/96300446/index.html [Pingback]
http://9uagr-le-informazioni.info/86789666/index.html [Pingback]
http://9uahp-le-informazioni.info/78199928/arte-design-architettura-storia.html [Pingback]
http://9uagc-le-informazioni.info/36216826/mito-caverna-platone.html [Pingback]
http://9uagk-le-informazioni.info/50198511/werner-von-strasse-n-14-hersbruck.htm... [Pingback]
http://9uagc-le-informazioni.info/24832907/index.html [Pingback]
Friday, January 28, 2005 2:27:00 PM (Central Standard Time, UTC-06:00)
I prefer



for i := 0 to 4 do



as opposed to



for iMyLoopVarForPrintingNumbers := 0 to 4 do



which would look like



arrMyNumbers[ iMyLoopVarForPrintingNumbers ] := 44;



as opposed to



arrMyNumbers[ i ] := 44;



If you fully comment a section of code, indicate what the loops represent, is it really necessary to make it more complicated than it is?



Mind you, I don't care for variables with a single character as the name AND no comments as to what it represents.

Friday, January 28, 2005 2:44:00 PM (Central Standard Time, UTC-06:00)
Well, yeah. That's why I said "Counter variables don't exactly require great names". :-)



Single character vars for loops is ok, in my book. As long as the loops make sense reading them that way. Sometimes the loop is nested, and maybe then the vars could be expanded to denote which slice you are working on.

Friday, January 28, 2005 2:51:00 PM (Central Standard Time, UTC-06:00)
I think this code is much easier to understand :



for aRowIndex := 1 to 10 do

begin

for aColIndex := 1 to 10 do

begin

FMatrix [aRowIndex][aColIndex] := ....;

end;

end;



than the "generic" :



for i := 1 to 10 do

for j := 1 to 10 do



P.S. And no hungarian notations too :) !
Rossen Assenov
Comments are closed.
Navigation
Archive
<July 2008>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Dan Miser
Sign In
Statistics
Total Posts: 306
This Year: 21
This Month: 0
This Week: 0
Comments: 603
All Content © 2008, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)