Page 1 of 1

ODAC code style

Posted: Wed 05 Jun 2013 11:39
by sinys
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

Re: ODAC code style

Posted: Wed 05 Jun 2013 13:10
by AlexP
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.

Re: ODAC code style

Posted: Mon 01 Jul 2013 14:56
by sinys
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]: Левая и правая части присваивания совпадают

Re: ODAC code style

Posted: Tue 02 Jul 2013 09:04
by AlexP
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