

The Little Book of Python Anti-Patterns - ThePhysicist
http://docs.quantifiedcode.com/python-anti-patterns

======
a3n
Although I mostly agree with "Returning more than one variable type from
function call," I do have some disagreement.

On the restriction itself, I'm fine with returning, for example, any kind of
iterable, whether it's a list, tuple, string or whatever. It depends on
context, and python is very much an interface/context kind of language.

As for the anti-example given, that code would not fail in most print
contexts:

    
    
      In [1]: a = None
    
      In [2]: print a
      None
    

A better anti-example might have been:

    
    
      In [3]: for i in a:
         ...:     print i
         ...:     
      ---------------------------------------------------------------------------
      TypeError                                 Traceback (most recent call last)
      <ipython-input-3-6fc9adb94b0c> in <module>()
      ----> 1 for i in a:
            2     print i
            3 
      
      TypeError: 'NoneType' object is not iterable

~~~
ThePhysicist
good point, will change this!

------
wingi
Chapter performance, use set instead list: If you convert a complete list to a
set only to check if a values in a list this is not performant. Use list.index
or binary search instead. But for every performance example you should offer a
micro benchmark example.

~~~
ThePhysicist
you're absolutely right, will point this out in the next version. As said
before, if you think something could be improved, feel free to contribute!

------
wingi
Second comment: Would you switch to python3 syntax or annotate the examples
with python2/python3 differences?

~~~
ThePhysicist
good point, definitely will do this. If you have any ideas feel free to
contribute!

