Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should instance/class fields be prefixed in Delphi? [closed]

As said in Uncle Bob's Clean Code, we shouldn't prefix class members. Although I totally agree with the arguments, talking specifically about Delphi, how would we differentiate private fields from public properties?

In Java that's not a problem, since there are no properties.

Microsoft also recommends this practice in big bold letters in their Coding Guidelines. They make the distinction by using lowercase for the private field and uppercase for the public property.

In addition to that, we don't have syntax highlight to field members like other IDEs (Free and Open Source IDEs included...)

So, should we prefix all of our fields? Or just the ones that collide with public properties?

Edit:

I know that the coding standard for Delphi is to prefix the fields with F, but that's preciselly what was stated as a bad practice in Clean Code. Does it mean that Delphi code cannot be "as clean" as code written in other languages?

like image 210
Rafael Piccolo Avatar asked Jun 05 '12 17:06

Rafael Piccolo


1 Answers

The Delphi way is to prefix them with F:

strict private
  FField: Integer;
public
  property Field: Integer read FField;

(see the Object Pascal Style Guide.)

like image 150
Uli Gerhardt Avatar answered Oct 07 '22 23:10

Uli Gerhardt