43 lines
919 B
Plaintext
43 lines
919 B
Plaintext
The length of a collection is always greater than or equal to zero. So testing that a length is greater than or equal to zero doesn't make sense, since the result is always ``++true++``. Similarly testing that it is less than zero will always return ``++false++``. Perhaps the intent was to check the non-emptiness of the collection instead.
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,python]
|
|
----
|
|
mylist = []
|
|
if len(myList) >= 0: # Noncompliant
|
|
pass
|
|
|
|
if len(myList) < 0: # Noncompliant
|
|
pass
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
[source,python]
|
|
----
|
|
mylist = []
|
|
if len(myList) >= 42:
|
|
pass
|
|
|
|
if len(myList) == 0:
|
|
pass
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|