Menu

Uppercase method names

2004-12-14
2013-04-17
  • Nobody/Anonymous

    Hello,

    why are all the method names uppercase? I have always liked the convention of having class names uppercase and method names lowercase, and I don't quite understand why to remove this helpful distinctive feature by doing it all uppercase.

    Please tell me, I'm really curious.

     
    • Brian Bisaillon

      Brian Bisaillon - 2004-12-15

      Class names follow the convention below:

      class ClassName

      Method names follow the convention below:

      MethodName()

      Constant names follow the convention below:

      define(CONSTANT_NAME, 'value');

      Variable names follow the convention below:

      mixed $variableName

      Template variable names follow the convention below:

      {TEMPLATE_VARIABLE}

      This provides a clear distinction between different items in the source code. If you find any classes, methods, variables, constants or template variables that do not conform to this syntax, they are probably a part of classes that I haven't written (meaning they were written by someone else).

      I don't like using underscores too often and tend to avoid them as a best practice. Furthermore, I would like to mention that when you have a $variableName, that convention applies to variables with two or more words. Otherwise, you just use $variable. By the way, keep in mind that variables can be properties of a class. They use the same convention.

      I also tend to avoid using multiple uppercase letters like DAOFactory so you will only see DaoFactory for example. I try to avoid abbreviations and acronyms too except in certain cases like the DaoFactory. I try to make it as much in plain english as possible.

      I could have used methodName() but that would look too much like a variable. So you could end up with methodName($variableName) but I liked MethodName($variableName) better and then when you use a class it's ClassName->MethodName($variableName).

      I didn't follow any one standard because I found them all to be different. .NET uses MethodNames() whereas J2EE uses methodNames(), etc. There are many different coding standards for different languages. I tried to pull in the best aspects and put it together in a way that I thought made sense.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.