10 things i hate about python

-- this is from a perl programmer's prospective...

10 things i hate about python, and possible workaround...

  1.  Using tab/space indent as part of syntax structure.
    Yes,  one could consider this as a driving force for "clean code", but doing this completely eliminates the possibility of any automatic format tools. Think about the Ctrl+Shift+F for eclipse, '=' for vim and my favorite -- perltidy for perl.
    what even worse is that one could chose from tab indent and space indent, but not both! this is even more dumb than the makefile syntax, which allow you to use only tab as part of syntax.
    Possible workaround:    

     #vi:tabstop=4:expandtab:shiftwidth=4:softtabstop=4:autoindent:smarttab
  2. Very very bad compatibility across multiple python version.
    This means syntax varies a lot in different versions, and also the libraries......
    For some reason i still using python 2.4 in some situation, and one day i need some json lib, so i typed:   

    [lobatt@perlfect ~]$ python
    Python 2.4.3 (#1, Dec 11 2006, 11:39:03)
    [GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import json
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ImportError: No module named json
    >>>

    What's happend? oh, here says, json module is only for python 2.6 and above. But how hard is that? a json output for dict?

    >>> json = {}
    >>> json['a'] = 97
    >>> json['*'] = [i for i in xrange(97,123)]
    >>> print json
    {'a': 97, '*': [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
    112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122]}
    >>>

    And oh, python 3.0 is completely a whole new language!

    possible workaround:

    [lobatt@perlfect ~]$python somescript.py
    [lobatt@perlfect ~]$python2.5 someother.py
    [lobatt@perlfect ~]$python3.0 someotherscript.py
    ?
  3. Still, very coarse object oriented coding style
    Before python, i didn't know there are another language that need to pass the "self" as a parameter to the member function other than perl5.
    But even perl5 have got some workaround which enable this:  

    use WebApp;
    my $webapp = WebApp->new();
    $webapp->run();

    but in python, you must write you constructor as: __init__, looks like a function in a deep hided library.
    Possible workaround:
    With Perl we have things like Moose. But with python, they expose to you the "__init__", but won't tell you how to build your own object system. so, just use it...

  4. you can not concate str and int in a output string
    >>> answer = 42
    >>> print "the answer is " + answer
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    TypeError: cannot concatenate 'str' and 'int' objects

    I'd say: come on! you are a scripting language.
    possible workaround:
    obeys the typing shit...

    >>> print "the answer is " + str(answer)
    the answer is 42
    >>>
  5. The boolean value using uppercase initial and is case sensitive!
    >>> ready = true
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    NameError: name 'true' is not defined

    Possible workaround:
    Remember to press Shift...

  6. I always forgeting the colons...
    Especially after the if statements... 

    >>> ready = True
    >>> if not ready
      File "<stdin>", line 1
        if not ready
                   ^
    SyntaxError: invalid syntax

    Possible workaround:
    practising this bad design into habit...

  7. There even is a "pythonic" way!
    You know what, i am a fan of TMTOWTDI. i 'd say you guys are so manipulative...
    Why don't you omit the list and leave us only the tuple! with that you can claim that python is a functional programming language!
    Possible workaround:
    copy paste from current code when you need new code. stupid as it is, it will not bring more criticism to you.
  8. Python got nothing like CPAN
    Oh, there is pypi. but one have to know, but CPAN, i am not meaning a "repository", but a handy tool for automatical module install, a beautiful style of documents, a comprehensive naming convention, automatic new module skeleton builder and the PAUSE.
    Possible workaround:
    Wait until pypi had learn from CPAN.
  9. Python is a snake!
    Yes, and O'Reilly print it on the books so vividly, that i don't even dear to touch it!
    Possible workaround:
    This book
  10. And i am forced to use it at work!
    And i love my job...
    Damn!

本文网址:http://blog.perlfect.me/2010/04/9/10-things-i-hate-about-python.html

comments powered by Disqus