
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
66 lines
1.6 KiB
Plaintext
66 lines
1.6 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Subprocedures and subroutines are both mechanisms to segregate logic, but subprocedures are preferred for three reasons:
|
|
|
|
* their local files and variables make maintenance faster and cleaner. They allow you to create variables without worrying about name clashes, and to change fields without worrying about negatively impacting other parts of the program.
|
|
* their local files and variables make code reuse easy.
|
|
* they can be called with parameters as functions, yielding clearer more readable code.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,rpg]
|
|
----
|
|
D FirstName S 20A
|
|
D Initial S 1A
|
|
D LastName S 20A
|
|
D FullName S 43A
|
|
|
|
/free
|
|
FirstName = 'John';
|
|
Initial = 'A';
|
|
LastName = 'Smith';
|
|
EXSR SPFullName;
|
|
DSPLY FullName;
|
|
...
|
|
|
|
begsr SPFullName;
|
|
FullName = FirstName + ' ' + Initial + ' ' + LastName;
|
|
endsr;
|
|
/end-free
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,rpg]
|
|
----
|
|
/free
|
|
DSPLY FullName('John':'A':'Smith');
|
|
...
|
|
/end-free
|
|
|
|
P FullName B
|
|
D FullName PI 43A
|
|
D FirstName 20A Const
|
|
D Initial 1A Const
|
|
D LastName 20A Const
|
|
/free
|
|
return FirstName + ' ' + Initial + ' ' + LastName;
|
|
/end-Free
|
|
P E
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Convert this subroutine into a subprocedure
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|