CodeIgniter Forums
"camelCase" when and where? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: "camelCase" when and where? (/showthread.php?tid=19932)

Pages: 1 2


"camelCase" when and where? - El Forum - 06-23-2009

[eluser]IamPrototype[/eluser]
I'm just curious about the standards in different languages.

* In PHP5 all classes should use underscore and functions should be using underscore as their seperator
* In CSS all elements (such as H1), classes and ids should be written in camelcase

Maybe it doesn't count whether you're using camelcase or not, but I'm really into standards and I want to keep my code clean and friendly.

Right now, in CSS, I'm using an underscore everywhere (elements, ids, classes) and in PHP5 I'm using an underscore for my classes and functions, like this:

Code:
class Class_name
function function_name

But really.. when and where should I use camelcase? According to the standards.


"camelCase" when and where? - El Forum - 06-23-2009

[eluser]TheFuzzy0ne[/eluser]
To which standards do you refer to? I use camelCase for JavaScript and CSS (just IDs and classes) only. Have you read the CodeIgniter PHP Style Guide? http://ellislab.com/codeigniter/user-guide/general/styleguide.html


"camelCase" when and where? - El Forum - 06-23-2009

[eluser]IamPrototype[/eluser]
PHP5, HTML and CSS. I've read the ExpressionEngine coding standards, but I didn't know CodeIgniter had a similar guide in its user guide (I've read the whole user guide, but I didn't see that guide). Thanks Fuzzy, I'll go read it right now.


"camelCase" when and where? - El Forum - 06-23-2009

[eluser]xwero[/eluser]
Standards are just a way to have predictable file, class and method names. CI uses the underscore-as-space standard which i think makes it easier to read but adds characters. Because CI follows that standard the file/class/method loading/calling is tailored for that standard so you better follow it if you don't want 'strange' things to happen.


"camelCase" when and where? - El Forum - 06-23-2009

[eluser]slowgary[/eluser]
None of them are really 'standards', they're more of a style guide to encourage consistency both in your own code and between developers. I have never heard any recommendation to use camelCase in CSS and JavaScript, and I'd prefer not to. I like underscores as they promote readability.

The only benefit camelCase may provide is smaller file sizes (and since CSS and JS are clientside, I see why one would recommend it), although that argument really has no weight, because I could name my CSS class 'column_1' while you could name yours 'leftColumn' and mine would be smaller. Also, a smaller file size is better, but only positively affects download speed when you manage to shave an entire packet off of the client's load. In other words, if the client's connection requires 20 packets to download your CSS file, and you shave 50 bytes off of that file by using camelCase, your client may STILL require 20 packets of data to complete the download. Basically all you did was made your code less readable and saved a few bytes on someone's hard drive (but probably not, because the winblows filesystem has the SAME problem with hard drive cluster size).

Moral of the story: A camelCase is something that belongs in the dessert filled with cold water, not in your source code.


"camelCase" when and where? - El Forum - 06-23-2009

[eluser]TheFuzzy0ne[/eluser]
[quote author="slowgary" date="1245803282"]Moral of the story: A camelCase is something that belongs in the dessert filled with cold water...[/quote]

Or with a camel who's going on holiday.


"camelCase" when and where? - El Forum - 06-23-2009

[eluser]jedd[/eluser]
[quote author="IamPrototype" date="1245767798"]
“camelCase” when and where?[/quote]

Never and nowhere.


"camelCase" when and where? - El Forum - 06-23-2009

[eluser]TheFuzzy0ne[/eluser]
[quote author="jedd" date="1245804549"]Never and nowhere.[/quote]

Did you mean noWhere? Wink


"camelCase" when and where? - El Forum - 06-23-2009

[eluser]Dam1an[/eluser]
I think he meant NowHere Wink

Nice and straight to the point

The only place I use CamelCase is in java at work, as I need to conform to their coding standards


"camelCase" when and where? - El Forum - 06-23-2009

[eluser]jedd[/eluser]
I knowwhat I meant.

Happily, English does not suffer from the same problems of ambiguity due to spacing confusion that, say, languages like Koine are renowned for - primarily because its syntax tends to preclude same, or at the very least allows the writer to preclude the ambiguity (or, bless, generate it intentionally where appropriate).

Even more happily, pretty much every computer language worth its salt copes with underscores in variables, so there's really no excuse.