Menu

Coding Standard

Developers
2002-02-18
2002-02-19
  • John Edward Judd

    I've given the idea of coding standards some thought, and here's whats worked for me. I'm not really into the Java naming conventions.

    1. Class names are capitilised. eg class TheClass.

    2. Method names are capitalised as well. eg. TheClass::TheMethod() {}

    3. Attributes are first letter lowercase. eg. int theAttribute;

    4. enum items and defines are full uppercase. eg
    #define THE_DEFINE 1234
    enum TheEnum { ITEM 1, ITEM 2};

    5. I dont use hungarian notation anymore (except when I am mandated to by an employer). I find it makes it harder if you need to re-type a variable.
    The exception to this is method parameters where the the parameter is the same as a class attribute.
    eg.
    TheClass::TheMethod(int aParam)
    {
       param = aParam;
    }

    6. Inline brackets. There's apparently a NASA study on this, that it reduces the defect count. I havent seen it, and dont know where to find it though.
    eg.

    if (a)
    {
    }

    Personally I find this easier to read than:
    if (a) {
    }

    Please comment on these styles. If anyone finds them objectionable please say so, and we'll reach a compromise.

     
    • David Barker

      David Barker - 2002-02-19

      I dislike this style of backets:

      if (iWantToSaveAnExtraLine) {
          putYouHandsInTheAir();
      } else {
          andWaveEmLikeYouJustDont();
      }

      Inline brackets are better:
      if (thisHasBeenSaidAlready)
      {
           thenIAgree();
      }

      Aside from that, I will happily go along with whatever convention is agreed - though I do agree one should be made and stuck to.

       
      • John Edward Judd

        Excellent. I was hoping no-one would object to inline braces. :-)

        Something I didnt mention yesterday [it doesnt have to be in a coding standard, though I might mention it] is that I also like the reasonable use of whitespace to break the code up. Why developers pack all their code together beats me. :-)

         
    • Dakshinamurthy Karra

      No issues on this front. I think we should document these conventions and keep it. Whenever, we have an issue an informal mail among us should sort it out.

       
      • John Edward Judd

        Good one. I'll get a document written up tonight.

         

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.