-
Notifications
You must be signed in to change notification settings - Fork 25
Description
This is a minor issue that should have no relevant impact in performance (and, for certain, not a negative one). But, IMHO, it is a boost in readability and friendlier to typical Python idioms.
There are a total of 26 places where a list is initialized with the following pattern:
some_blocks = [object() for _ in range(number_of_blocks)]AFAICT, there is no need to initialize object instances in order to populate the list. This is a burden for readability and for the garbage collector. I have not investigated the 26 different usages of that anti-idiom, but in the ones I have looked at, the instantiated object is never used and is simply a placeholder.
I believe that the following is much more readable for Python standards and avoids flooding the GC:
some_blocks = [None] * number_of_blocksBecause None is a singleton object (in Python), the suggested code will be lighter. I expect that to be "the chocolate of the parrot" regarding performance, but again, "Simple is better than complex & Readability counts".