|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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... |
|
#2
|
||||
|
||||
|
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
__________________
. Spiration channels: Free scripts, programming tutorials and articles Dotcut alerts: Online Press cuttings / news alerts Clearprop: UK microlight school, wiltshire Uk dating: UK safe dating with Topdates About Christo . . |
|
#3
|
|||
|
|||
|
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:
doesn't that make it hard to read for something like getmysqldata? |
|
#4
|
||||
|
||||
|
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
__________________
~~ 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 ) |
|
#5
|
||||
|
||||
|
Quote:
exactly christo |
|
#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.. |
|
#7
|
|||
|
|||
|
Quote:
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:
|
|
#8
|
|||
|
|||
|
I adhere to Microsoft VB standards. They haven't failed me so far...
http://support.microsoft.com/kb/q110264/
|
|
#9
|
|||
|
|||
|
I use the Hungarian Notation on my variables and the K & R for my code structure.
|
![]() |
| Viewing: Dev Shed Forums > Web Site Management > Scripts > Variable naming conventions?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|