Click to See Complete Forum and Search --> : camelCase or under_scores?
sneakyimp
08-16-2007, 12:54 PM
Does anyone have a strong preference in their coding style? In their file naming conventions? Do you have a good reason for your preference?
Most of the Javascript I've seen has been camelCase. PHP has been mixed from what I've seen. Can anyone make a good case for which one is better suited to PHP?
stolzyboy
08-16-2007, 01:40 PM
$i_like_underscores regardless of the language i'm using, it could be php, asp, .net, perl, js, html, css, etc....
sneakyimp
08-16-2007, 01:48 PM
Given that the linux filesystem is case-sensitive, I'm partial to underscores in my PHP. If you miss one capitalization in a filename, you get 404!
In Actionscript, most examples and tutorials use camelCase.
laserlight
08-16-2007, 01:52 PM
If no coding standard is specified, I use a style that mixes the two depending on context. Namely, I use underscores to separate words in variable names and defined constants (variable names all lower case, constants all upper case), but I use camel case to separate words in function and class names (function names begin with a lowercase letter, class names are capitalised).
I avoid camel case for filenames in view that filenames may be case insensitive on some systems, and thus I use underscores as word separators for filenames. However, if some suffix (typically a date or number) is added to the filename, I would use a dash as a separator for that.
I do not think that there is a case to be made to say that one of them is better suited to name identifiers in PHP, or in Javascript, or any other programming language for which such naming is relevant. It tends to be just a matter of style. Consistency is the important thing.
sneakyimp
08-16-2007, 02:16 PM
That sounds a lot like what I do in PHP...only I use underscores for functions too.
I am currently working on a hybrid PHP/Actionscript project and am tasked with establishing a coding standard. I was leaning toward my usual habits for PHP but thinking about a more camelCase approach for the Actionscript both to keep with Actionscript culture and also to distinguish the AS from the PHP for the sake of clarity.
But then I started thinking maybe that's too complicated?
laserlight
08-16-2007, 02:38 PM
I am currently working on a hybrid PHP/Actionscript project and am tasked with establishing a coding standard. I was leaning toward my usual habits for PHP but thinking about a more camelCase approach for the Actionscript both to keep with Actionscript culture and also to distinguish the AS from the PHP for the sake of clarity.
But then I started thinking maybe that's too complicated?
You have defensible reasons: keep to Actionscript convention and distinguish Actionscript code from PHP for the sake of clarity. I do not think that it will be too complicated.
On the other hand, if the Actionscript and PHP code are not interspersed, then the only reason you have to to keep with convention. If this convention is not particularly prevalent, then the choice becomes very much arbitrary.
dougal85
08-16-2007, 03:34 PM
I just use camelCase for everything... it just seems to make sense to me...
NogDog
08-16-2007, 10:56 PM
I use camel-case for variables, functions, classes, and methods. I use underscores for constants (since I use all upper-case for them) and for file names. I guess I find camel-case a bit quicker to type and it saves a little space. Also, it looks cooler. :)
sneakyimp
08-17-2007, 01:03 AM
It does look pretty snappy...especially in some contemporary non-serifed font.
ctsiow
08-17-2007, 04:52 AM
I am learning Java so camelCase is good for me. Only_use_underscores for filenames really
piersk
08-17-2007, 05:43 AM
We use underscore here at work, but I've always used camelCase for my stuff so it's kinda hard to break the habit
bpat1434
08-17-2007, 07:26 PM
I mix it all together. Typically I use underscores in variables and camelcase in functions. I do it to mainly tell almost immediately whether it's a function or a variable.
I replace spaces with hyphens in file-names, but separate logical portions by underscores. For example, my mp3 collection is nothing more than: artist-name_track-title.mp3. If I have more info (like album, or year, or track number) I separate with underscore, and clump with hyphen. Just makes more sense to me. Plus, it's very easy to run a quick regex against that ;)
But as far as coding goes, find something that works, and stick with it. If you're asked to switch, learn the new system.
suntra
08-17-2007, 11:42 PM
I use a mix of camelCase and underscores... the very beginning of a variable is its type, usually "int" or "str", while the beginning of a function will be the actions it does (often "return")... , then the first word uses camelCase, and if there are other words, they will be separated by underscores and will use camelCase... example : $strFirst_Name, returnValidate_Something()...
Weedpacket
08-18-2007, 10:55 AM
It does look pretty snappy...especially in some contemporary non-serifed font.Vera Sans Mono; and I don't mind taking it down to 7pt for all the hinting to properly kick in.
[the whole thing]This is satire, right? :glare:
jazz_snob
08-18-2007, 02:44 PM
useUnderScoresItsEasierToRead
That said, I mix them in my own coding:
class names: camels, start w/ a capital letter
functions and variables: underscores and never start w/ a captal letter
A_CONSTANT <- if its gonna be uppercase there isn't really a choice
file name: underscores
Other things I tend to do:
braces go here {, not underneath
use spaces (qty:4), not tabs to indent
single line comments use a #
multiline comments use /* */ unless it commenting a function, class, var, etc in which case I use
/**
* javadoc style comments
* @return void
*/
So if you actually read this far, now I provide a gem for you to see, in case you've never been to this page:http://mindprod.com/jgloss/unmain.html
Try this one (http://mindprod.com/jgloss/unmainnaming.html).
PHP Builder
Copyright WebMediaBrands Inc. All Rights Reserved.