The Concise Delphi Coding Standard (2018)
1. Use the Delphi Source Code Formatter on New Units before you Check them In. When you touch a function keep its formatting style the same, or reformat the whole function with the Source Code Formatter. Only that one function you touched. Use your team's settings which are shared within your team.
2. Do Not Randomly Reformat Entire Files because of Coding Standards. If you need this point explained to you in detail, you need a lot of re-education about version control.
3. Avoid WITH
4. Avoid obfuscation, including unnecessary accidental complexity, avoid unreadable code, very long functions over 80 lines in length are completely unreadable, and are a form of obfuscation, as are placing things far apart that shouldn't be far apart. Avoid that.
5. Bend, don't break. Do not start holy wars over spacing, indentation, and variable naming, or any other thing in any coding standard ever. Find a peaceful way to defer like everybody defers to the Graybeard, or whatever. Just bend, and go with the team. Do not turn coding into an emotional bloodsport.
Fin.
Postscript:
There's actually only one thing in the above list that's explicitly delphi specific. But the VCL source code formatter's default settings are pretty reasonable. I prefer to add line breaks to uses clauses as that enhances readability, reformatting the following into one unit per line, which with the addition of Delphi namespaces makes Delphi uses clauses a lot more like reading the import list of a java or C# module:
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Mask, ExtCtrls, AdvGlassButton;
1. Use the Delphi Source Code Formatter on New Units before you Check them In. When you touch a function keep its formatting style the same, or reformat the whole function with the Source Code Formatter. Only that one function you touched. Use your team's settings which are shared within your team.
2. Do Not Randomly Reformat Entire Files because of Coding Standards. If you need this point explained to you in detail, you need a lot of re-education about version control.
3. Avoid WITH
4. Avoid obfuscation, including unnecessary accidental complexity, avoid unreadable code, very long functions over 80 lines in length are completely unreadable, and are a form of obfuscation, as are placing things far apart that shouldn't be far apart. Avoid that.
5. Bend, don't break. Do not start holy wars over spacing, indentation, and variable naming, or any other thing in any coding standard ever. Find a peaceful way to defer like everybody defers to the Graybeard, or whatever. Just bend, and go with the team. Do not turn coding into an emotional bloodsport.
Fin.
Postscript:
There's actually only one thing in the above list that's explicitly delphi specific. But the VCL source code formatter's default settings are pretty reasonable. I prefer to add line breaks to uses clauses as that enhances readability, reformatting the following into one unit per line, which with the addition of Delphi namespaces makes Delphi uses clauses a lot more like reading the import list of a java or C# module:
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Mask, ExtCtrls, AdvGlassButton;
I wonder what caused this, er... rant^H^H^H^Hadvice.
ReplyDeleteI worked at a place five years ago where there were holy wars, and I was one of the combatants.
ReplyDeleteSuch holy wars are wars of attrition, where privilege ultimately will out. I was reminded of it because someone innocently asked about a Coding Standard Document, on a facebook delphi group.
There is a coding standard from Embarcadero, or actually Borland (written by Charlie Calvert, ages ago -- around the early Kylix days, IIRC). I had my own coding style, but my sources looked very different from the generated and runtime code, so after a while, I simply adopted the Borland standard. That way, my code looks consistent and readable. I don't understand why others insist on their own standards. The Delphi IDE formatter also uses the default standard, and so do (almost) all sources.
Delete