views:

103

answers:

2

I learned to program with delphi, and i always liked the object pascal code style, looks very intuitive and clean.

When you look at the variable declaration, you know what are you dealing with..

A fast summary:

Exception E EMyError
Classes and Types T TMyClass
Fields in classes f fVisible
Events On OnMouseDown
Pointer types P PMyRecord
Property Get Something Set SetSomething

It's too bad to use this identifier naming style in C++ C# Java, or any other language code?

+2  A: 

As far as I know, the T, E, F, and P prefixes are only commonly used in Delphi programming. They're a standard part of the idiom here, but in C# or Java they'd look out of place.

Get and Set are pretty standard across object-oriented programming. Not sure about the On prefix, but it wouldn't surprise me to find that that's common in any event-driven framework.

Mason Wheeler
The On is used in WinForms, but the reverse of how it is used in VCL. In VCL it is the name of the property holding the event. In WinForms it is the name of the method that fires the event. The event property in WinForms is without the On.
Lars Truijens
Get and Set in .Net are written as get_ and set_. Also a subtle difference
Lars Truijens
+2  A: 

Aside from taste and cultural issues (as already pointed by Mason)

There might be reasons why a convention is tied to a certain language, and the other languages might also have reasons for theirs.

I can only quickly think of a few examples though:

On languages that don't require a pointer type to be defined before use (like most non-Borland Pascals, C etc), the "P" one is usually rarely necessary.

Other languages might also have additional means of disambiguating (like in C where often types are upper cased, and the variables or fields get the lowercase identifier), and does not need "T". (strictly speaking Delphi doesn't neither at least for fields, since identifiers are somewhat context dependantly looked up (likeseparate namespaces for fields and types), but the convention is older than that feature)

BTW, you forget "I" for interface, and enum names being prefixed with some prefix derived from the base type name (e.g.

TStringsDefined = set of (sdDelimiter, sdQuoteChar, sdNameValueSeparator,
sdLineBreak, sdStrictDelimiter)

)

etc.

Hmm, this is another language specific bit, since Object Pascal always adds enum names to the global space (instead of requiring enumtype.enumname). With a prefix there is less polution of the global space.

That is one of my pet peeves with Delphi btw, the lack of import control (Modula2 style IMPORT QUALIFIED , FROM xxx IMPORT. Extended Pascal also has some of this)

Marco van de Voort