SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 34
  1. #1
    SitePoint Evangelist TomTees's Avatar
    Join Date
    Apr 2010
    Location
    Iowa
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multi-Word Field Names

    What is the best way to separate multi-word field names?

    1.) Pascal case (e.g. "FirstName")

    2.) Camel Case (e.g. "firstName")

    3.) Underscores (e.g. "first_name")

    4.) No Separation (e.g. "firstname")

    5.) Spaces (e.g. "first name") I already know the answer on this one!

    6.) Other??

    I used to prefer Pascal Case, but have grown to see the benefits of underscores - mainly that you never have to worry about remembering where/how you capitalize letters.

    What does everyone else do and think?



    TomTees

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Seeing as I use camelCase for variable names in PHP I also use camelCase for database field names.
    I don't like the PascalNames because to me something that starts with a capital is a class name, whereas something that starts with a lower case is a variable. So, as I use ActiveRecord for PHP and I need to create a PHP class for each table, and I already said I use PascalCase for classes, I use PascalCase for tablenames.
    Somehow I don't like underscores in my databases, but I do use underscores in CSS. Colour me undecided
    The puteverythingtogether approach is fine for short thing like "firstname", but for longer names it just becomes unworkable.
    As for the spaces ... no comment
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

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

  3. #3
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,617
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    As long as you're consistent, it doesn't matter a whole lot.

    The only place where I've seen problems crop up is when you have double letters together--the same letter at the end of a word and the same letter at the start of the next one

    Something like: "saveeverytime".

    It can lead to typos and such.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  4. #4
    SitePoint Evangelist TomTees's Avatar
    Join Date
    Apr 2010
    Location
    Iowa
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does using underscores (e.g. "sale_unit_price") affect performance?

    Can that blow up MySQL (or another non-MS Access database)?



    TomTees

  5. #5
    SitePoint Evangelist TomTees's Avatar
    Join Date
    Apr 2010
    Location
    Iowa
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    Seeing as I use camelCase for variable names in PHP I also use camelCase for database field names.
    I don't like the PascalNames because to me something that starts with a capital is a class name, whereas something that starts with a lower case is a variable.
    Not being an object-oriented developer by nature, I've never had that problem. Although since I hope to make this my first-ever OOP project, that is a good point.

    I used to be big on PascalNames, but someone pointed out that it makes it tougher on other developers who may not know exactly how you change case.

    By using underscores (_), you make it simplier in that it is just all words in lower-case with an _ between words.

    It is slightly more verbose, but I've grown to like it for predictability reasons.


    TomTees

  6. #6
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by TomTees View Post
    Does using underscores (e.g. "sale_unit_price") affect performance?
    Apart from the 3 bytes data traffic (saleUnitPrice is 3 bytes shorter than sale_unit_price) which is completely negligible, I don't see why it should.

    Quote Originally Posted by TomTees View Post
    Can that blow up MySQL (or another non-MS Access database)?
    No
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

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

  7. #7
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by TomTees View Post
    Does using underscores (e.g. "sale_unit_price") affect performance?
    absolutely not

    Quote Originally Posted by TomTees View Post
    Can that blow up MySQL (or another non-MS Access database)?
    none that i know

    my own preference is to use single words for column names whenever possible -- the whole problem just goes away, doesn't it -- but when necessary, an underscore
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  8. #8
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lower case underscores for me. reason? table names can be case sensitive, so I just extend that and always use lower case when dealing with the database. Underscores are just for readability.

  9. #9
    #titanic {float:none} silver trophy
    molona's Avatar
    Join Date
    Feb 2005
    Location
    from Madrid to Heaven
    Posts
    8,268
    Mentioned
    249 Post(s)
    Tagged
    1 Thread(s)
    Camel case for variables and never underscore... the reason? Underscores are harder to type in my Spanish keyboard... unlike English keyboards, typing an underscore is not just hitting a key but a key combination with the shift key. Not much of a problem but I don't see why I need to delay 0.5 secs every time I need to write a multiple word name.

    I try to use single names when possible, of course.

  10. #10
    SitePoint Evangelist TomTees's Avatar
    Join Date
    Apr 2010
    Location
    Iowa
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    my own preference is to use single words for column names whenever possible -- the whole problem just goes away, doesn't it -- but when necessary, an underscore
    So how does that translate for "First Name"?

    fname?

    firstname?

    first?



    TomTees

  11. #11
    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
    I used to prefer Pascal Case, but have grown to see the benefits of underscores - mainly that you never have to worry about remembering where/how you capitalize letters.
    How do you mean? Surely it's a direct translation from one to the other - if you have to remember where/how you capitalise letters, you also have to remember where/how you place underscores!

  12. #12
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by molona View Post
    Underscores are harder to type in my Spanish keyboard... unlike English keyboards, typing an underscore is not just hitting a key but a key combination with the shift key.
    It's a key combo on a UK English keyboard too ... Shift and - (between 0 and = keys) give the _ character.
    Ian Anderson
    www.siteguru.co.uk

  13. #13
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 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... unlike English keyboards, typing an underscore is not just hitting a key but a key combination with the shift key. Not much of a problem but I don't see why I need to delay 0.5 secs every time I need to write a multiple word name.
    And you don't need a key combination to get a capital?
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

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

  14. #14
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by TomTees View Post
    So how does that translate for "First Name"?

    fname?

    firstname?

    first?
    yeah, any of those

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  15. #15
    SitePoint Guru
    Join Date
    Oct 2006
    Location
    Queensland, Australia
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    And you don't need a key combination to get a capital?
    Not if he toggles caps-lock :P

  16. #16
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    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.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  17. #17
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing to have in mind is that if you migrate from Windows to any "Linux"/Unix system (except Mac's unix versions, and maybe some other), or between some Unix versions the databse and table names and their corresponding directories are case sensitive (Win and Mac aren't). And what about moving to other db's? It may not be of any importance today, but could be a consideration for the future!

    If so, a lower case uniformity is probably the best - That is perhaps also important when you write SELECTs or when you program functions, procedures, and triggers? - But my experience with MySQL under "ux"-systems is limitied to basic php-programming without any db's involved.

  18. #18
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    I've used all of the above and then some (I've even tried dashes before).
    My first tables were very simple newbie experiments and single word names worked fine.

    But when I eventualy needed to differentiate I tried adding numbers eg.
    item1
    item2
    item3
    Ugh! Don't do that! It may be OK while the code is fresh in the memory but try figuring out what is what after you've been away for a while.

    Then for a while I used alternately PascalCase camelCase under_score and allthewordsputtogether.
    Ugh again! Don't do that either. Find a way and stick with it.

    I now use lowercase underscore, saves a lot on the mental gymnastics.

  19. #19
    SitePoint Evangelist TomTees's Avatar
    Join Date
    Apr 2010
    Location
    Iowa
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    How do you mean? Surely it's a direct translation from one to the other - if you have to remember where/how you capitalise letters, you also have to remember where/how you place underscores!
    Not really. How about these examples...

    "LogInStatus" vs. "LoginStatus" vs "log_in_status"

    "SiteMapLink" vs SitemapLink" vs "site_map_link"

    "SitePointNumber" vs "SitepointNumber" vs "sitepoint_number"

    "EMailAddress" vs "EmailAddress" vs "email_address"

    "ECommerceLink" vs "EcommerceLink" vs "ecommerce_link"

    and a very common one...

    "ZIPCode" vs "ZipCode vs "Zipcode" vs "zip_code"
    (Did you know that out of the first three Upper/Lower-case choices for zip_code, only one is truly correct? Do you know why?)

    Adding an underscore between words is much less likely to be misinterpreted than using capitalization between words, as seen above.



    TomTees

  20. #20
    Floridiot joebert's Avatar
    Join Date
    Mar 2004
    Location
    Kenneth City, FL
    Posts
    823
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I try to use a single word to describe columns. I like to prevent ambiguous column names by using a second word sometimes though. I use underscores when I do this.

    Rather than the names "id", or "order", I might use "category_id", "image_id", and "insert_order".

  21. #21
    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
    Not really. How about these examples...

    "LogInStatus" vs. "LoginStatus" vs "log_in_status"
    login_status vs log_in_status

    Quote Originally Posted by TomTees View Post
    "SiteMapLink" vs SitemapLink" vs "site_map_link"
    sitemap_link vs site_map_link

    Quote Originally Posted by TomTees View Post
    "SitePointNumber" vs "SitepointNumber" vs "sitepoint_number"
    sitepoint_number vs site_point_number

    Quote Originally Posted by TomTees View Post
    "EMailAddress" vs "EmailAddress" vs "email_address"
    email_address vs e_mail_address

    Quote Originally Posted by TomTees View Post
    "ECommerceLink" vs "EcommerceLink" vs "ecommerce_link"idl
    ecommerce_link vs e_commerce_link

    Quote Originally Posted by TomTees View Post
    "ZIPCode" vs "ZipCode vs "Zipcode" vs "zip_code"
    zip_code vs z_i_p_code

    Admittedly this one is far fetched but if you accept that ZIP is an initialism, both are plausible.

    Quote Originally Posted by TomTees View Post
    Adding an underscore between words is much less likely to be misinterpreted than using capitalization between words, as seen above.
    Rubbish I'm afraid. Wherever there is ambiguity with capital letters, there is ambiguity with underscores. The only example that even had some merit was Zip Code, but I'm pretty sure Zip is one word in that case (despite being an initialism, that is not its common usage), not all capitalised. In any case, I'm not American so it isn't something I have to deal with anyway!

  22. #22
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    I am an American and I had to Google
    Zoning Improvement Plan

    I won't say I'd prefer zoning_improvement_plan_code !

  23. #23
    SitePoint Enthusiast v1rgil's Avatar
    Join Date
    Dec 2008
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    naming fields is actually your preference.
    for me, camel case is good

  24. #24
    SitePoint Evangelist TomTees's Avatar
    Join Date
    Apr 2010
    Location
    Iowa
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    login_status vs log_in_status

    sitemap_link vs site_map_link

    sitepoint_number vs site_point_number

    email_address vs e_mail_address

    ecommerce_link vs e_commerce_link

    zip_code vs z_i_p_code

    Admittedly this one is far fetched but if you accept that ZIP is an initialism, both are plausible.

    Rubbish I'm afraid. Wherever there is ambiguity with capital letters, there is ambiguity with underscores. The only example that even had some merit was Zip Code, but I'm pretty sure Zip is one word in that case (despite being an initialism, that is not its common usage), not all capitalised. In any case, I'm not American so it isn't something I have to deal with anyway!
    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.

    Assuming you know "Sitepoint" is one word, then it can only be "sitepoint_number" using my approach.

    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.

    In the end, you can debate anything.

    I was just explaining why others have told me that using underscores to break up complete words seems less ambiguous.



    TomTees

  25. #25
    SitePoint Evangelist TomTees's Avatar
    Join Date
    Apr 2010
    Location
    Iowa
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    I am an American and I had to Google
    Zoning Improvement Plan

    I won't say I'd prefer zoning_improvement_plan_code !
    Very good, Mittineague. You get the prize!!

    In it's original form, it should be "ZIP code", but in modern American English it can be "ZIP code" or "Zip Code" or "Zipcode" or "Zip".



    TomTees


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
  •