My biggest problem with Python is that projects larger than a given size tend to become unmaintainable rather quickly. This is in large part because of the lack of strong typing and type annotations; if you aren't the only author or can't keep the codebase in your head, it takes real effort to figure out what a function does. Even the type annotations provided in a language like Java or C++ make this task much easier…
This is a significant problem for me as well, coming from C++ and Haskell. Even just going through and making a few changes here and there, there’s no way for me to know without extensive testing whether my edit was even remotely correct beyond a cursory syntax check. I’ve never had to deal with testing all that heavily in statically typed languages, because I can rely on the type system to do a lot of very helpful s…
Why Python is Important for You
101–110 of 231 posts
Re: Why Python is Important for You
#102Python doesn't have the glyph noise that brace-based languages do, and well-written Python is beautiful and easy to read. But lately I have been having an internal debate on whether using autodoc and inline docstrings detracts from its beauty and makes it harder to read because it reduces the amount of code you can see on the screen (see Steve Yegge's rant on this http://steve-yegge.blogspot.com/2008/02/portrait-of-n…
Re: Why Python is Important for You
#103Some 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.
Re: Why Python is Important for You
#104I am kinda afraid of getting down voted, but I have used Python and I feel like I get all this and more (CPAN) when using Perl. The major difference in my opinion is that Perl gives you even more freedoms, which causes you to need some self discipline, but you get stuff done even quicker that way. It feels a bit like Python is better for programming beginners or people that tend to be too lazy sometimes and Perl is f…
Re: Why Python is Important for You
#105As a commenter on the article wrote: what about Ruby? I say this as a happy Python user. Ruby seems very similar but I'm reminded of a pg essay on language power: looking up the power curve, you see '$Language plus a bit of weird stuff that is probably irrelevant.' So I don't trust myself. As someone who loves Python and doesn't know any Ruby beyond a few bits of syntax and the obvious bits that are common to most la…
Ruby's blocks and built in regular-expressions are two examples of things you're missing. if result =~ /regex/ that kind of thing is awesome for readability, but it can also be pretty darn slow. There's also some interesting things about the ruby object model and interpreter that are different from python's approach. Whereas in the python REPL you type help(object) to get the docs on that object, in ruby you type obj…
Also, Ruby programmers talk about how readable Ruby is, but I disagree. The lack of consistency between using parenthesis or not, how to separate arguments, or even string formating syntax makes reading Ruby code wrote by someone else much more prone to "WTF" moments than Python.
Re: Why Python is Important for You
#106I 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] * Envir…
Re: Why Python is Important for You
#107Earlier quoted context omitted.
This is a significant problem for me as well, coming from C++ and Haskell. Even just going through and making a few changes here and there, there’s no way for me to know without extensive testing whether my edit was even remotely correct beyond a cursory syntax check. I’ve never had to deal with testing all that heavily in statically typed languages, because I can rely on the type system to do a lot of very helpful s…
+1 on the static type checking problem.. i am beginning to feel very annoyed by the same... have found that writing and maintaining unit test cases help.. but are a PITA nevertheless...
Anyway, Haskell and even C++ used intelligently can tell you a lot about your program at the outset, so ultimately your tests can be more focused.
Re: Why Python is Important for You
#108I 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] * Envir…
Re: Why Python is Important for You
#109I work with python daily. I find that when I first started I avoid a lot of the "fancy" constructs such as list comprehensions, dynamic arguments, and decorators as well as meta programming. The great thing is the bar to being effective in the language is so low. You can pretty much pick up most python code and just read it and get a general feel for what it does. Not only that but it is much easier to read because o…
I find a great way to avoid deep nesting is to move code to functions, and bail out when some conditions are not met. As an example, this deeply nested code: def frob(someargs): if something > 2: ... # do some processing if that == "CONNECT": ... # some more processing if verdict in blessedsolutions: ... # even more processing print "Happy birthday!" I tend to write like this: def frob(someargs): if something I do th…
function oneTimeLoopMethod(x) {
var result, temp = -1, a, b;
do {
... extra processing code ...
a = func_a(x);
if (!a) break;
... extra processing code ...
b = func_b(a);
if (!b) break;
... extra processing code ...
temp = b;
} while (false);
result = postProcess1(postProcess2(postProcess3(temp))); // This step can be more complicated.
return result;
}
It's useful when you want do additional processing before returning the final result to the caller. Because, otherwise, you'd have to duplicate the processing code in multiple places. When I first read about this technique, its description cautioned about the lack of clarity. So, use it at your own risk!Re: Why Python is Important for You
#110I do love Python, but I often wish there was more rigor for some things. I currently work on a large project (>500K LOC) and have started to see it fall apart with a bigger team. Lack of enforced typing in function arguments, inability to create strict interfaces, inconsistency in standard library conventions, and package management would probably be my biggest gripes.