rspec/rules/S1902/rpg/rule.adoc

71 lines
1.8 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,rpg]
2021-04-28 16:49:39 +02:00
----
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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,rpg]
2021-04-28 16:49:39 +02:00
----
/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[]