rspec/rules/S1902/rpg/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
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.
2023-05-25 14:18:12 +02:00

71 lines
1.8 KiB
Plaintext

== Why is this an issue?
Global variables can seem like a handy way to pass state information around in a program, but the use of global variables only works well in very small programs. As the code base grows, you'll need to understand every subprocedure's impact on the global state in order to understand how the program works. This is a task that quickly becomes impossible.
To control the situation, only the main procedure should be allowed access to global variables; it can then pass that state information to subprocedures as parameters.
=== Noncompliant code example
[source,rpg]
----
D FirstName S 20A
D LastName S 20A
/free
FirstName = 'John';
LastName = 'Smith';
DSPLY FullName();
/end-free
P FullName B
D FullName PI 41A
/free
return FirstName + ' ' + LastName;
/end-Free
P E
----
=== Compliant solution
[source,rpg]
----
/free
DSPLY FullName('John':'Smith');
/end-free
P FullName B
D FullName PI 41A
D FirstName 20A Const
D LastName 20A Const
/free
return FirstName + ' ' + LastName;
/end-Free
P E
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Pass "XXX" to this subprocedure as a parameter.
'''
== Comments And Links
(visible only on this page)
=== relates to: S2536
=== on 12 Sep 2014, 14:48:35 Ann Campbell wrote:
\[~pierre-yves.nicolas] do you find this rule interesting enough to provide code samples for me? The initial requester lost interest before doing so.
endif::env-github,rspecator-view[]