Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other camelCase or under_score?

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #163656
    nixnerd
    Participant

    How do you name your classes? Like this:

    .classOne
    

    or like this:

    .class_one
    

    I prefer camelCase.

    #163671
    Senff
    Participant

    Neither.

    .class-one

    #163673
    mcjohnst
    Participant

    Follow the conventions of the language

    CSS

    .my-class

    PHP

    $my_var = ”;

    JS
    var myVar = ”;

    #163681
    nixnerd
    Participant

    I’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.

    #163684
    Alen
    Participant

    I’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

    #163691
    nixnerd
    Participant

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

    #163692
    nixnerd
    Participant

    I think it’s ironic that my handle has an underscore and I hate them… just another reason to change it. :)

    #163693
    nixnerd
    Participant

    Next we should talk about 2 vs. 4 spaces.

    #163701
    __
    Participant

    I 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 and getLocale_byRegion clearly do the same thing, and the difference between the two methods is also obvious. Likewise, I might have an HTTPResponse_HTML class, and an HTTPResponse_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.

    #163704
    nixnerd
    Participant

    there is nothing to talk about.

    I prefer 4… just saying.

    #163711
    __
    Participant

    I prefer 4… just saying.

    I like how you never even acknowledged that there might be a choice between “tabs” and “spaces.” : )

    #163712
    nixnerd
    Participant

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

    #163713
    __
    Participant

    Absolutely right – I use the tab key, but there are no tab characters in my script.

    #163714
    Alen
    Participant

    I use Tab as well, only 2 spaces tho… I set my padding top/bottom so it all reads very nicely…

    #163716
    nixnerd
    Participant

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

Viewing 15 posts - 1 through 15 (of 15 total)
  • The forum ‘Other’ is closed to new topics and replies.