Welcome Guest, Not a member yet? Register   Sign In
"camelCase" when and where?

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:

class Class_name
function function_name

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

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-gui...guide.html

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.

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.

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.

[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.

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

Never and nowhere.

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

Did you mean noWhere? Wink

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

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.

Theme © iAndrew 2016 - Forum software by © MyBB