Holger's Thoughts on Delphi

Friday, December 02, 2005

Coding "Standards" - The Summary

Firstly, let me tell you that I was positively surprised that I got so many comments on that subject. But I should clarify one thing: I was surprised not that there were coding standards for Delphi in general, but about the fact that Borland has an official document on BDN.

What I learned because of all the comments is that this document can be found in the help, which comes with Delphi, as well. That surprised me even more, as I never noticed it.... using Delphi since version 2. Furthermore, I was flamed by my fellow Indy Core team-mates that I forgot to mention that Indy - of course - has its own coding standard as well. Have a look at it here.

Finally, I'd like to stress that Delphi 2006 really helps you to implement a certain standard using Code Templates. Depending on how you modify the templates for basic constructs like "if" or "for" you can make sure that you get the right level of indentation or that the cursor is positioned right below the "if" to type in the begin... Of course, you can also define a complete if-construct that already has "begin" and "end;", but if you implement code like me, you do not always use a "begin" and "end"-block. This is e.g. a rule in the Indy Coding Standards to always use "begin" and "end". Be it needed or not.

I guess, I could make up a whole blog about different coding standards and related issues.

Again, thanks for all the feedback.

2 Comments:

  • If work on more than one project (eg. Indy, Jedi, your own), you would have to rewrite the code templates all the day, or have a copy of them for each coding style.

    But at least Indy and Jedi have a codingstyle (Jedi's is based on the one from BDN). I know projects where I cannot read the code without a code reformator because every function has a different coding style.

    By Anonymous Anonymous, at 12:30 PM  

  • Is there any way to change the code formatting for other stuff as well?
    For example, if I refactor a method, something like this

    function foo: integer:

    var
    iStart : integer;
    iEnd : integer;

    begin
    result:=iStart-iEnd;
    end;

    will be changed to

    function foo: Integer:
    var
    iStart: Integer;
    iEnd: Integer;

    begin
    result := iStart - iEnd;
    end;

    The capitalization of the variable types changes, spaces are added, the var gets stuck right underneath the function declaration, etc.

    By Anonymous Anonymous, at 8:49 PM  

Post a Comment

<< Home