SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 34 of 34
  1. #26
    SitePoint Enthusiast MJ Pieterse's Avatar
    Join Date
    May 2010
    Location
    Fourways, Gauteng, South Africa
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    camelCase

    _____________________

    http://www.megapixeljourneys.com/

  2. #27
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TomTees View Post
    You were adding underscores for hyphenation and breaking up words like "Sitepoint" into two words when it is one, so I don't think my examples were as ambiguous as your made them out.
    Then why did you use SitePoint and Sitepoint as examples when you have just said it is one word?

    Quote Originally Posted by TomTees View Post
    Assuming you know "Sitepoint" is one word, then it can only be "sitepoint_number" using my approach.
    ...and it can only be SitepointNumber using the camelcase approach.

    Quote Originally Posted by TomTees View Post
    By contrast, it could be "Sitepoint" or "SitePoint" since there are a lot of compound words that use mid-word capitalizations (e.g. "NetApp") which leads to confusion above the using Pascal Case.
    There are no compound words that use mid-word capitalisations. Anyone who uses them like this is using them incorrectly. That's the whole point of it being a new compound word, and not separate words!

    Neither approach is any more or less ambiguous than the other.

  3. #28
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    I use a mix of underscores and camelBacks across all my code - that might sound odd, but there's a method to my madness.

    camelBacks I choose as my primary formatting method because it's what javascript uses and suggests using, so I use it across all my code - HTML, CSS, PHP, PERL, etc - so I have one consistent naming convention. All my classes, ID's and functions of the past... six years or so use camelBacks.

    But I also use underscores in a handful of cases, often in COMBINATION with camelBacks. For example a section delimiter in a name - for example if I have two fieldsets with near identical information in the same form, the first one being "your info" and the second one being "spouses info" and both have a 'name' field, I'll prefix the fieldset className before each.

    your_name, spouses_name

    I also often use underscores on classes or ID's when using them as javascript hooks as it lets me divide up the element...

    <span id="sControl_myContent1"></span>
    <div id="myContent1">Some text</div>

    My javascript can then pulls all spans, checks for the sControl_ prefix (substr), attach the onclick handler, fill in some content, and use the end of the ID to target the DIV. Scripting off content is always shown and controls are not, scripting on the control gets added.

    Another example would be a code library. If I have multiple library files I'll use the prefix_ structure to say what library a function is from, while using camelBacks for the actual function name.

    For example:
    Code:
    function common_camelBack($inString) {
    	return lcfirst(str_replace(
    		array(
    			' ',"\n","\t","\r",'&nbsp;'
    		),'',ucwords($inString)
    	));
    }
    
    function common_randomPassword($min=8,$max=12) {
    I then know those functions are stored in /libraries/common.php, just as I would know:

    Code:
    function forms_isValidEmail($address) {
    is in /libraries/forms.php

    Also prevents namespace headaches.

    Really though it just helps me make my code feel cleaner/clearer. Same reason I use XHTML and have burned out tab and enter keys on "Model M" Keyboards. (which if you know what those are, your head just exploded like you were in the same room with Micheal Ironsides)

  4. #29
    SitePoint Addict
    Join Date
    Mar 2005
    Location
    California, US
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Functions are lowerUpper
    Classes are UpperUpper
    Variables are lower with underscore

    I find it easier to read past or long code when I know exactly what is being called by the naming style.

    I also don't shorten words but at the same time I don't use bloated sentences. Instead of 'fitlerByAssociatedCategoryId()' I would write 'filterByCategory()' and make the function parse through either ids or slugs.

  5. #30
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I use lowerUpper for functions and variables (although controversially, I put the type before the name as well, so I actually use $typeUpperUpper for vars)

    UpperUpper for classes as well. I tend to use underscores in mysql field names for some reason.

  6. #31
    SitePoint Addict
    Join Date
    Mar 2005
    Location
    California, US
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do lowercase with underscores for both mysql tables and fields. I think this is just habit from using Symfony as my primary framework for so long.

    I don't think there is really any right or wrong method. As long as you stay consistent so you can read it and another programmer can learn and debug quickly.

  7. #32
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by molona View Post
    Camel case for variables and never underscore... the reason? Underscores are harder to type in my Spanish keyboard...
    Quote Originally Posted by C. Ankerstjerne View Post
    I use underscores as well for everything (and I need the [Shift]+[-] combination as well). It just looks prettier to me, and I don't have to worry about whether a letter is a lower-case L or an upper-case I if using a different computer.
    I do OO so like ScallioXTX, I use camel case with Pascal case in reserve for classes and large scale objects like that. I don't know why, but underscores really bug me. They are a key combo on my American English default key map. I don't like trying to reach anything with my little pinky up there -, =, +. I hate having to backspace out all the errors when I hit the wrong key.

    Though MySQL automatically converts my field names to all lower case. Is there a setting I can change to allow capital letters?
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  8. #33
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Chroniclemaster1 View Post
    Though MySQL automatically converts my field names to all lower case. Is there a setting I can change to allow capital letters?
    Yes, put lower_case_table_names=2 in your my.ini
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  9. #34
    SitePoint Addict dAEk's Avatar
    Join Date
    Oct 2003
    Location
    Stockholm, Sweden
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think PascalCase and camelCase is easier to read compared to other conventions. I prefer PascalCase though.
    David Shamloo-Ekblad

    Go Habs! | For music addicts: Last.fm, SongMeanings


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •