David Dixon wrote:
The only advice I can really give is be consistent, or you'll just end
up confusing not just yourself, but anyone else who has to look through
your code.
I would recommend that one of the following would be most useful (for
popularity, and understandability):
PascalCase - generally used more for Object/Class declarations
(especially in Java, PHP etc)
camelCase or underscore_style - probably the two most used styles. Used
for creating variables, functions etc
PascalCase is just a variant of camelCase.
http://en.wikipedia.org/wiki/CamelCase
I don't recommend those for use in CSS. CSS is not a programming
language, classes and IDs are not variables. You should be able to
clearly identify classes and IDs used in JavaScript and distinguish them
from javascript variable names. There's little reason to carry a
programming lanaguage convention across to a markup and style languages.
UPPERCASE_UNDERSCORE - prob best to stay clear of this in general usage,
but useful for identifying constants, and globalised variables.
That's definately not recommended for use in CSS because there are no
constants or global variables in CSS.
I would steer clear of the following:
Hungarian Notation - usually seen as oMyObj - using an initial
identifier to show the type of variables ([o]bject, [i]nt, [s]tring
etc), in practice however, it can be very confusing.
Actually, that's Systems Hungarian and it illustrates the abuse that led
to its downfall. The original Hungarian notation (now called Apps
Hungarian) was not intended to indicate the data type, it was meant to
indicate the 'usage type' (i.e. the variables purpose).
http://en.wikipedia.org/wiki/Hungarian_notation
hyphenated-style - similar to underscore_style - unlike the others, this
style is not universal (eg. cannot use in PHP). As css uses this style
for naming its properties, it might seem like a good idea... but avoid
if possible.
No, use this one for classes and IDs because it's the easiest to read
and, unlike most programming languages, there's no restriction of the
use of a hyphen (usually used as the minus operator). Plus using all
lowercase means you nicely avoid case sensitivity issues.
As I said, the main thing to consider is consistency, even within
different languages...
It's important to be consistent, but there's no reason to carry your
PHP, C++, JavaScript or whatever other programming language conventions
across to markup and stylesheet langauges.
adopting a single style for css, javascript, php
etc will make your code much more understandable
That doesn't make sense. Since there aren't yet any variables in CSS,
it doesn't make sense to do so. Classes and IDs are not variables and
shouldn't be treated as such.
It may make sense to use camelCase if and when 'string-set' gets
implemented (from CSS3 Generated Content drafts), because that
effectively is a variable.
e.g.
@page { @top-center { content: string(pageHeader) }}
h1 { string-set: pageHeader "Chapter " counter(chapter) content() }
--
Lachlan Hunt
http://lachy.id.au/
******************************************************
The discussion list for http://webstandardsgroup.org/
See http://webstandardsgroup.org/mail/guidelines.cfm
for some hints on posting to the list & getting help
******************************************************