4 ms·
I have a list I wrote up once about Python's problems. Some of these are more exotic than others. Most of them are kludgearoundable. A couple are fixed in Pytho
by pnathan 15y ago
I have a list I wrote up once about Python's problems. Some of these are more exotic than others. Most of them are kludgearoundable. A couple are fixed in Python 3. Some are simply design choices that are exactly different from my mental model of the world, and due to the TOOWTDI Python world, it is frustrating to work with them.
Some Things Wrong With Python
* Immutable strings[0]
* Everything a reference[1]
* Environment copied on loop entrance (implying assignments often break when done in loops)
* Lack of braces[2]
* Lack of enums[3]
* Standard debugger pdb reminds me of the first debuggers ( used on the PDP-1 and EDSAC) in its feature list.
* Exception-oriented design, which clutters code with "try/catches" everywhere.
* Exceptions aren't just exceptions, they are also overloaded to provide signals.
* Two forms of objects (old style vs. new-style)
* Object inheritance is pointer to parent. Metaprogramming becomes an exercise in hackery.
* Objects are actually dictionaries with some pointers behind the scenes.
* Duck typing will automagically cast certain things[4]
* As an interpreted language, code that is not tested can be assumed to be syntactically correct but in error (this is a horrible problem when testing for rare error conditions)[4.5]
* When Python is fast, it's because it's calling out to C.
* Python objects are gigantic. An empty string is 40 bytes, for example. This adds up.
* Python can not meaningfully multithread, due to the global interpreter lock.
* Python suffers from many different versions being installed on different versions of Linux[5]
* Lambdas are totally broken[6]
* Large-scale module importing is a half-baked job[7]
* Python 3 routes around some these issues by using generators for everything[8].
[0] Ever try to step through a string and modify it in-memory? Well, you can't. Sorry. ;-)
[1] I.e., a function can modify something unexpectedly.
[2] Which means block commenting or commenting out tops of loops means a complete reindenting of the block, that is, editors can't do the smart thing, they don't have enough context. This is a waste of the engineer's time. Delimiters were figured out in Lisp, a very long time ago.
[3] This was figured out long ago as well.
[4] But not others. Object design is a bit funky.
[4.5] This is a general design 'con' in dynamic languages. It's partially solvable with a sufficiently smart compiler, most compilers aren't that smart.
[5] This is why serious Python programs (that don't come bundled with their own version of Python) are written to target Python 2.4, released in 2004.
[6] A 'lambda' function in Python can not have statements. Most interesting functions have statements.
[7] Python (similar to Java) relies on a very specific directory structure for a given program to be able to import libraries. This means that if you are doing anything remotely exotic with layouts (e.g., libraries are in a peer directory, not a child directory), you have to commit hackery.
[8]This avoids the fact that the end result has to be emitted in some fashion.
- aangjie 15y ago+1 for the exhaustive list..
- hcarvalhoalves 15y agoBesides PDB, you are really just complaining about design aspects.
- tikhonj 15y agoYou forgot mutable default arguments! def fn(ls=[]): ls += [1] return len(ls) (My syntax might be a little off, but you get the idea.) This will return an ever-increasing number if called repeatedly with no arguments. Also, the reliance on tuples, particularly tuples of one item always gets me because (1) and (1,) are different. Also, the scoping for list comprehensions doesn't make sense: x = 11 [x for x in [1,2,3]] print x # 3! This has also gotten me in the past.
- pnathan 15y agoyes, those are nasty little gotchas.
- llimllib 15y agoJust for the record list comp scoping is fixed in python 3: $ python3 Python 3.2.1 (default, Aug 1 2011, 14:47:14) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x = 11 >>> [x for x in [1,2,3]] [1, 2, 3] >>> x 11
- randallsquared 15y agoThe problem is not that the argument is mutable, it's that the default argument creation is run at definition time. Mutable arguments are quite useful, and it's consistent to be able to use default arguments in this way; the argument shouldn't outlive the function execution, is all.
- buster 15y agoI stopped when i found "Lack of braces" in your list. If you don't like it.. fine.. but it's in my opinion a major plus for python. Also "everything is a reference" is 1) not true for everything and 2) a smart thing to do. Many languages do that.