ODAC code style

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
sinys
Posts: 186
Joined: Tue 21 Feb 2012 03:44

ODAC code style

Post by sinys » Wed 05 Jun 2013 11:39

I had to look at the source code ODAC to understand what crash my application and I noticed a lot of places where the code can be more optimal.
For example:
1) Use the keyword CONST for parameters of type String.
Gives a gain in resources, as well as good / right style.
2) Change Length (String_Variable)> 0 on String_Variable <>'' and
Length (String_Variable) = 0 on String_Variable =''
gives a decent win, because the Length function generates 10 lines of ASM code to 2 lines if a simple comparison.
To easily find the places I use TotalComander with the search text with the option of regular expressions:
\([a-z.\d/_]+: string
; [a-z.\d/_]+: string
Length\([a-z.\d/_]+\) > 0
Length\([a-z.\d/_]+\) = 0

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: ODAC code style

Post by AlexP » Wed 05 Jun 2013 13:10

Hello,

Thank you for the information, we try to use the CONST keyword and comparison without length in all key methods. In future, we will modify the whole code, where such expressions occur.

sinys
Posts: 186
Joined: Tue 21 Feb 2012 03:44

Re: ODAC code style

Post by sinys » Mon 01 Jul 2013 14:56

I want to recommend to use static code analyzers like:
CodeVerifier
Pascal Analyzer
CodeHealer

for make your code better and avoid mistakes.
Simple examle:
В файле "D:\odac90src\ODAC\Source\DBAccess.pas" сработали следующие проверки:
procedure TDAEncryption.EncryptDataSet(AutoCommitExplicitTransaction: Boolean = True)
...
for i := 0 to FOwner.FieldCount - 1 do
if FOwner.Fields.CanModify then
FOwner.Fields.Value := FOwner.Fields.Value; [строка 10049]: Левая и правая части присваивания совпадают

procedure TDADataSetUpdater.CheckUpdateSQL(const SQL: string;
...
NewSQL := NewSQL; [строка 11504]: Левая и правая части присваивания совпадают

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: ODAC code style

Post by AlexP » Tue 02 Jul 2013 09:04

Hello,

The string

Code: Select all

FOwner.Fields[i].Value := FOwner.Fields[i].Value;
is used for field data encryption, and since encryption is implemented in a setter, this is correct code.

The string

Code: Select all

NewSQL := NewSQL; 
is added to fix a specific case when optimization is enabled in Delphi 5 and 6 leading to AV. We will add a correspondent define for this string

Post Reply