+ Reply to Thread
Results 1 to 3 of 3

Thread: More Coding Methods

  1. #1
    Programmer RobSoftware is an unknown quantity at this point
    Join Date
    Nov 2005
    Posts
    143

    More Coding Methods

    From the other thread in this forum we got "The One True Brace" as a brace style and another type (I forget the name of that one). What about variables? I name my variables by capping the second word and each word after that such as:

    $myVariable
    int myVariable
    int myVeryLongVariable

    I notice people often use different styles or in really bad coding, no styles.

    I often see all words capped.
    $MyVariable
    int MyVariable

    and in bad coding
    myVariable
    int MyVeryLongVariable (notice the first word isn't capped and then capped?)

    My question is: What are these styles called and which do you use? Is there a correct way because I've taken several programming classes and read even more books. Each teacher/author will have a different style.

  2. #2
    Programmer brackett is on a distinguished road
    Join Date
    May 2006
    Posts
    193
    IME, the first style is called camelCase, and the second PascalCase. Note that this Wikipedia article, however, says they are both camel case and should be called lowerCamelCase or UpperCamelCase (edit: that used to say UpperPascalCase, which is wrong...oops). I say I've never heard of such terms - but do realize that wiki engines in general call PascalCase camelCase. I submit the .NET Framework Design Guidelines on Capitalization in my defense.

    For .NET, Microsoft has the above design guideline for the BCL. I'm sure Java has something similar. It's probably advisable to follow those guidelines, so here's the relevant portions of the .NET one:
    a. camelCase for parameters, local and (non public) member variables
    b. PascalCase for classes, enum types and values, properties, functions, events, readonly statics, public member variables, interfaces, namespaces, and acronyms more than 2 letters long
    c. no Hungarian notation
    d. no prefix for member variables (I'm not entirely sure this is in there, I know it recommends against underscores for class names, but others have stated it does as well for member variables. I do know, however, that you cannot be CLS compliant with an underscore prefix)

    And, now that I have given the "official" recommendation, here's how I actually do it for both VB.NET and C#:
    a. camelCase for local variables and parameters
    b. PascalCase for pretty much everything else
    c. _camelCase (camelCase with a leading underscore) for private or protected member variables
    d. ALL_CAPS_WITH_UNDERSCORE for constants
    e. Hungarian notation only for web or WinForm control variables

    IOW, it's a strange mix of .NET guidelines and my own peculiariaties. Oh well, at least I'm consistent.
    Last edited by brackett; 05-30-2006 at 06:06 PM.

  3. #3
    Lop
    Lop is offline
    Speaks fluent binary Lop has a spectacular aura about Lop has a spectacular aura about Lop's Avatar
    Join Date
    May 2006
    Posts
    1,179
    Quote Originally Posted by brackett
    IME, the first style is called camelCase, and the second PascalCase. Note that this Wikipedia article, however, says they are both camel case and should be called lowerCamelCase or UpperPascalCase. I say I've never heard of such terms - but do realize that wiki engines in general call PascalCase camelCase. I submit the .NET Framework Design Guidelines on Capitalization in my defense.

    For .NET, Microsoft has the above design guideline for the BCL. I'm sure Java has something similar. It's probably advisable to follow those guidelines, so here's the relevant portions of the .NET one:
    a. camelCase for parameters, local and (non public) member variables
    b. PascalCase for classes, enum types and values, properties, functions, events, readonly statics, public member variables, interfaces, namespaces, and acronyms more than 2 letters long
    c. no Hungarian notation
    d. no prefix for member variables (I'm not entirely sure this is in there, I know it recommends against underscores for class names, but others have stated it does as well for member variables. I do know, however, that you cannot be CLS compliant with an underscore prefix)

    And, now that I have given the "official" recommendation, here's how I actually do it for both VB.NET and C#:
    a. camelCase for local variables and parameters
    b. PascalCase for pretty much everything else
    c. _camelCase (camelCase with a leading underscore) for private or protected member variables
    d. ALL_CAPS_WITH_UNDERSCORE for constants
    e. Hungarian notation only for web or WinForm control variables

    IOW, it's a strange mix of .NET guidelines and my own peculiariaties. Oh well, at least I'm consistent.
    Wow, nice post. I've never done it so. I've always just used CamelCase (Upper) or PascalCode for everything. I guess each person should read up and then default to their own style.

    .... I need to change my style now .....
    Lop

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. New Anti-Cheat Community needs coding help
    By avguste in forum PHP Forum
    Replies: 8
    Last Post: 04-04-2008, 04:42 PM
  2. Coding a stock ticker accessing an asp DB
    By gtg100i in forum General Programming
    Replies: 2
    Last Post: 12-10-2006, 09:33 AM
  3. Classes, Methods, and Objects
    By Sionofdarkness in forum Java Help
    Replies: 6
    Last Post: 08-21-2006, 12:55 PM
  4. Coding Methods
    By Lop in forum General Programming
    Replies: 10
    Last Post: 07-14-2006, 10:03 AM
  5. How long have you been coding php?
    By cpvr in forum PHP Forum
    Replies: 11
    Last Post: 07-11-2006, 12:41 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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