Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb Site ManagementScripts

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old February 12th, 2004, 10:43 PM
lunatic lunatic is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 150 lunatic User rank is Private First Class (20 - 50 Reputation Level)lunatic User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 3 h 50 m 39 sec
Reputation Power: 6
Variable naming conventions??

Heys guys,

I know this is totally personal preference, but I just want to see all the different naming style people use for coding scripts. I find myself changing styles from time to time. At first I tired to get a one worded variable like:

$pic

Then I realize without comments it's useless some time later. So I changed to

$replacepicpath

This got messy and hard to read. But now I tend to switch between these

$oldPicPath
$new_pic_path

I like the 2nd one better - easier to read but man you gotta reach for that underscore key. I've seen some people's code where their variables are just letters basically $xy or $rre. Feel bad for the next coder who has to decipher this...

Reply With Quote
  #2  
Old February 14th, 2004, 03:09 PM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,296 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 4 m 36 sec
Reputation Power: 101
Send a message via ICQ to christo Send a message via Yahoo to christo
my personal preference is to always use descriptive names in ALL lower case with NO underscores.. that way I don't find myself having to guess whether I might have not used a capital letter or a '_' somewhere.. I just do everything in exactly the same way. I did used to code C in Hungarian notation, and very occasionally still do if I think it helps to clarify my datatyping, however these days I mostly use weakly-typed languages, so those habits have waned somewhat.

The one place where I draw an exception to the above rule is when coding in Java.. Because there are such strong conventions for capitalising in class and method names throughout the Java API, I do my best to adhere to those convensions when defining my own classes - otherwise the finished sources are just a muddled mess of different styles.

christo

Reply With Quote
  #3  
Old February 15th, 2004, 12:32 AM
lunatic lunatic is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 150 lunatic User rank is Private First Class (20 - 50 Reputation Level)lunatic User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 3 h 50 m 39 sec
Reputation Power: 6
I think I've miscommunicated here. I understand what you're saying, christo, about using the same naming convention throughout the entire script. When I said that I change my style from time to time, it's from script to script. I'll code one web app using one style and another web app using another.

Quote:
use descriptive names in ALL lower case with NO underscores

doesn't that make it hard to read for something like getmysqldata?

Reply With Quote
  #4  
Old February 16th, 2004, 01:21 PM
codergeek42's Avatar
codergeek42 codergeek42 is offline
少しな日本語とスペイン語と英語を話します。
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jul 2003
Location: Anaheim, CA (USA)
Posts: 6,415 codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)codergeek42 User rank is General (90000 - 100000 Reputation Level)  Folding Points: 35702 Folding Title: Starter FolderFolding Points: 35702 Folding Title: Starter Folder
Time spent in forums: 1 Month 1 Week 6 Days 2 h 29 m 21 sec
Reputation Power: 968
Send a message via ICQ to codergeek42 Send a message via AIM to codergeek42 Send a message via Yahoo to codergeek42 Send a message via Google Talk to codergeek42
Yes, but imho, it makes it easier to remember the varibale name. You don't have to worry about how you originally typed it:
Code:
GetMySQLData
getMySqlData
getMySQLData
getmySQLData
etc...
__________________
~~ Peter ~~
( My Blog: It's exactly like normal nerdiness, but completely different. ) :: ( Supporter of the EFF & FSF ) :: ( I'm a GNU/Linux addict and Free Software Advocate. ) :: ( How to Ask Questions the Smart Way ) :: ( The Fedora Project, sponsored by Red Hat ) :: ( GNOME: The Free Software Desktop Project ) :: ( GnuPG Public Key )

Reply With Quote
  #5  
Old February 16th, 2004, 02:03 PM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,296 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 4 m 36 sec
Reputation Power: 101
Send a message via ICQ to christo Send a message via Yahoo to christo
Quote:
Originally Posted by php4geek
Yes, but imho, it makes it easier to remember the varibale name. You don't have to worry about how you originally typed it


exactly


christo

Reply With Quote
  #6  
Old February 16th, 2004, 07:24 PM
lunatic lunatic is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 150 lunatic User rank is Private First Class (20 - 50 Reputation Level)lunatic User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 3 h 50 m 39 sec
Reputation Power: 6
Again, I understand the concept of using the same naming convention throughout. Over time I have notice that I change my style of writing variable names. At the current time I create my variables with partial descriptions and with spaces such as:

cust_name_ar

which states customer name array. where as before I would have witten something like this

name

Looking at other programmer's styles makes me question mine. I see captials for every word (CustNameArray). I've seen one long name (custnamearray), and I've seen the above spaced with "_". I've also seen sometimes that programmers will do this 'cna'. which means nothing without comments.

IMHO:
custnamearray - too messy, hard to read, easy to type.
CustNameArray - distinguishable names, can be hard to read, not so easy to type.
cust_name_array - sort of neat, easy to read, hard to type.

If anything I would go with CustNameArray. Question is what's your style and why?

Thanks for responding..

Reply With Quote
  #7  
Old June 8th, 2004, 11:50 AM
BrunoUsesBBEdit BrunoUsesBBEdit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Atlanta, GA
Posts: 2 BrunoUsesBBEdit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 30 sec
Reputation Power: 0
Thumbs up

Quote:
Originally Posted by lunatic
IMHO:
custnamearray - too messy, hard to read, easy to type.
CustNameArray - distinguishable names, can be hard to read, not so easy to type.
cust_name_array - sort of neat, easy to read, hard to type.

If anything I would go with CustNameArray. Question is what's your style and why?


I agree on all points. But as Neal Boortz always says "if two people agree on everything, one of them isn't necessary" so I will add, or should I say prepend, to your convention.

Instead of saying CustNameArray or CustNameString, I say aCustName and sCustName.

I use studlyCaps for functions and variables. And I prepend all variable names with an i,n,b,h,s,a,o,f to denote that the variable is type integer (obligatory integer), number (possibly floating point), bool, hex, string, array, object, or file handle resource.

This convention is easily adapted by all of my hired contractors, and makes guess work completely unnecessary regardless of who wrote the code.

One additional thing to note is that even things that would normally be all caps gets converted. ie: $sHtmlBlock and parseMysqlWhereClause()

But the result is very easy to read and understand:
PHP Code:
foreach ($aSqlResults as $i => $sSqlResult) {
    
$aCustomers[$i]['sRep'] = $sSqlResult;


Reply With Quote
  #8  
Old October 13th, 2004, 10:13 AM
Kamoku_Wan Kamoku_Wan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 Kamoku_Wan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I adhere to Microsoft VB standards. They haven't failed me so far...

http://support.microsoft.com/kb/q110264/

Reply With Quote
  #9  
Old October 14th, 2004, 02:06 AM
2slick 2slick is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 57 2slick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 55 m 57 sec
Reputation Power: 5
Send a message via ICQ to 2slick Send a message via MSN to 2slick
I use the Hungarian Notation on my variables and the K & R for my code structure.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb Site ManagementScripts > Variable naming conventions??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway