- This topic is empty.
-
AuthorPosts
-
February 21, 2014 at 11:15 am #163656
nixnerd
ParticipantHow do you name your classes? Like this:
.classOne
or like this:
.class_one
I prefer camelCase.
February 21, 2014 at 12:43 pm #163671Senff
ParticipantNeither.
.class-one
February 21, 2014 at 12:46 pm #163673mcjohnst
ParticipantFollow the conventions of the language
CSS
.my-class
PHP
$my_var = ”;
JS
var myVar = ”;February 21, 2014 at 1:26 pm #163681nixnerd
ParticipantI’m fully aware that this is superficial… but I’ve always DETESTED the copious amounts of underscores in PHP. It literally hurts my eyes to stare at a bunch of PHP.
The hyphens are ok but sometimes they visually start to blend in with properties. I understand that this is what syntax highlighting and indentation is for but I like to see a really clear difference. Especially when I look at my code on Github or in a terminal where there is no syntax highlighting. It’s really nice to have the visual breakup.
February 21, 2014 at 1:39 pm #163684Alen
ParticipantI’m trying to find a great article about how we read. will find it eventually…
Anyways, it basically said that we read or skip at the top of the letters… I’m probably butchering the explanation. If you were to take a line of text and cut it in half horizontally you would still be able to read it…
So this_would_be_most_legible… But I do agree that you should follow conventions mentioned by @mcjohnst
February 21, 2014 at 2:06 pm #163691nixnerd
ParticipantIt couldn’t be this:
http://whathecode.wordpress.com/2011/02/10/camelcase-vs-underscores-scientific-showdown/
This one actually sides with Camel Case to some degree:
Considering all four hypotheses together, it becomes evident that the camel case style leads to better all around performance once a subject is trained on this style. Training is required to quickly recognize such an identifier.
Anyway, I was just curious on what people use.
February 21, 2014 at 2:06 pm #163692nixnerd
ParticipantI think it’s ironic that my handle has an underscore and I hate them… just another reason to change it. :)
February 21, 2014 at 2:08 pm #163693nixnerd
ParticipantNext we should talk about 2 vs. 4 spaces.
February 21, 2014 at 2:48 pm #163701__
ParticipantI use both, to an extent, plus some others.
- I use camelCase in most situations. I find it easiest to read and write.
- I use under_scores in cases where there is a logical separation between groups of words: for example,
getLocale_byLanguage
andgetLocale_byRegion
clearly do the same thing, and the difference between the two methods is also obvious. Likewise, I might have anHTTPResponse_HTML
class, and anHTTPResponse_JSON
class, etc..
I know your question is about CSS classes, but I tend to use the same logic for my naming conventions everywhere. The one I haven’t shaken (yet) is using basically all caps for SQL. I hate that, but it’s a very strong habit.
Some other conventions I follow:
- As in many frameworks (across languages), _leadingUnderscores denote non-public properties or methods.
- I use TitleCase for the names of concrete classes.
- I use ALL_CAPS for global constants (though I buck the status quo and use TitleCase for class constants).
Next we should talk about 2 vs. 4 spaces.
there is nothing to talk about.
February 21, 2014 at 3:03 pm #163704nixnerd
Participantthere is nothing to talk about.
I prefer 4… just saying.
February 21, 2014 at 3:49 pm #163711__
ParticipantI prefer 4… just saying.
I like how you never even acknowledged that there might be a choice between “tabs” and “spaces.” : )
February 21, 2014 at 4:34 pm #163712nixnerd
ParticipantI was going to acknowledge it but I didn’t want it to get contentious. This is holy war territory!
Truth be told… I use tabs so I can type less. I know some people say you’re not supposed to because if you send the file or use a different text editor, spacing can get messed up, blah blah blah.
I set Sublime Text 2 tab width to 4 spaces and never think about it again.
February 21, 2014 at 5:11 pm #163713__
ParticipantAbsolutely right – I use the tab key, but there are no tab characters in my script.
February 21, 2014 at 6:12 pm #163714Alen
ParticipantI use Tab as well, only 2 spaces tho… I set my padding top/bottom so it all reads very nicely…
February 21, 2014 at 9:36 pm #163716nixnerd
ParticipantI use the tab key, but there are no tab characters in my script.
Same here. Sublime Text 2 interprets the tabs to make them spaces.
I’m still thinking about learning Vim. I’ve got it installed.
-
AuthorPosts
- The forum ‘Other’ is closed to new topics and replies.