rspec/rules/S2011/python/rule.adoc

39 lines
807 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-01-27 13:42:22 +01:00
Global variables are a useful construct, but they should not be abused. Functions access the global scope through the ``++global++`` keyword, but this practice considerably reduce the function's readability and reusability. Instead, the global variable should be passed as a parameter to the function.
2020-06-30 12:48:07 +02:00
=== Noncompliant code example
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,python]
2020-06-30 12:48:07 +02:00
----
NAME = 'Joe'
def write_name();
global NAME # Noncompliant
print NAME
----
=== Compliant solution
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,python]
2020-06-30 12:48:07 +02:00
----
def write_name(name);
print name
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]