Code Refactoring With RDi
Code Refactoring With RDi
Charles Guarino
Central Park Data Systems, Inc.
@charlieguarino
0
Today, along with the team at Central Park Data Systems, he is serving
individuals and companies on a worldwide basis though his consulting work and
award-winning speaking engagements.
Charles is a true people person and can often be found at conferences sharing
his expertise on RDi and other IBM i topics.
• Terminology
• Why refactoring?
• Decision time
• Getting started
• Change management
• Wrap up
Refactoring
https://en.wikipedia.org/wiki/Code_refactoring
https://en.wikipedia.org/wiki/Technical_debt
Code Smell
https://en.wikipedia.org/wiki/Code_smell
https://softwareengineering.stackexchange.com/qu
estions/255866/what-is-meant-by-code-rot
• Terminology
• Why refactoring?
• Decision time
• Getting started
• Change management
• Wrap up
10
11
12
13
• Terminology
• Why refactoring?
• Decision time
• Getting started
• Change management
• Wrap up
14
15
16
17
18
No GOTO statements
GOTO
19
20
• Terminology
• Why refactoring?
• Decision time
• Getting started
• Change management
• Wrap up
21
https://www.altexsoft.com/blog/engineering/code-refactoring-best-practices-
when-and-when-not-to-do-it/
22
https://www.altexsoft.com/blog/engineering/code-
refactoring-best-practices-when-and-when-not-to-do-it/
23
https://sloboda-studio.com/blog/prons-and-con-for-rewriting-and-refactoring/
24
https://dev.to/bosepchuk/the-rewrite-vs-refactor-debate-8-things-you-need-to-
know-2hi4
25
26
27
28
• Terminology
• Why refactoring?
• Decision time
• Getting started
• Change management
• Wrap up
29
32
Fun Fact! Alias keyword allows you to read long field names
33
34
Database normalization
1NF
• Each table cell should contain a single value
• Each record needs to be unique
2NF
• Must be in 1NF
• Single column primary key
3NF
Must be in 2NF
Have no transitive functional dependencies
35
https://stackoverflow.com/questions/353424/list-of-source-members-in-a-
file-with-sql
36
https://www.rpgpgm.com/2016/01/using-sql-for-objects-statistics.html
37
RPG FREE
38
39
Duplicated routines
40
Using intermediate variables makes the code easier to read and debug
Instead of this:
If hours <= 40;
wages = hours * hourlyrate;
else;
wages = (hourlyrate * 40) + (hourlyrate * 1.5) * (hours – 40);
endif;
Consider this:
If hours <= 40;
Wages = hours * hourlyrate;
else;
overtimerate = hourlyrate * 1.5;
overtimehours = hours – 40;
wages = (hourlyrate * 40) + (overtimerate * overtimehours);
endif;
45
https://www.ibm.com/support/pages/node/1106409
46
• Terminology
• Why refactoring?
• Decision time
• Getting started
• Change management
• Wrap up
47
48
49
50
Extract Procedure
This can be the start of something BIG…
Section of
Mainline code
Refactor
Extract Procedure
Create service
program!!!
51
53
Example 2:
A process that can be reused in the same program
54
• Terminology
• Why refactoring?
• Decision time
• Getting started
• Change management
• Wrap up
57
58
59
60
61
62
63
https://www.youtube.com/watch?v=roesIrpiIAs
64
65
Continue Processing
66
• Terminology
• Why refactoring?
• Decision time
• Getting started
• Change management
• Wrap up
69
e-GIT Perspective
70
71
72
• Terminology
• Why refactoring?
• Decision time
• Getting started
• Change management
• Wrap up
73
Code Refactoring!
With a side of RDi
Charles Guarino
THANK YOU!!!
@charlieguarino
74