6

New Delphi’s Object Pascal Style Guide

 2 years ago
source link: https://blog.marcocantu.com/blog/2021-april-object-pascal-style-guide.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

April 29, 2021

New Delphi’s Object Pascal Style Guide

Embarcadero has just published on the docwiki site an updated version of the language style guide. The document has been updated to cover modern Delphi language features and some changes to the coding style


Over the last few months I drove an effort to publish a new Object Pascal style guide for today's Delphi language. From the preface:

"This document is an updated version of the classic Object Pascal style guide, originally curated by Charlie Calvert for Borland at the time Delphi was originally released. The updated version has been curated by Delphi Product manager Marco Cantu, with contributions from the internal R&D team, Delphi MVPs, and the Delphi community at large."

The text is not a language guide, rather it covers the use of white space and formatting when writing code -- something the compiler generally ignores. Nothing is mandatory here, this is just a recommendation to favor readability. Following these rules is a requirement for our own internal team and any contributor.

You can find the style guide at http://docwiki.embarcadero.com/RADStudio/Sydney/en/Delphi's_Object_Pascal_Style_Guide .
This is the document index:

  • Introduction
  • General Rules: Identifiers, Keywords, Indentation
  • Source Code Files, Units and Their Structure
  • White Space Usage
  • Comments
  • Statements
  • Type Declarations

I'll end this blog posting the short introduction:

While the Delphi compilers generally ignore any whitespace and allow for a lot of flexibility in the way a developer writes code, for readability and maintainability of the source code, Embarcadero has defined a set of guidelines used by the internal R&D and any developer involved with the project. We recommend the Delphi community at large to adopt this coding and formatting style.

The introduction of the original version of this document expresses this nicely:

“Object Pascal is a beautifully designed language. One of its great virtues is its readability. These standards are designed to enhance that readability of Object Pascal code. When developers follow the simple conventions laid out in this guide, they will be promoting standards that benefit all Delphi developers by using a uniform style that is easy to read. Efforts to enforce these standards will increase the value of a developer's source code, particularly during maintenance and debugging cycles.”
This document does not refer to or explains the language syntax and grammar, as it is only focused on defining code writing style in places where the language gives you a choice, by allowing many different options in terms of whitespace and formatting.

None of these guidelines is set in stone and we expect them to evolve over time along with the language.


posted by marcocantu @ 8:56AM | 2 Comments [1 Pending]

2 Comments

New Delphi’s Object Pascal Style Guide

It is great that there is an effort to get consistent style in projects. 
People do however have their own preferences, and teams may want 
to have a choice on what style they want to adopt. Using automated 
formatters, such as the one provided by the IDE and command line 
can be useful in helping to address this systematically. (there are a 
few quality portal requests for the formatter to disable formatting in 
certain regions such as documentation or something that requires a 
custom layout).

Comment by Conrad Vermeulen [https://www.sempare.ltd] on April 29, 13:25

New Delphi’s Object Pascal Style Guide

What about modernizing the indentation?
Two spaces is tiny, most modern style guides seem to go for at least 
3, and often 4 or more.

Comment by Eric [https://delphitools.info] on April 30, 18:12

Post Your Comment

Click here for posting your feedback to this blog.

There are currently 1 pending (unapproved) messages.

  • posted by Kerstin on May 1, 06:57

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK