Solved

Delphi coding conventions

Posted on 1998-06-09
23
657 Views
Last Modified: 2010-04-04
Does anybody know of a web-source providing coding conventions for Delphi / Object Pascal
0
Comment
Question by:andrewjackson
  • 5
  • 5
  • 4
  • +6
23 Comments
 
LVL 1

Expert Comment

by:michaue
ID: 1351635
No, we created our own.  Why???
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1351636
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
 
LVL 1

Expert Comment

by:michaue
ID: 1351637
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
 
LVL 2

Expert Comment

by:kjteng
ID: 1351638
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
 
LVL 1

Expert Comment

by:michaue
ID: 1351639
Doesn't look like he's answering us ... maybe he's out.
0
 

Author Comment

by:andrewjackson
ID: 1351640
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
 
LVL 2

Expert Comment

by:kjteng
ID: 1351641
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
 
LVL 8

Expert Comment

by:ZifNab
ID: 1351642
hi, ktjeng proposal sounds great...
0
 

Author Comment

by:andrewjackson
ID: 1351643
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
 
LVL 8

Expert Comment

by:ZifNab
ID: 1351644
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
 
LVL 2

Expert Comment

by:kjteng
ID: 1351645
Zif: good idea.

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1351646
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
 
LVL 5

Expert Comment

by:knowlton
ID: 1351647
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
 
LVL 5

Expert Comment

by:julio011597
ID: 1351648
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
 
LVL 8

Expert Comment

by:ZifNab
ID: 1351649
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
 

Author Comment

by:andrewjackson
ID: 1351650
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
 
LVL 8

Expert Comment

by:ZifNab
ID: 1351651
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
 

Expert Comment

by:skeleton
ID: 1351652
Hi

It is best to look at the Delphi VCL Source Code and see
how the Borland Experts does it.
0
 

Author Comment

by:andrewjackson
ID: 1351653
I realise that Skeleton, I just wish Borland would publish it as a document
0
 
LVL 2

Accepted Solution

by:
brainware earned 50 total points
ID: 1351654
Yes.. We do a litlle of that stuff..

http://www.bw-soft.dk

mvh.
PPL from BrainWare


0
 
LVL 2

Expert Comment

by:kjteng
ID: 1351655
sorry brainware: I went to http://www.bw-soft.dk but cannot find any thing on programming convention. Why exactly it is?
0
 

Author Comment

by:andrewjackson
ID: 1351656
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
 
LVL 2

Expert Comment

by:brainware
ID: 1351657
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now