[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 694
  • Last Modified:

Delphi coding conventions

Does anybody know of a web-source providing coding conventions for Delphi / Object Pascal
0
andrewjackson
Asked:
andrewjackson
  • 5
  • 5
  • 4
  • +6
1 Solution
 
michaueCommented:
No, we created our own.  Why???
0
 
kjtengCommented:
What is "coding conventions"? You mean whether to write
if x=1 then
begin
  ...
end

OR

if x=1 then begin
  ...
end

OR something else?

 
0
 
michaueCommented:
Yes, I suppose that is what he means.

I also  declare objects etc like this

  TBitButton   bitbContinue
  TPanel        pnlMasterData

 <lowercase object prefix><initial case object description>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kjtengCommented:
What is "coding conventions"? You mean whether to write
if x=1 then
begin
  ...
end

OR

if x=1 then begin
  ...
end

OR something else?

 
0
 
michaueCommented:
Doesn't look like he's answering us ... maybe he's out.
0
 
andrewjacksonAuthor Commented:
To expand on what I mean by coding conventions....

I lead a small team of Delphi developers, and we each have our own preferred way of naming variables, commenting code and laying out code blocks etc.  I want to develop some kind of standard convention for all these aspects of Delphi development for the team to adopt.  I've seen links to C++ equivalent standards and just wondered if anything was already developed for Delphi.

From your comments so far I think you all have the jist of what I'm trying to achieve but I also want to extend the coding convention further to recommend ways for writing certain types of code.  For example, I come from a pre-Delphi Object Pascal background and so when defining new classes I used to declare lots of private variables and expose Get / Set methods to access that data.  

Delphi now provides 'Properties' which are a much neater way of encapsulating data within objects, so I'd like to recommend that people implement encapsulation using Properties wherever possible.  I'm sure there are lots of other Delphi-related issues that ought to be documented in a coding convention.

My feeling is that Delphi (and Visual Basic) make it so easy to put together a working program that its very easy for developers to become lazy and not consider how efficient, expandable or easy-to-read their code is.


Any comments?
0
 
kjtengCommented:
I remember I come across some guide for project team in dsp but it is that comprehensive as what you mentioned.
Where can we find the standard for c? May be we can modified from there.
0
 
ZifNabCommented:
hi, ktjeng proposal sounds great...
0
 
andrewjacksonAuthor Commented:
There is a very basic standard for C++ at :

http://www.pebbs.com/mauricej/lang.html

but I'd like to see a lot more information than this.
0
 
ZifNabCommented:
what about this :

 you set up which information you need, every expert fills in the information he knows and then we discuss all the available information?.

Zif.
0
 
kjtengCommented:
Zif: good idea.

0
 
Pegasus100397Commented:
Speaking for myself, and having taught it to others, here are a few things I do to make my code more readable

rVariableName: Float;          (prefix r indicates a Real or Float)
iVariableName: Integer;      (prefix i indicates Integer)
 and so on and so on...

Column in tables are prefixed with a 2 character code identifying the table they are part of, for instance

CI_ACCOUNT_CODE tells me the this Account column comes from the Customer Information yable whereas AP_ACCOUNT_CODE comes from the Accounts Payable code.

I use prefixed for everything, a few examples:

rb (Radio Button)
tbl  (table)
qry (query)
lbl (Label)
edt (edit box)

doing this allows me to know quicking what it is I'm working with.



Not alot here and not real specific but just thought I'd pass along a few things that make my life a little easier.

Pegasus
0
 
Tom KnowltonWeb developerCommented:
You know, Delphi already does a lot of this for you (naming conventions for components).  For example, when you drop a TEdit Field on the form, the name of the component in the Object Inspector is automatically set to Edit1.  I just take off the "1" on the end and name it whatever I want, like "EditUserName" or whatever.

I suggest to let Delphi do this work for you.  Provided the names are not longer than 32 characters, or whatever the limit is, you should be fine.
0
 
julio011597Commented:
Pardon me, but this - very interesting - discussion seems to confirm there are no standard coding conventions for Delphi/OOP...(?) I'm also inclined to think C++ conventions - maybe, better, Windows/C++ conventions - are not adequate, since Delphi/OOP seems quite higher level. Doesn't Borland (Imprise) tell anything on this matter?

-julio
0
 
ZifNabCommented:
There are conventions, yes... but not so quit specific... let say this simple thing for instance, what is the best way :

 for i := 1 to 5 do begin
 end;

 for i:= 1 to 5 do begin
 end;

 for i := 1 to 5 do
 begin
 end;

 for i := 1 to 5 do
  begin
  end;

..

you see, if you want a really code convention, you have to go really deep...
0
 
andrewjacksonAuthor Commented:
Thanks for all your comments, I never expected to generate such a discussion.  From the responses so far it seems that currently there is no convention or best practice for writing Delphi code but enough people seem to have an interest or at least enough ideas to indicate a need for one.

I think we could spend forever discussing the pros and cons of different naming conventions etc in the experts-exchange so I agree with Julio that Borland(Inprise) ought to put some kind of best practice document together. Delphi is no-longer standard Pascal (unlike ANSI C++) so it makes sense that the producer of the language also produce a coding convention for it that emphasises best use of its new syntax like Properties etc.  Also, the VCL source code all looks quite consistent so Borland probably already work to a standard themselves, why don't they publish it as a white paper on their web-site?

I've no contacts at Borland but perhaps some of the 'experts' have and could make this suggestion to Borland.

Andrew
0
 
ZifNabCommented:
Sorry, I don't feel myself as an expert and I absolutely have no contact with some of the guys at Borland... I haven't reached such a high level. So I guess it has to come from an 'expert'
0
 
skeletonCommented:
Hi

It is best to look at the Delphi VCL Source Code and see
how the Borland Experts does it.
0
 
andrewjacksonAuthor Commented:
I realise that Skeleton, I just wish Borland would publish it as a document
0
 
brainwareCommented:
Yes.. We do a litlle of that stuff..

http://www.bw-soft.dk

mvh.
PPL from BrainWare


0
 
kjtengCommented:
sorry brainware: I went to http://www.bw-soft.dk but cannot find any thing on programming convention. Why exactly it is?
0
 
andrewjacksonAuthor Commented:
For anyone interested I've found a couple of useful links:

Delphi 4 Developer's Guide Coding Standards Document
http://www.xapware.com/ddg/

Orange County Delphi Users Group Delphi/Pascal Coding Standards
http://www.ocdelphi.org/standard.htm

Andrew
0
 
brainwareCommented:
http://www.bw-soft.com/devarchive/

Should be up and running with a lot of files soon..
We will also open a Large Archive with Professional Game Development..


0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 4
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now