_REDUCT Code Reduction Report

Top  Previous  Next

 

Targets: All

 

This report pinpoints unnecessary code that could be deleted, resulting in a smaller amount of code to maintain and search for errors.

 

 

 

Identifiers never used (REDU1)

 

This is a list of all identifiers that are declared but never used. The Delphi compiler (from Delphi 2) also reports this if warnings ($W+) have been turned on during compilation. Most often, you can remove these identifiers. If you remove any identifier, make sure your code still compiles and works properly. A wise habit is to first comment out these declarations, and remove them entirely when you have validated that the code still compiles and works as intended. Also, note that if a subprogram is not used, does not necessarily indicate that it is not needed at all. If it is part of a general unit, the subprogram could very well be used in other applications.

 

Identifiers (parameters, local variables etc) related to subprograms that are not used, are not reported.

 

Constructors/destructors are not examined by this section. Also parameters to event handlers, or methods that are referenced in form files, are not reported as unused. The reason is to avoid unnecessary warnings.

 

Also unused methods of a class that are implemented through interfaces are not reported. In this case, the class has no choice but to implement these methods.

 

Example:

 

clip0110

 

In this case, the parameter Sender is not reported as unused, since mnuOpen is an event handler.

 

This section is also generated for multi-projects.

__________________________________________________

 

Local identifiers only used at a lower scope (REDU2)

 

This is a list of all local identifiers that are only used at a lower scope, in nested subprograms. You can declare these identifiers in the local procedures/functions where they are actually used.

 

Example:

 

clip0111

 

__________________________________________________

 

Local identifiers only used at a lower scope, but in more than one subprogram (REDU3)

 

This is a list of all local identifiers that are only used at a lower scope, in nested subprograms. You can probably declare these identifiers in the local procedures/functions where they are actually used, unless they should be shared by the nested subprograms.

 

Example:

 

clip0112

 

__________________________________________________

 

Local identifiers that are set and referenced once (REDU4)

 

This is a list of all local identifiers that are set and referenced just once. It may be more efficient to skip these intermediate identifiers.

 

Restrictions:

Identifiers that are first set as a var parameter in a call to a subprogram, and afterwards referenced, are not reported.  Also, when the identifier is referenced in a loop, it is not reported.

 

Example:

 

clip0113

 

__________________________________________________

 

Local identifiers that possibly are set and referenced once (REDU5)

 

This is a list of all local identifiers that possibly are set and referenced just once. They are referenced in unknown fashion, and the parser cannot determine whether they are set or just referenced in these locations. It may be more efficient to skip this intermediate identifier.

 

Restrictions:

Identifiers that are first set as a var parameter in a call to a subprogram, and afterwards referenced, are not reported. Also, when the identifier is referenced in a loop, it is not reported.

 

Example:

 

clip0114

 

__________________________________________________

 

Local identifiers that are set more than once without referencing in-between (REDU6)

 

This is a list of all local identifiers that are set (assigned) more than once without referencing in-between. You can probably remove all but the last assignment. It may of course also indicate a coding error.

 

Example:

 

clip0115

__________________________________________________

 

Local identifiers that possibly are set more than once without referencing in-between (REDU7)

 

This is a list of all local identifiers that are set (assigned) more than once without referencing in-between. They are referenced in unknown fashion, and the parser cannot determine whether they are set or just referenced in these locations. You can probably delete all but the last assignment.

 

Example:

 

clip0116

 

__________________________________________________

 

Class fields that are zero-initialized in constructor (REDU8)

 

This is a list of all class fields that are zero-initialized in constructor. Since class fields are automatically zero-initialized when the object is created, there is usually no need to include this code.

 

Example:

 

clip0117

 

__________________________________________________

 

Class fields that possibly are zero-initialized in constructor (REDU9)

 

This is a list of all class fields that possibly are zero-initialized in constructor. They are referenced in unknown fashion, and the parser cannot determine whether they are set or just referenced in these locations. Since class fields are automatically zero-initialized when the object is created, there is usually no need to include this code.

 

Example:

 

clip0118

 

__________________________________________________

 

Local long strings that are initialized to empty string (REDU10)

 

(Not relevant for BP7 and D1)

 

This is a list of all local long strings that are initialized to empty strings. An unnecessary action, since long strings are automatically initialized as empty strings upon creation.

 

Example:

 

clip0120

 

__________________________________________________

 

Local long strings that possibly are initialized to empty strings (REDU11)

 

(Not relevant for BP7 and D1)

 

This is a list of all local long strings that are initialized to empty strings. They are referenced in unknown fashion, and the parser cannot determine whether they are set or just referenced in these locations. An unnecessary action, since long strings are automatically initialized as empty strings upon creation.

 

Example:

 

clip0121

 

__________________________________________________

 

Functions called only as procedures (result ignored) (REDU12)

 

These functions may possibly better be implemented as procedures, because the result is never used.

 

This section is also generated for multi-projects.

 

__________________________________________________

 

Functions/procedures (methods excluded) only called once (REDU13)

 

The code in these functions/procedures could possibly be included inline instead, avoiding an unnecessary call.

 

This section is also generated for multi-projects.

 

__________________________________________________

 

Methods only called once from other method of the same class (REDU14)

 

These methods are never called from the outside. The code in these methods could possibly be included inline instead, avoiding an unnecessary call.

 

This section is also generated for multi-projects.

 

__________________________________________________

 

Unneeded boolean comparisons (REDU15)

 

This list contains locations with statements like

 

if bReady = true then

 

This could be shorter and better written as

 

if bReady then

 

 

__________________________________________________

 

Boolean assignment can be shortened (REDU16)

 

This list contains locations with statements like

 

clip0122

 

This could be shorter and better written as

 

clip0123

 

__________________________________________________

 

Fields only used in single method (REDU17)

 

This list contains class or record fields that are only used in a single method. They could probably better be declared as local variables.

 

 

__________________________________________________

 

Consider using interface type (REDU18)

 

This list contains objects which can be declared and implemented as an interface type, instead of as the class type implementing the interface. The advantage is that interface reference counting can be used so you will not have to explicitly free the object.

 

clip0200

 

The list will not include objects that are not created. These objects are probably just assigned to another object.

Another condition that must be met is that the object is of a class that implements exactly one interface.

 

__________________________________________________

 

Redundant parentheses (REDU19)

 

This section lists locations in your code where superfluous parentheses can be removed, simplifying the code.

 

clip0198

 

 

__________________________________________________

 

Common subexpression, consider elimination (REDU20)

 

This section lists locations in your code with repeated common subexpressions. Those may be candidates to put into temporary variables to simplify and optimize the code.

 

Example:

 

clip0178

 

 

If any of the variables involved in the repeated expressions would have been modified, between the locations, there should not be any warning.

 

_________________________________________________

 

Default parameter values that can be omitted (REDU21)

 

This list contains calls to functions or procedures that use default parameters, and where the parameter can be omitted at the call site. The reason is then that the value of the parameter passed is the same as the default parameter value.

 

Example:

 

clip0179

 

_________________________________________________

 

Inconsistent conditions (REDU22)

 

This section reports locations with inconsistent conditions. These are places where a condition check is repeated, even if the outcome will be the same as in the previous location.

 

Example:

 

clip0176

 

_________________________________________________

 

Typecasts that possibly can be omitted (REDU23)

 

This section reports locations with typecasts that possibly can be omitted. It is locations where the typecast casts the variable to the same type that it already has.

 

Example:

 

clip0185

 

 

 

See also:

 

R_GEN General Reports