Refactorings to Improve Maintainability
The refactorings in this category are intended to improve internal
quality attributes of the code such as: readability,
understandability, flexibility and extensibility (attributes that
refactoring has been recognized to improve) and also refactorings
that allow upgrading the code to newer versions of Fortran, removing
Refactorings to Improve Presentation / Readability
- Rename: change
the name of a variable, subprogram, etc.
- Extract Local Variable:
remove a subexpression from a larger expression and
assign it to a local variable.
- Extract Local
Procedure: remove a sequence of statements from a
procedure, place them into a new subroutine, and replace the
original statements with a call to that subroutine.
- Canonicalize Keyword
Capitalization: make all applicable
keywords the same case throughout the selected Fortran program
Variable Case : make all pvariable names
aplicable the same case throughout the selected Fortran
program files.Added 27/06/2012
Statements: rewrites all variables declarations,
so that there is only one variable declaration per line, and
every variable declaration contains a double colon (::).This is
intended to make the code more readable.
Specification Statement to Declaration Attribute:
Replaces the various specification statements (DIMENSION,
PARAMETER, SAVE, etc.), with the attribute declarations in the
variables' type declaration statements.Added
Refactorings to Facilitate Design/Interface Change
Refactorings to Avoid Poor Fortran Coding Practices
Variable: create getter and setter methods for
the selected variable.
- Make Private
Entity Public: switch a module variable or
subprogram from Private to Public visibility.
Arguments: change the order of the
arguments to a subroutine and adjust all call sites accordingly.
Clause To Use Statements: create a list of the
symbols that are being used from a module, and adds it to the
Between Modules: move a module variable or procedure
from one module to another and adjust Use statements
- Add Use of
Named Entities To Module: allow to
select entities in a module and add a use only statement in a
target module (or alter the existing one).
- Safe-Delete Internal Subprograms: This
refactoring will remove all Internal Subprograms from dource
code. Added 13/09/2010
Subroutine to Function: This
refactoring will transform a subroutine to a function. Added 13/09/2010
Subroutine Signature: This
refactoring will change the order of the arguments to a
subroutine and adjust all call sites accordingly. Added 13/09/2010
- Add Subroutine Parameter : This refactoring
will add arguments to a subroutine and adjust all call sites
Unreferenced Labels: delete a label if it is
Real Type Iteration Index: change non-integer Do
parameters or control variables.
Words As Variables: rename variables named equal to
Fortran reserved keywords.
None: add Implicit None statements to a file and
add explicit declarations for all variables that were previously
In/ Out: introduce intent In or Out in each variable
declaration within functions and subroutines.
Unused Local Variables: remove declarations of
local variables that are never used.
symbols that are not being used from the Only list in a Use
Common Variable Names Consistent: give variables
the same names in all definitions of the Common block.
Common Block Variable: remove unused variables declared
in a Common Block.
Statement: add the Dimension statement to declare an
Format Statement Labels: replace the format
code in the read/write statement directly with a parameter
string, instead of specifying the format code in a separate
- Add identifier to END
statement (e.g. END SUBROUTINE FOO):
add the identifier that belongs to End statements. Added 17/05/2010
- Toggle End
Name: The toggle-end-name refactoring is
designed to automatically add or remove the end-name of a
nameable construct, provided the end-name is optional (with
several exceptions).Added 15/04/2011
Refactorings to Remove Outdated, Obsolete and Non-Standard
Obsolete Operators: replace all uses of
old-style comparison operators (such as .LT. and .EQ.) with
their newer equivalents (symbols such as < and ==).
Form To Free Form: change Fortran fixed format files to
Fortran free format files.
to Character(Len =) declaration: replace
Character* with the equivalent Character(Len =) for string
Computed Go To statement: replace a
computed Go To statement with an equivalent Select-Case
construct containing Go To or if possible remove the Go Tos
Arithmetic If Statement: replace an old
arithmetic If statement, being analogous to removing computed Go
Go Tos: remove assigned Go To statements.
- Replace Old
Styles DO loops: replace old styles Do Loop
Continue with the equivalent Do Loop with End Do statement.
Shared Do Loop Termination: replace all
shared Do Loop termination construct with the equivalent Do Loop
with End Do statement.
While Sentence: remove simulated While made by If and
Go To statement.
Block to Module: remove all declarations of a
particular Common block, moving its variable declarations into a
module and introducing Use statements as necessary.
Variables To Common Block: create a Common block
for all saved variables of a subprogram.
- Data To
Parameter: change a Data declaration to
Parameter declaration making more clear which variables are
constant and which ones are not.
This category currently has two examples of how refactoring can be
used to improve performance while preserving not only the behavior
of the program but also the readability and maintainability of the
code. This is one of the factors that sets refactoring apart form
Refactorings For Performance
- Change To Vector
Form: rewrite a Do Loop into an equivalent
Fortran vectorial notation, which allows the compiler to make
- Make DO
Loop Concurrent/Non-Concurrent (Fortran 2008) :
Loops: swaps inner and outer loops of the
selected nested do-loop, in the case that doing so allows to
optimizes memory access pattern and allows to take advantage of
data prefetching techniques.
- Fuse Loops: Takes two
do-loops, normalizes their bounds, and finally puts the loop
bodies in a single do-loop.Added 15/04/2011
- Reverse Loop:
Takes an incrementing or decrementing loop, swaps the lower and
upper bounds, and negates the step.Added
- Tile Loop: This
refactoring takes a double nested do-loop, and creates a nested
do-loop with four levels of depth. Instead of iterating through
a two dimensional array (for example) by going through each row,
it will loop over smaller tile blocks.Added
Loop: Takes the selected do-loop and either completely
or partially unrolls it. This will also optionally include a
conditional statement to make sure the loop stays in bounds. Added 15/04/2011
- Replace Do
Loop By Forall: This refactoring is used to
substitute DO loops by FORALL, when you have only assignments in
the loop body. Added 27/06/2012