Slashdot Mirror


Van Rossum: Python Not Too Slow

snydeq writes "Python creator Guido van Rossum discusses the prospects and criticisms of Python, noting that critics of Python performance should supplement with C/C++ rather than re-engineering Python apps into a faster language. 'At some point, you end up with one little piece of your system, as a whole, where you end up spending all your time. If you write that just as a sort of simple-minded Python loop, at some point you will see that that is the bottleneck in your system. It is usually much more effective to take that one piece and replace that one function or module with a little bit of code you wrote in C or C++ rather than rewriting your entire system in a faster language, because for most of what you're doing, the speed of the language is irrelevant.'"

510 comments

  1. 007087 by Anonymous Coward · · Score: 5, Insightful

    Title is kinda silly.. as the basic referenced statement is that in some cases python _is_ too slow but that one can work around that using hacks (or a language agnostic component oriented architecture).

    As for:

    You said that if you trust your compiler to find all the bugs in your program, you've not been doing software development for very long.

    It’s not about finding all the bugs, or even many of them. It’s about another layer where a potential bug can be caught. Runtime bugs are the worst kind as they can sit dormant for a while if in a rarely traveled branch. The more checking that can be done at the compile level, the better (imo).

    Personally my biggest complaint about python wasn’t on the list: A lot of the (common) libraries out there are poorly documented, inconsistent, buggy, or incomplete.

    As a Gentoo user, the python 2/3 thing is also especially annoying. Obviously this isn’t really python’s fault.. but it still gives me a bad taste about python.

    That said, this was a great article.. short, to the point, and the answers were pretty good!

    1. Re:007087 by stanlyb · · Score: 0, Flamebait

      And just as a comment, if you are smart enough to pinpoint this critical little piece of code, which you could write in C/C++......then your skills would be pretty much enough to write the same program on C/C++, and i dare to say, even with less skill set. So, what was the point again of learning Python!!!

    2. Re:007087 by Pieroxy · · Score: 5, Insightful

      And to add to that:

      Python Not Too Slow

      True. It's not too slow. It's just not fast enough.

    3. Re:007087 by MightyMartian · · Score: 2, Insightful

      No fucking kidding. "Python isn't slow, especially when you rewrite the Python function causing the problem in C..." WTF do these people come from?

      --
      The world's burning. Moped Jesus spotted on I50. Details at 11.
    4. Re:007087 by Anonymous Coward · · Score: 1

      I can see the argument being made, though I've made it more with java/c++. It's not about skill set, it's about tool set/existing infrastructure and so on. If a system is primarily built on Java and uses an extensive set of frameworks / libraries.. it really doesn't make sense to re-write the whole thing because there is _one_ section where java is the worst possible language for the job.

      That said I always consider this type of approach a last result.. and in general, I would vastly prefer to write the whole thing in c++ if I anticipated performance being an issue .. especially on a new project.

    5. Re:007087 by errandum · · Score: 1

      But python brings some things to the table that other languages don't have, like some of those libraries that, as you said, are not well documented, but most of the time do what you want and you don't have to worry about memory management, pointers, etc. while having access to dictionaries out of the box.

      I'm all for writing the program in whatever language you feel more comfortable on and just do the heavy duty stuff in c++ daemons or something like that.

    6. Re:007087 by Anonymous Coward · · Score: 1

      And just as a comment, if you are smart enough to pinpoint this critical little piece of code, which you could write in C/C++......then your skills would be pretty much enough to write the same program on C/C++, and i dare to say, even with less skill set. So, what was the point again of learning Python!!!

      Not necessarily. There are quite a lot of use cases where you may want to write a relatively small inner data-processing loop over a bunch of arrays in C or C++, but you don't want to have to implement all of the GUI, networking protocols, I/O, configuration management etc. in C or C++. In order to turn a proof of concept into a usable tool you can take a lot of time developing the peripheral stuff, but the critical requirement for that sort of code is flexibility rather than raw performance. That is a place where Python might be ideal to minimize development time and cost. Python sets up and loads all of the data and parameters in an appropriate way and then a C function carries out the grunt work before Python formats and displays the results.

    7. Re:007087 by Anonymous Coward · · Score: 5, Insightful

      This thread is idiocy. The point is, you can write the code in python several times in the same amount of time it takes to write it in C or C++. So if you then spend a fraction of that to optimize it, you write a very small portions in C/C++, you still wind up WAAAAY ahead.

      These people come from a place where they understand the value of coders all that it entails. A better question is, where do you come from that you don't have to deal with the reality of programming in the real world?

    8. Re:007087 by Anonymous Coward · · Score: 5, Insightful

      Python, apart from the inconsistent standard of the libraries that the GP mentioned, is brilliant for the 'glue code' that holds small to medium sized programs together. Ruby may have the edge for organising larger programs.

      Rewriting a relatively small Python program in C++, one that does a fair bit of file handling, string chopping about etc, can make it into a relatively large program. Doing it in C is asking for pointer problems. I've been programming in C from before C++ existed, C++ since then and Python for about 5 years.

      I am quite capable of writing the glue code successfully in any of the languages, but to do it efficiently I'd choose to do exactly as TFA says - write the main bulk of the code in Python( (or Ruby, or some other higher level language), then measure it to find the real slow bits (you wouldn't optimise until you have measured where the problems REALLY are, would you?) and rewrite just those bits in a lower level, faster language.

      Of course, once you see where the speed issue lies, it's just as likely you can find an algorithmic improvement that fixes it 'enough' anyway...

    9. Re:007087 by Anonymous Coward · · Score: 2, Insightful

      Both of you guys are goddamned idiots. The fucking language is designed to seamlessly use libraries written in C. Can you not really in your infinite arrogant wisdom not see how a ridiculously easy language like Python would be something to use to write all of an application save for that one little spot that needs just a little more performance? Of course, I know what you're thinking, "fuck that, I'm teh l33t; why would I use a language that uses 1/10 the code to do the job when I can just do it The Hard Way(TM)." Fucking morons.

    10. Re:007087 by MightyMartian · · Score: 0, Troll

      As the GP pointed out, if you're skilled enough to write optimized code in C/C++, why fuck around with Python at all?

      --
      The world's burning. Moped Jesus spotted on I50. Details at 11.
    11. Re:007087 by sjames · · Score: 4, Interesting

      I have been coding in C for quite a while. Everything from simple user programs through kernel code, drivers, and firmware. I find that python is quite liberating. It allows me to accomplish a lot more faster and have it tend to just work. I do perform the analysis and occasionally re-implement a performance critical function in C, but I find that it's surprising how little that actually improves most situations, not because of a deficiency in Python, but because it wasn't actually all that slow.

      Yes, I could implement the cool handling of various data types Python has in C, but doing so will produce something that looks a LOT like a poorly tested and less optimum implementation of Python.

    12. Re:007087 by nedlohs · · Score: 5, Insightful

      Because it's significantly faster in terms of development time, or in terms of cost (having the less skilled, cheaper programmers work on it).

      It's always been a case of write the critical stuff in C/C++. That's why languages like python and perl make doing so so simple.

    13. Re:007087 by buchner.johannes · · Score: 4, Informative

      As the GP pointed out, if you're skilled enough to write optimized code in C/C++, why fuck around with Python at all?

      Because we don't want to spend our time thinking about pointers and how to iterate over things? Because functional programming is actually really nice? Because in Python, you can download some data from the web, analyse it using a machine learning algorithm, plot the results, and install another package on the fly, combining 4 independent packages, and many ideas, in just 50 lines of code.

      ctypes is really easy to use and to interface with C or Fortran. I use it a lot, namely for the 1% of the code that takes 99% of the time. The rest is nice OOP and functional.

      --
      NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
    14. Re:007087 by RoccamOccam · · Score: 1

      Because it takes quite a bit more time to do it without Python? I'm not sure why that point is not coming through.

    15. Re:007087 by Grishnakh · · Score: 3, Insightful

      It's not about skills, it's about developer time. It generally takes longer to write code in C or C++ that to write something to do the same thing in a higher-level language like Python (C much more so than C++ I would think, especially if you're doing anything involving strings; C really sucks for that stuff; C++ is much better, esp. with a good library like Qt).

      Another factor is that you might be working on a larger project, and not everyone is all that skilled. So you can put the Python monkeys to work on some parts, and put the C or C++ people to work on the performance-critical sections, and merge the two together.

    16. Re:007087 by Anonymous Coward · · Score: 0

      Not about skills. About time.

    17. Re:007087 by Anonymous Coward · · Score: 0

      True, if you are skilled enough to rewrite that piece of critical code in C/C++, so why not do the entire code in C/C++? The idea behind this philosophy (IMO) is to reduce coding time, as opposed to having to spend time writing everything in C/C++, which depending on your requirements may be daunting, or simply a drag, then you can simply write everything in Python, then while testing if you see anything that is running too slow, and there is no native way of speeding it up, then just identify the problematic code, and rewrite just that piece in C/C++ and be done with it. Simply put, Python is language that is powerful, and allows you to get things done quickly, and it should be taken as a bonus that you can branch out to another language, and exploit its speed/functionality.

    18. Re:007087 by Anonymous Coward · · Score: 5, Insightful

      Also most people don't realize these were the same arguements given back in the 80s for writing stuff in assembly instead of C, and given that people have moved on to C++ since with the same things being said 'If it's too slow in C++ then optimize that routine in C', I would say this explanation is correct... ASSUMING python offers good enough profiling capabilities to pinpoint hotspots in the code so that you CAN optimize them away.

      That said as the GGGP stated, gentoo's usage of python in a somewhat slow and half assed manner is frustrating (but if you compare it to ANY rpm based distro it's still faster than heck. Be it a 200 mhz or 3ghz processor. Most of the speed issues seem to be pertaining to sleep states rather than actual code anyways).

    19. Re:007087 by Anonymous Coward · · Score: 0

      Obviously this isn’t really python’s fault

      Except for the decision to make an incompatible change in the language, but...

    20. Re:007087 by Anonymous Coward · · Score: 3, Informative

      ... because given two equally talented developers, the one working in python will literally run circles around the guy working in C/C++... and in the real world developer time = money.

      The fact is that interfacing with C libraries in Python is already trivial. Furthermore modern tools like Cython make it EVEN EASIER!

      So you take your code, profile it, decorate the most time-intensive portions to be compatible with Cython (trivial for most applications) -or- interface it with your C library. This way, you get your code up and running in a fraction of the developer time, with near identical performance to the C implementation.

    21. Re:007087 by tomhath · · Score: 5, Insightful

      as the basic referenced statement is that in some cases python _is_ too slow but that one can work around that using hacks

      You completely missed what he said, which is "use the best tool for the job".

      Most apps can be written much more quickly in Python than C/C++. If they perform adequately you're done. If there are slow spots, use an extension (it's not a hack) to optimize that tiny part of the app. This has been SOP since compiled languages were first invented; we used to write that last 5% of the app in Assembler. But obviously using C/C++ is more productive than Assembler and usually fast enough, just as using Python is more productive than C/C++ and usually fast enough.

    22. Re:007087 by madprof · · Score: 2

      Yeah but on actually using the language this isn't an issue. It certainly works for me.

    23. Re:007087 by vgerclover · · Score: 3, Informative

      As most things in life do, code usually follows the Pareto distribution: 80% of the time is spend in 20% of the code. If Python is fast enough for, let's say 90% of your code, and you are much more productive in Python than C, then writing most all the code in Python first, and replacing the bits and pieces that are too slow for you with C functions, is much more efficient use of your time than writing everything in C.

      Also consider that sometimes you have to go in fishing expeditions for the correct algorithm to do what you are doing. Doing so in Python, with the speedup in iterative design that that carries, and even if that once you find the most efficient algorithm for your problem you implement it in C, you will have had spend the same time as before, but knowing all the ways you can't do it, and have arrived to an at least nearly optimal solution.

      Most of the time you don't need that much speed. When you do, you have to have the right algorithm and the right language. I also put forth that Python has a lot of modules that are already written in C, so you take advantage of existing optimized code that you don't have to write.

    24. Re:007087 by Teckla · · Score: 1

      Because we don't want to spend our time thinking about pointers and how to iterate over things?

      Because the only alternative to Python with higher performance is C or C++, and all of those non-existent alternatives have all the same pitfalls as C and C++?

      *sigh*

    25. Re:007087 by lgw · · Score: 5, Insightful

      The point is, you can write the code in python several times in the same amount of time it takes to write it in C or C++. So if you then spend a fraction of that to optimize it, you write a very small portions in C/C++, you still wind up WAAAAY ahead.

      I have to disagree with that, a bit. C and old-style C++ has a lot of boilerplate allocate/release stuff going on, and yes that really slows you down making sure you got it right. But modern C++ RAII-style auto-everything code isn't like that. I find modern-style C++ and Java equivalent in the time it takes to solve the actual problem.

      Python is sometimes faster to write in. If you're doing a lot of parsing, for example, it's great. If the total size of your Python codebase remains small, that really helps. But once you start writing very formal Python where the type of every argument is declared in comments, and error handling being done with exacting precision and logging, and so on, you might as well be writing in C++ or Java.

      It's really not so much the language that makes adding code to a large code base slow! It's the need to obsess over geting the details of your thought process recorded in the code once you pass the point that any one person could possibly understand the whole codebase, or it's old enough that the original authors have all left.

      Wrting code for small projects is what's (potentially) fast - and Python is great for realizing that potential.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    26. Re:007087 by jedidiah · · Score: 2, Insightful

      People still optimize to assembler. That idea never went away. So pointing out that we've "moved on" to C++ or Java doesn't really mean this kind of issue has gone away.

      Some stuff still remains performance sensitive enough that people will go to the trouble of optimizing it at a lower level.

      --
      A Pirate and a Puritan look the same on a balance sheet.
    27. Re:007087 by Anonymous Coward · · Score: 3, Insightful

      You must be retarded because it was already explained to you above - which you even acknowledged.

      In the real world, programming costs dollars. You can write something in python for 1/8 - 1/2 the cost (cost is a function of time) and optimize a tiny section of code or you can write it in C++ and get nearly identical performance. These need not even be the same programmers; which means the opportunity for additional savings is there. Furthermore, contrary to the assertion, this is not black art programming. This is pretty medium level stuff. Your entire point of contention is a bullshit, ignoranrtly loaded question, or a knowledgable troll. In the real world, it makes LOTS of sense, contrary to the stupidity of your trolling.

      Really, a more interesting question is, this has been the party line for, what, over a decade now? Why the hell is decade (plus) old news suddenly /. worthy???? Seriously, anyone who's been doing python for more than a couple of months will have run into the python mantra, meaning its slow but fast enough. /. is so dead.

    28. Re:007087 by Anonymous Coward · · Score: 1

      Except of course Python isn't functional.

    29. Re:007087 by tgv · · Score: 1

      PERL??? Are you ... O wait. How was it? Starve a flame war, feed a troll? Or was it the other way around?

    30. Re:007087 by LordLimecat · · Score: 2

      I take it that you never use Windows logon batch scripts. I mean, if you are skilled enough to implement "net use E: \\server\share" in C++ in a few hundred lines of code, why the hell wouldnt you? It will run a few microseconds faster!

    31. Re:007087 by RocketRabbit · · Score: 1

      What language do you suppose the high performance numerical Java libraries are written in?

    32. Re:007087 by SQLGuru · · Score: 1

      If this is your argument, then you should support the use of C# with Visual Studio as well. As an IDE, Visual Studio is superior to all of them and makes writing applications quick and simple. The Intellisense makes calling into the library easy and the language is similar enough to C/C++ that when you need to drop down into those languages for performance reasons, you don't have to learn a completely new syntax.

    33. Re:007087 by Anonymous Coward · · Score: 0

      No, it's multiparadigm. Which means a bit of functional, a bit of object oriented, and I haven't seen the logic bit yet, but it must be there somewhere.

    34. Re:007087 by Savage-Rabbit · · Score: 4, Interesting

      Because it's significantly faster in terms of development time, or in terms of cost (having the less skilled, cheaper programmers work on it).

      It's always been a case of write the critical stuff in C/C++. That's why languages like python and perl make doing so so simple.

      That is heavily project dependent. If you are in a position where you can work with pure Python (i.e. the tedious job of writing wrappers for external libraries is done by others) then yes, you get RAD benefits but that is not chiseled in stone. If you are forced to combine your own C++ components with Python the picture changes. I am involved in a project that has a specialized OLAP engine, written in C++ for speed (no way around it) and a 3D GUI app that runs on top of it which was written in Python for RAD benefits. The biggest single headache we encountered with Python was that yes, you do code the GUI faster in Python, but you loose a lot of development time screwing around with writing Python wrappers for the C++ APIs of the OLAP engine. Plus, there are also endless deployment headaches. It's not as if every customer's machine comes preloaded with Python and even if it does, believe it or not your app may work with one Python distro but it will crash with the another and there are also incompatibilities between versions of Pyhon and you have no way of knowing what version is default on the target machine. You may end up having to bundle your own Python environment with your app for stability. Eventually the GUI team concluded that they were better off time wise if the just wrote the GUI in C++ using QT.

      --
      Only to idiots, are orders laws.
      -- Henning von Tresckow
    35. Re:007087 by Anonymous Coward · · Score: 0

      Do not forget that once you start combining different languages, suddenly you also need to configure and maintain two development environments, build environments, keep them up to date, compatible, and other stuff. Suddenly you are dealing with subtle differences and tricky bugs in not one but two standard libraries and other plugins. All that for a single project.

      It could be the best course of action, depending on the situation, but should not be taken lightly.

    36. Re:007087 by Grishnakh · · Score: 1

      Maybe I'm missing something here, but one big difference I see between Python and JVM, for instance, is that Python is an interpreted language, not a compiled one. Java is a compiled language, though it compiles to an intermediate bytecode that then runs on a VM (the JVM). So Python is really no different from PHP, Perl, or even BASIC in this respect: every time it runs, the interpreter has to re-read the source files and parse them before compiling them into something the machine can run, whereas with a true compiled language like C or C++, it's compiled once, before ever being run, and then kept as machine-readable binary forever after. So Java is an intermediate between the two extremes: the source code only needs to be parsed once, though the resulting bytecode running in a VM isn't as fast as natively-compiled code. So I really don't see how you could even expect Python to match the performance of Java.

    37. Re:007087 by Anonymous Coward · · Score: 0

      I'd like to point out that I hate you people. All of you. That is all. (walks slowly off into the sunset)

    38. Re:007087 by kanto · · Score: 3, Interesting

      Amen to this:) The biggest issue with scripted languages seems to be that people think simplicity of the language is a substitute for proper design for the solution to your problem. I've been involved in coding a feature where there is a possible solution in both C++ and python; seems that C++ is seen as cumbersome mostly because it requires more forethought and python is then immediately hailed as the victor as soon as it can do a halfassed job of it.

      Add to this that most people really can't code C++ and do not understand stl...

    39. Re:007087 by Bromskloss · · Score: 3, Funny

      Python! :-)

      --
      Swedish plasma phys. PhD student; MSc EE; knows maths, programming, electronics; finance interest; seeks opportunities
    40. Re:007087 by Terrasque · · Score: 4, Insightful

      Some stuff still remains performance sensitive enough that people will go to the trouble of optimizing it at a lower level.

      And the other side of that coin, is of course, that most stuff is not performance sensitive enough to go to the trouble of optimizing it at a lower level.

      Hence what Guido is saying. You can do that "most stuff" part in python, and then write that "some stuff" part as a C module. You can then use that module from python. Thus you get the benefit of both languages.

      --
      It's The Golden Rule: "He who has the gold makes the rules."
    41. Re:007087 by SolitaryMan · · Score: 1

      No fucking idea how rewriting THE SAME DAMN THING in another language would require "more skills".

      --
      May Peace Prevail On Earth
    42. Re:007087 by Anonymous Coward · · Score: 0

      Python is compiled. It's just not in-your-face about it, and, like Java, it compiles to byte code for a virtual machine instead of native code. It won't save the compiled code to disk if you are executing the Python file directly, but any modules your python file imports will have their byte code saved in .pyc files.

      There's a version of Python called Jython that compiles the Python source to JVM byte code instead of Python's. (And IronPython compiles to whatever .NET uses.)

    43. Re:007087 by Anonymous Coward · · Score: 0

      Indeed, we did used to write that last 5% in assembly language, but that wasn't to speed up a program that wasn't compiled... it was to speed up our C programs!

      Past: Program in C, identify bottlenecks, redo those bits in assembly language. Writing the whole thing in assembly language would be tedious; C programming is faster to do.
      Now: Program in Python, identify bottlenecks, redo those bits in C. Writing the whole thing in C would be tedious; Python programming is faster to do.

    44. Re:007087 by shutdown+-p+now · · Score: 3, Informative

      Because we don't want to spend our time thinking about pointers and how to iterate over things? Because functional programming is actually really nice?

      You can do all that in C++11 these days, if a tad more verbose.

      vector<int> xs { 1, 2, 3 };
      transform(xs.begin(), xs.end(), [](int x) { return x * x; });
      for (int x : xs) {
        cout << x << '\n';
      }

      Note the lack of pointers, and the lambda passed to std::transform.

    45. Re:007087 by Anonymous Coward · · Score: 0

      Python is compiled.

    46. Re:007087 by Anonymous Coward · · Score: 0

      It isn't an "issue" unless you expected Python to be C, which would be a stupid and point-missing thing to expect.

    47. Re:007087 by Grishnakh · · Score: 1

      Some languages are much harder to work with that others for certain operations. Writing some code in Perl to do a regex match of string data is nearly trivial. In straight C, it's a giant PITA, and you'll probably have a bunch of pointer bugs you'll have to debug. And if you think it doesn't require "more skills" to do regex searches in Assembly language than in Perl, you're a fool.

    48. Re:007087 by shutdown+-p+now · · Score: 3, Informative

      Python is compiled to bytecode, and said bytecode is then interpreted by Python VM. It's just that this compile cycle happens transparently, and is not explicit as with .java & .class files. It also caches the resulting bytecode in form of .pyc files, and this process can be triggered manually - indeed, many Linux distros have Python packages do that when they are installed. So there's no re-parsing there, and no direct interpretation of AST.

      Java is compiled to bytecode, and said bytecode is then JIT-compiled to native code by the VM. The VM does not typically run bytecode directly - or rather, it runs it for a few times, but when it's clear that the function is going to be called a lot, such that overhead of compiling bytecode to native is worth the bother.

      Also note that the above description of how Python works only applies to CPython, which is the most popular implementation, but by far not the only one. Python language spec explicitly recognizes the existence of alternative implementations, and language is intentionally designed to cover a wide range of implementation technique (e.g. it does not mandate reference counting and predictable implicit release of orphaned objects, for the benefit of GC-driven implementations, and provides a "with" statement to explicitly release things RAII-style). Hence why we have Jython, IronPython, PyPy etc. PyPy, in particular, implements the full source code -> bytecode -> JIT-compiled native code, similar to Java, and is much faster than CPython.

      The real reason why Python will still be slower than Java is because it's a much more dynamic language. JIT-compiler can try to infer types and other constraints, or at least predict the most likely path and optimize for that, but even a single extra check is still slower than no checks.

    49. Re:007087 by Anonymous+Brave+Guy · · Score: 4, Interesting

      People still optimize to assembler.

      Very rarely, though. On modern architectures, writing high performance assembly language requires a deep knowledge of how everything fits together. Compiler writers spend a lot of time becoming experts in this field, and a lot more time becoming experts in applying optimisations at different levels of abstraction within an entire codebase during the different stages of compilation/optimisation. Consequently most non-specialist programmers, even those who have done plenty of assembly work in their time, would produce slower final code today by hand-crafting their own assembly language than they would by writing in C and trusting a good compiler to take care of the code generation.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    50. Re:007087 by shutdown+-p+now · · Score: 1

      Or, for C++, use Boost.Python.

    51. Re:007087 by Anonymous Coward · · Score: 0

      Python compiles to PYC files. These are then run by the interpreter. Though Java tends to be faster.

    52. Re:007087 by svick · · Score: 1

      For simple, local things like this, you can avoid pointers. But most of the time, you need to pass things around, which means using pointers (possibly behind a thin veil of shared_ptr or similar). And you need to think about the pointers, which doesn't happen in languages with garbage collector.

    53. Re:007087 by Vanders · · Score: 1

      Because we don't want to spend our time thinking about pointers and how to iterate over things?

      Iterators in C++ are no harder than Python. Hell, basic pointer increments in C aren't exactly rocket surgery.

    54. Re:007087 by rrohbeck · · Score: 1

      What is this PERL language you're talking about? /me, going back to hack some Perl code...

    55. Re:007087 by Vanders · · Score: 0

      C much more so than C++ I would think, especially if you're doing anything involving strings; C really sucks for that stuff

      Depends on the problem. Just this week I needed to write a "quick" script that took a MAC address (A string of twelve characters) and add a separator (':' character) every 2 characters.

      It took me a good while to figure out a sensible way to do it in Python, but I could have done it in C in about two minutes. Including the time to compile it.

    56. Re:007087 by Anonymous Coward · · Score: 0

      You're missing something here. Python compiles to PYC files ("Python Compiled"). File timestamps are used to see if .PY code has been updated since the last compile to .PYC.

    57. Re:007087 by kraut · · Score: 1

      Writing the system in Python and only the performance critical part of the system in C++ is going to be a lot easier, and a lot quicker, to do than writing the whole system in C++. And yes, I've done both.

      You'll also find that Python is usually more than fast enough, and, and getting faster thanks to nice tools like pypy.

      --
      no taxation without representation!
    58. Re:007087 by shutdown+-p+now · · Score: 1

      For simple, local things like this, you can avoid pointers. But most of the time, you need to pass things around, which means using pointers (possibly behind a thin veil of shared_ptr or similar). And you need to think about the pointers, which doesn't happen in languages with garbage collector.

      I wouldn't exactly call shared_ptr a "thin veil". Between it and std::make_shared, you never have to deal with a raw pointer at all, and the resulting semantics are effectively equivalent to Python object references. It's somewhat more explicit because in Python "everything is a reference" and e.g. an int variable is really a reference to an immutable int object (semantically, not necessarily implemented that way); while in C++ "everything is a value" and hence extra indirection needs to be explicit. Even so, in both cases you have to understand what references are and how they work, so I don't see either model as being easier to understand.

    59. Re:007087 by Anonymous Coward · · Score: 0

      The point is, you can write the code in python several times in the same amount of time it takes to write it in C or C++.

      Citation?

    60. Re:007087 by Jeremi · · Score: 5, Funny

      the one working in python will literally run circles around the guy working in C/C++

      Pedant police here. You are under arrest for abusing the word 'literally'. Hand over your poetic license and step away from the keyboard.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    61. Re:007087 by Anonymous Coward · · Score: 0

      It's funny to me that your post assumes that python coders are going to be the "code monkeys" that are less talented than the C/C++ guys. In my experience the "less talented" guys tend not to even play around with "alternative" languages like Python. They are "ok" at .NET, Java, or even C/C++ and if you put them in front of any language outside of their comfort zone they falter pretty quickly. The people I know who know a bit of python are the best all around programmers I've worked with. PHP, on the other hand, is the opposite.. every PHP developer I've worked with has been an idiot. Again, it's just my experience...

    62. Re:007087 by Daniel+Phillips · · Score: 0

      Guido's position, in hearly so many words, is: Python is not too slow if you write your code in some other language.

      His exact words were "It is usually much more effective to take that one piece and replace that one function or module with a little bit of code you wrote in C or C++". But on the face of it, that is a glaring language deficiency. Python is too slow for compute intensive work. I have one word for Guido's attitude. Denial.

      Obfviously, Python can never be a serious competitor to Java with Guido blocking progress. Java with its bloat and performance issues is indeed nothing to crow about, but it is a better all round language than Python.

      --
      Have you got your LWN subscription yet?
    63. Re:007087 by rsclient · · Score: 3, Insightful

      My father's been in software since the 1950's. There were arguments in favor of octal machine code as being superior to assembler -- on the grounds that if you programmed in assembler, you didn't really understand what the machine is doing.

      And all those arguments are...dead. Along with the C-is-slower-than-FORTRAN battles, and the C++-is-slower-than-C, and the bytecode-languages-are-slower-than-compiled.

      It turns out that developer productivity is actually more important than almost anything. Sure, there are a couple of niches. But they are small.

      Heck, I've got developer customers inspecting over 100K packets per second in C#: they want computer performance, but they need developer performance.

      --
      Want a sig like mine? Join ACM's SigSig today!
    64. Re:007087 by Tough+Love · · Score: 1

      WTF do these people come from?

      Get hired by Google then tell each other every day that they are smart people, it must be true, just look at all this free food?

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    65. Re:007087 by ceoyoyo · · Score: 3, Interesting

      Sure, but you'd never write a whole application in assembler just because it was too slow in C. That's what the "Python is too slow" people are doing.

      There are even a variety of excellent tools to make interfacing bits of C with Python stupid easy. With Pyrex/Cython you can take your Python code as is and slowly C-ify it until its fast enough for you. Just statically defining a variable or two often makes a big difference, and yes, you can just take your Python code and statically define a single variable using Cython.

    66. Re:007087 by Anonymous Coward · · Score: 0

      I work in a shop where one side is C/C++ the other python. The python side is staffed with more people than the C++ side.

      Guess which side develops faster (hint: not the so-called RAD language)

    67. Re:007087 by Daniel+Phillips · · Score: 1

      Bash works for me a lot of the time too. But Bash sucks, and so does Python as a general purpose language. Python just goes out of its way to pigeonhole itself as a scripting language, for no discernable rational reason.

      --
      Have you got your LWN subscription yet?
    68. Re:007087 by marcosdumay · · Score: 1

      in some cases python _is_ too slow but that one can work around that using hacks

      No, he said to write the slow part in another language. Python code is composed of hacks*, thus he is telling you to use less of them. Oh, wait... He told you to write the slow parts in C, so no change here, you just exchange one kind of hacks for another.

      * Python is a great language, as is C. Maybe that pattern is universal, and what makes a language great is that it lets people hack. Well, that would answer the question of another story at the front page today.

    69. Re:007087 by Anonymous Coward · · Score: 0

      The fact is that the way you used the term 'C/C++' shows that you have literally little to no clue of what you're talking about.

    70. Re:007087 by bug1 · · Score: 1

      "It turns out that developer productivity is actually more important than almost anything."

      And productivity mean what, quality code, or cheap code ?

    71. Re:007087 by MightyYar · · Score: 1

      IronPython, Jython?

      --
      W..w..W - Willy Waterloo washes Warren Wiggins who is washing Waldo Woo.
    72. Re:007087 by narcc · · Score: 1

      The point is, you can write the code in python several times in the same amount of time it takes to write it in C or C++.

      Citation needed.

    73. Re:007087 by s1d3track3D · · Score: 1

      Say what you will about Perl (now at version 5) it has always maintained backward compatibility. (while adding new features)
      A very annoying aspect of Python is that version 3 is not backwards compatible with 2.
      Version 2 apps need to be rewritten to 3, depending on your code base and organization, this is a major PITA

    74. Re:007087 by gbjbaanb · · Score: 2

      no. If this is the argument, they you should be writing in VB.NET, not C#. VB.NEt is faster and it helps you along a lot more than C# (seriously, I was very surprised C# wasn't as good seeing as its the same bytecode under the covers). So if you really want the programmer performance with a bit of C/C++ (implemented as an inproc COM object, that VB.NET again helps you consume better than C#), you need to be dumping C# today.

      I also found that the syntax differences helped. Its easy to get confused about the subtle differences between C++ and C# because it all looks very similar. Write in VB.NET and you know which language you're dealing with and code accordingly.

    75. Re:007087 by Grishnakh · · Score: 1

      Part of this may be professional vs. hobbyist. PHP is used a lot professionally for small-to-medium-size websites, and the barrier to entry is low: it's not a hard language to learn. Someone who's talented enough to do C/C++ and also PHP is probably going to get a job doing C/C++ instead, because those jobs likely pay much better than PHP web dev jobs; this leaves the professional PHP devs as being the guys who weren't talented enough to get C/C++ jobs, while the C/C++ devs might be making very nice personal websites in PHP in their spare time.

      .NET and Java are used a lot professionally, so there's going to be tons of people who use those languages. A lot of them probably wouldn't bother with Python because their job is in .NET/Java, not in Python, so they stick with that. Moreover, maybe I'm missing something, but I haven't heard of many professional jobs in Python, so if my assumption is right that it's mainly used by hobbyists, those people you know playing around with Python are going to naturally be the more talented people who don't just learn one programming language and focus on that for their day job, but who have more of a passion for programming and want to learn about other languages out there, regardless of their popularity in industry: Python, LISP, OCaml, Haskell, etc.

    76. Re:007087 by Daniel+Phillips · · Score: 1

      you can write the code in python several times in the same amount of time it takes to write it in C or C++.

      Or C++? Maybe if you don't know C++, otherwise I would have to say that is a wild exaggeration or at best an over generalization. I find that Python development generally progresses somewhat faster than C++, but not enormously faster. And the quality of result is generally better with C++. Standalone executable, pretty compact, low memory footprint, very fast. For many "big" projects, developing in Python would just lower the quality of the result without saving enough development time to justify it.

      How about trying this: Python has less of a learning curve than C++. More accessible to more programmers. You don't need a CS degree to program in Python.

      --
      Have you got your LWN subscription yet?
    77. Re:007087 by lattyware · · Score: 2

      Title is kinda silly.. as the basic referenced statement is that in some cases python _is_ too slow but that one can work around that using hacks (or a language agnostic component oriented architecture).

      I don't really see it as a hack - it just means that Python can get on and do what it does well - letting the developer focus on the important higher-level stuff, and then if you need to focus on the lower-level to optimise, you do it in something designed for it.

      A lot of the (common) libraries out there are poorly documented, inconsistent, buggy, or incomplete.

      Really? I have never found this - generally I've found everything Python I've ever used to be really well documented - not that I often need to stray outside the standard library, but Sphinx provides a good toolset for creating really good custom documentation.

      As a Gentoo user, the python 2/3 thing is also especially annoying. Obviously this isn’t really python’s fault.. but it still gives me a bad taste about python.

      I presume you mean the default version of Python being 3 - maybe it's different under Gentoo, but I've found Arch Linux has handled this really well. Python 3 is the default and I havn't noticed any issues.

      --
      -- Lattyware (www.lattyware.co.uk)
    78. Re:007087 by icebraining · · Score: 1

      Maybe you should move past arrays and actually learn some data structures, if you think all an iterator does is "increment a pointer".

    79. Re:007087 by Daniel+Phillips · · Score: 1

      most people don't realize these were the same arguements given back in the 80s for writing stuff in assembly instead of C.

      And the argument failed because compilers were improved to the point that code quality became comparable to that of a naive assembly program. Python code quality has not improved into anything like the ballpark to overcome that argument. For many applications, Python is three or four orders of magnitude slower than C++. This is just embarrassing.

      --
      Have you got your LWN subscription yet?
    80. Re:007087 by marcosdumay · · Score: 1

      But once you start writing very formal Python where the type of every argument is declared in comments, and error handling being done with exacting precision and logging, and so on, you might as well be writing in C++ or Java.

      I can second that. Once you start writting Java in Python you may quite well start writting it in Java.

      It is hard to see that comming from a more structured language, but the entire point of Python is missed if you insist on only writting functions that can only accept a finite set of arguments and know their type at compile time.

    81. Re:007087 by icebraining · · Score: 1

      Can you iterate over values dynamically generated on demand by some function or class using the same syntax?

    82. Re:007087 by madprof · · Score: 4, Insightful

      I'm always wary of people who say a language "sucks". Each language was designed the way it as for certain reasons. You may not agree with those reasons but they are there.
      As it turns out I enjoy using Python quite a bit and it helps me get my work done nice and quickly, which mainly involves web code and associated sales processing. I could sit there and worry about what it can't do but what it can do is just fine.

      Obviously the bash comparison is nonsensical. Bash is hardly the same kind of language as Python and I think you know that.

    83. Re:007087 by lattyware · · Score: 5, Informative

      [Python is sometimes faster to write in.]

      Python isn't just fast to write though - it's fast and easy to read and understand, to work with, and it's very easy to keep code clear and well documented. I'm not saying these things are impossible in other languages, but in Python it is effortless, and enocouraged by the language. There are big benefits to using it besides simply 'fast to write'.

      --
      -- Lattyware (www.lattyware.co.uk)
    84. Re:007087 by Daniel+Phillips · · Score: 2

      The fucking language is designed to seamlessly use libraries written in C.

      It's hardly seamless. The glue layer is horrible awkward and hopelessly inefficient. Often that gets buried behind a SWIG autogenerated interface that produces truly putrid code. Orders of magnitude more than you would get from writing it by hand, and the hand written interface already sucks.

      --
      Have you got your LWN subscription yet?
    85. Re:007087 by icebraining · · Score: 1

      This code can be written by a child after a couple of minutes of explanation:

      print "Hello"

      Now translate that to assembly and count how many concepts the person would have to learn to write that code by themselves.

    86. Re:007087 by marcosdumay · · Score: 1

      That does explain everything!

    87. Re:007087 by Daniel+Phillips · · Score: 1

      Because we don't want to spend our time thinking about pointers and how to iterate over things?

      Whoops, you should have stopped with the "pointers". Because iterating over things in Python is very little different from C++.

      Because functional programming is actually really nice?

      Agreed, and C++11 supports it well.

      Because in Python, you can download some data from the web, analyse it using a machine learning algorithm, plot the results, and install another package on the fly, combining 4 independent packages, and many ideas, in just 50 lines of code.

      Sometimes. Sometimes not. It depends how well the libraries fit, just like C++.

      --
      Have you got your LWN subscription yet?
    88. Re:007087 by Anonymous Coward · · Score: 0

      Yeah, I get paid by the hour, so I'm completely unconcerned with development time. If my code is unreliable, or opaque, or difficult for the next developer in line to decipher, though, it's my ass.

    89. Re:007087 by russotto · · Score: 1

      Also most people don't realize these were the same arguements given back in the 80s for writing stuff in assembly instead of C, and given that people have moved on to C++ since with the same things being said 'If it's too slow in C++ then optimize that routine in C'

      Anyone who said "if it's too slow in C++ than optimize that routine in C" was not thinking straight. Anyway, C and assembler are at different levels of abstraction. C and Python, not so much. There's no great advantage to using python, except for lack of compile time.

    90. Re:007087 by Daniel+Phillips · · Score: 1

      ...you can put the Python monkeys to work on some parts, and put the C or C++ people to work on the performance-critical sections, and merge the two together.

      Be careful not to gloss over how much work that "merge" might turn into, with concomittant maintainability and reliability issues. I generally do not favor the idea of adding a new layer of bugs to a complex system.

      --
      Have you got your LWN subscription yet?
    91. Re:007087 by Daniel+Phillips · · Score: 1

      You can write something in python for 1/8 - 1/2 the cost (cost is a function of time) and optimize a tiny section of code or you can write it in C++ and get nearly identical performance.

      Let's just accept your magic numbers for the moment. If Python performance did not suck so badly, in many cases you could just drop that expensive and time consuming "optimize a tiny section" step and save even more money.

      --
      Have you got your LWN subscription yet?
    92. Re:007087 by Berfert · · Score: 2

      Its not about being good enough to write it in C or C++. It's about being more productive writing it in a higher level language and only taking the time to use something lower level when it's worth the cost to do so. You don't write in Python/Ruby/Tcl/etc because you're not good enough to write in C or C++. You write in them because you know they're a good tool for the job you're working on, to get it done quickly, cleanly, and maintainably. Sometimes, using more than one tool for the job at hand (ie, some C code at core parts) is necessary, but just because you need a manual screwdriver for one part of a job isn't reason not to use the power screwdriver for the other parts. Honestly, using a lower level language only where it's needed is an argument that many higher level, dynamic languages have been making for years (I know Tcl has). It was a perfectly valid argument years ago, and it's even more so now.

    93. Re:007087 by Anonymous Coward · · Score: 0

      *cough*moron*cough*

    94. Re:007087 by Anonymous Coward · · Score: 0

      It's not even that simple. If you want to use a processor's special extensions, I'm specifically thinking SIMD extensions (i.e. NEON on ARM chips; I think compilers can handle SSE, but can't remember), you sometimes need to use assembly.

    95. Re:007087 by narcc · · Score: 2

      the one working in python will literally run circles around the guy working in C/C++

      You should fire that python guy. Not only is he being unproductive, it's very disruptive and will likely really hurt the productivity of your other staff members.

      Oh, and the c/c++ thing makes you look like an idiot... Wait ... are you the guy running around that other developer?

    96. Re:007087 by Grishnakh · · Score: 1

      This is all theoretical, but if your project is already so large that you have a whole team of developers working on it together, I don't see how it's any worse from a maintenance and reliability standpoint to have it all in Python or to have parts of it in C++. The different devs have to create interfaces between the different sections anyway, so what does it matter what language one particular section is written in? You're already going to have those issues just by having a large, team project.

    97. Re:007087 by Anonymous Coward · · Score: 0

      When did I say it was? But let's be honest: for(;n!=NULL;n++){} is no more intellectually challenging than the basic and dead-common use-case for most iterators.

    98. Re:007087 by dkf · · Score: 1

      Personally my biggest complaint about python wasn’t on the list: A lot of the (common) libraries out there are poorly documented, inconsistent, buggy, or incomplete.

      That's true of so many libraries, not just for Python but other languages too. The more popular a language, the more you'll come across libraries for it that just aren't written to a high standard. The problem is the nature of poor programmers: they tend to gravitate to whatever they think is winning some kind of buzzword contest at the moment and their output is a POS in any language.

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    99. Re:007087 by GmExtremacy · · Score: 4, Insightful

      You don't need a CS degree to program in Python.

      This is true of any language. Degrees don't equal knowledge or experience.

    100. Re:007087 by icebraining · · Score: 1

      OK, now how does that work if you want to iterate over a dynamically generated sequence or a file read lazily without changing the iteration code?

    101. Re:007087 by Daniel+Phillips · · Score: 2

      I'm always wary of people who say a language "sucks".

      Well, if you don't know what I mean when I say "bash sucks" then you haven't written much bash. And by the way, it is in many cases the best tool for the job, but that does not mean it does not suck.

      --
      Have you got your LWN subscription yet?
    102. Re:007087 by shutdown+-p+now · · Score: 1

      Yes, absolutely, so long as the returned value is something that has members named "begin" and "end" (or global functions with the same names taking it as argument - used to enable arrays to work with this), which in turn return something that provides operators unary *, ++ and == (i.e. basically satisfy input iterator requirements). It's simply desugared down to the usual for-statement with explicit iterator.

    103. Re:007087 by smellotron · · Score: 3, Insightful

      Consequently most non-specialist programmers, even those who have done plenty of assembly work in their time, would produce slower final code today by hand-crafting their own assembly language than they would by writing in C and verifying the output of a good compiler to take care of the code generation.

      For the most part, the compiler kicks my ass at generating assembly. But every once in a while I find that I have programmed some construct that it's not very good at optimizing, or I've subtly surpassed some parametrized limit after which the compiler decides to stop optimizing. Or maybe I've forgotten to give the compiler the right hints for function visibility, pointer aliasing, or the like. Or heck, maybe I am making some meatspace assumptions that the compiler is not at liberty to make, and I need to find a way to codify the assumptions.

      In any case, I agree with you that the solution is almost always "tweak the high-level code until the compiler groks me" and not "discard the compiler and write some assembler"; but I find that the "blind trust" approach to compiler-assisted optimization leads falls apart pretty quickly. Always verify!

    104. Re:007087 by agrif · · Score: 1

      But once you start writing very formal Python where the type of every argument is declared in comments, and error handling being done with exacting precision and logging, and so on, you might as well be writing in C++ or Java.

      Minor quibble. That sounds a lot like you're writing Python like it is C++ or Java. Python is well suited to duck typing; generally (though not always) if you use isinstance(), you're doing something wrong.

    105. Re:007087 by Waffle+Iron · · Score: 1

      You mean something like this?

      new_mac = re.sub('(..)(?!$)', r'\1.', old_mac)

    106. Re:007087 by Anonymous Coward · · Score: 0

      tried that with the game I was writing using cocos2d.

      Ended up switching to c++ and using raw opengl. Instead of 15fps with hundreds and hundreds of effects, it's still at a solid 60 and I can focus on real logic instead of optimization.

      So python is easy up front, hard when you can't figure out any more hacks to speed it up another 5%.
      C++ is hard up front, hard to setup, hard to build a portable app.... but it's easy in the end since it just performs and performs.

      I learned an important lesson about this. Now I prefer c++ for games. I still use python a lot for work through.

    107. Re:007087 by thanasakis · · Score: 1

      +1. Not only that, but the new features introduced after 5.8 have to be explicitly enabled(perldoc feature to know how). Otherwise, the behavior is consistent with 5.8. Somebody took extra extra care so that there are no surprises after upgrades.

    108. Re:007087 by Anonymous Coward · · Score: 0

      No, that is not correct. Python doesn't "re-read the source files" "every time it runs". The interpreter compiles and caches bytecode files. Moreover, with the maturity of the PyPy project there is also a JIT interpreter. speed.pypy.org

    109. Re:007087 by Anonymous Coward · · Score: 0

      Most apps can be written much more quickly in Python than C/C++.

      Depends on your toolkit.

      Small scripts, sure, much faster to duke them out in Python. But if you have a larger piece of code, my main language ends up either Java or C++. Anything multithreaded can't use Python by definition.

      Scriptable toolkits have their place. Nothing better than having Javascript or Python scriptable part of your application. But main app, well, no (unless performance will NEVER be of any importance)

      Aside: personally I hate the forced formatting of Python, 2nd worst thing after lack of multithreading.

    110. Re:007087 by Anonymous Coward · · Score: 0

      ahh ... well I have not optimized to assembler since ahhhh - well hmmmm ... Multics!

    111. Re:007087 by smellotron · · Score: 1

      if you're skilled enough to write optimized code in C/C++, why fuck around with Python at all?

      Because Python is superior for prototyping an algorithm. As a skilled C++ programmer, I still recognize that it takes time to optimize and it's only worthwhile if the architecture is appropriate (solves the right problems, handles all edge cases and dark corners, uses appropriate data structures and algorithms). If I can bang out a Python implementation that does the right job slowly, the translation to a high-bandwidth or low-latency C++ implementation is usually a breeze.

    112. Re:007087 by Anonymous Coward · · Score: 0

      I have to disagree with that, a bit. C and old-style C++ has a lot of boilerplate allocate/release stuff going on, and yes that really slows you down making sure you got it right. But modern C++ RAII-style auto-everything code isn't like that.

      Python is often faster because:
      1) You needn't waste time on type declarations. There's no point in commenting types, especially if you use pylint or pyflakes. If you want types in Python, you want Cython, but even that's faster to code in than C or C++.
      2) Higher Order Functions are trivial in Python, and Higher Order Methods are practically identical. I'm currently working on Python code written by C++ developers who don't seem to realize that HOF's exist; instead they cut and paste and modify one or two lines in 20 or 30.
      3) Generators and Comprehensions make things fly by

    113. Re:007087 by siride · · Score: 1

      Libraries, flexibility and a different type model aren't worth it? A more straightforward syntax isn't worth it? Maybe Python isn't as far away from C as C is from assembly (though, to be honest, C isn't *that* far away from assembly, except in syntax).

    114. Re:007087 by siride · · Score: 1

      ReSharper nullifies this argument.

    115. Re:007087 by Anonymous Coward · · Score: 0

      Python was actually originally conceived as a language to sit between a *ix shell, and C.

    116. Re:007087 by RoccamOccam · · Score: 1
      Pretty straightforward version:

      newmac =str..join(':', [mac[0:2], mac[2:4], mac[4:6], mac[6:8], mac[8:10], mac[10:12]])

    117. Re:007087 by siride · · Score: 1

      Maybe the guy really is running circles around other programmers for fun or something.

    118. Re:007087 by Alef · · Score: 2

      The real reason why Python will still be slower than Java is because it's a much more dynamic language.

      That's actually a rather bad excuse. Dynamic languages don't need to be that much slower. For instance, have a look at JavaScript V8 or LuaJIT 2 for some incredibly fast dynamic language implementations. If I recall correctly, last time I checked, LuaJIT was about a factor 3 behind optimized C code in the median case on the Computer Language Benchmarks Game (although it seems to be no longer included in that benchmark for some reason).

    119. Re:007087 by shutdown+-p+now · · Score: 0

      That's actually a rather bad excuse. Dynamic languages don't need to be that much slower. For instance, have a look at JavaScript V8 or LuaJIT 2 for some incredibly fast dynamic language implementations. If I recall correctly, last time I checked, LuaJIT was about a factor 3 behind optimized C code

      Hence why I said "Python will still be slower", rather than "that's why Python is slow today". Today, it is of course slow just because it is a bytecode interpreter. But, as you say yourself, even state-of-the-art JIT compilers for dynamically typed languages like JS or Lua are still 3x slower than C/C++ - and I'd imagine that those are for typical well-written code that doesn't confuse the optimizer too bad.

    120. Re:007087 by Anonymous Coward · · Score: 0

      To be fair, they are both used as "glue" languages in the linux ecosystem.

    121. Re:007087 by Mr+Thinly+Sliced · · Score: 1

      Python was actually originally conceived as a language to sit between a *ix shell, and C.

      I think you got the asterisk in the wrong place, let me rewrite that for you:

      Python was actually originally conceived as a language to s*it between a Unix shell, and C.

      Which I confess, it does very well.

    122. Re:007087 by Mr+Thinly+Sliced · · Score: 1

      The real reason why Python will still be slower than Java is because it's a much more dynamic language.

      Well, that and the fact you can't use more than one core profitably in python without going out to native code....

    123. Re:007087 by Anonymous Coward · · Score: 0

      There's a difference in degree here. C/C++ compilers today are so good that most of the code they emit is as good as hand-optimized assembler. In many cases, they are better, because compilers will apply hundreds of little incremental optimizations that even the most skilled of assembler programmers will not (either because it would make the code less maintainable or because it wouldn't seem worth the effort). The few places you'd resort to assembler for performance tend to be where an expert can wring a little bit more speed out of a tight loop by using CPU-specific instructions (MMX/SSE in a Fourier transform, for example).

      Python, on the other hand, is still orders of magnitude slower than C/C++. Enough so that people generally don't consider implementing certain things (like, say, a video codec) in pure Python that you could straightforwardly do in plain C/C++, or else include significant amounts of C code just to make it performant (like, say, with PIL). This isn't true of faster interpreted and JIT-assisted languages like Java (FFMPEG and Vorbis, for example, have both been ported to Java).

      It also doesn't help that including C/C++ code can complicate the build process and make deployment a fair bit more difficult.

      In other words, Python has serious performance problems hampering its utility as a general-purpose language, but optimizing bottlenecks away with C/C++ is not practical. The language just needs to be faster.

    124. Re:007087 by Altrag · · Score: 1

      Well "cheap code" isn't really meaningful, but I'll take it to mean "fast" and/or "sloppy".

      But that's the great thing about languages like Python or C# or Java over C/C++ (and in turn, C/C++ over assembler) -- a lot of the detailed (and easy to screw up) work has been done for you either in the runtime or the libraries, allowing your programmers to make better code (or alternately, a boatload more sloppy code) in the same amount of time.

      And for 99% of the applications in the world, nobody gives a crap that it takes and extra quarter of a second to perform its task, making the performance of the compiler and/or virtual machine a whole heck of a lot less important. Computer time is cheap. Programmer time is expensive.

      But yes, you run across that 1% of cases where performance matters and you can't just reduce the problem complexity (in the big-O sense) with any amount of cleverness. And for those cases, they allow hooks into "faster" languages such as C linking to assembler modules (or even embedded assembly in many dialects) or Python linking to C modules.

      It happens and the language designers know it happens, so they've given you a way to handle the performance-sensitive parts of your program without having to spend countless extra hours (or months) writing the entire thing in some harder-to-use-but-theoretically-faster language.

    125. Re:007087 by wagnerrp · · Score: 1

      Because he has all that free time with which to do so, having completed his programming assignments much faster than his C/C++ counterparts.

    126. Re:007087 by Gibgezr · · Score: 1

      I like Python. I like C++. I sort-of like C.

      If Python were only 4 times slower than C++, it wouldn't be such a big deal. On things where speed really matters, Python seems to be a lot slower than that. Just to give an example off the top of my head, the other day I wrote a brute force decryption routine; the C++ version ran in seconds, the Python version took between 5-10 minutes on every run. Python is hella fun to code in, but it doesn't seem to be a language for heavy lifting. It makes a great scripting language, or a fun language to design and kick ideas around in.

      I've heard that pypy can help with the speed issue, though. I'll have to look into that.

    127. Re:007087 by Nursie · · Score: 1

      Stuff that runs in the server rooms is less than 1%?

      Fast, quality code is still needed in these situations. Developer productivity comes in second to speed and reliability in a lot of server situations.

      I am the 1%?

    128. Re:007087 by Nursie · · Score: 1

      I'm a C developer by trade.

      I can write something faster and in many less lines in python. If I'm doing toy projects or putting together simple utilities, it's brilliant. It's also pretty useful as a general scripting language.

      I wouldn't use it for performace-intensive code, but to knock something simple together in a limited amount of time? It's brilliant. You should give it a try.

    129. Re:007087 by youn · · Score: 1

      (((To verify that assumption, I suggest you try porting lisp to javascript)))))) ... oops, I got lost there in the parenthesis count... I am glad I will not be read by a lisp interpreter :)

      --
      Never antropomorphize computers, they do not like that :p
    130. Re:007087 by Anonymous Coward · · Score: 0

      Occupy Global Interpreter Lock!

    131. Re:007087 by TheLink · · Score: 1

      It'll be nice to be able to introduce the good old LISP "optimize" concept to python or similar.

      So that the compiler/JIT will only try extra-hard on the small section of code you really need to be fast.

      That way you can write most of your python program in whatever style you think suitable (idiomatic or not), but then at a crucial part you write it in a more easily JIT'ed way[1] and tell the compiler "make this bit really fast". And the compiler might spend 5 minutes on that small bit (exploring various possibilities) and while only needing 5 seconds for everything else. The result being equivalent to optimized C for trivial cases and close in not so trivial cases. After all why should c=a*b in python have to be slower than in C?

      The limitation might be only certain types of functions can be optimized, not just a section of the code. That way inside the function it could be really fast, you only pay some o(1) cost between the function and the rest of the python code. I bet many python programmers would be happy with that. Others might want the interactions with network and other IO to be optimizable too, but that might be trickier (though possibly more fun ;) ).

      [1] could provide some code guidelines and examples, and have the compiler have an option to provide performance warning messages when you have "make it fast" but something in the code prevents that.

      --
    132. Re:007087 by shutdown+-p+now · · Score: 1

      Cython aims to do something similar, but the code is not pure Python - it introduces some language extensions of its own - so the boundary between non-optimized-but-idiomatic and optimized-but-verbose code is a translation unit. It would be interesting to do something like that, but work directly with regular Python files, using standard decorators and annotations to drive the translator. I.e. you could have a .py file that has typical code, but then one function like so (note, all still valid Python):

      @optimize
      def foo(x: int, y: int) -> int
        return x+y

      and do an extra pass with a tool that finds all those @optimize declarations and spits out C code for them, taking into account all type annotations to improve codegen, such that the result is readily consumable as a Python module. Then, at runtime, @optimize would just throw away the function body, and replace it with the corresponding C function from that module.

      I don't think much would be needed beyond those annotations. Local variables can be type-inferred, and for cases where the right-hand side of the assignment to a local is of an indeterminate type (say, a Python function call), an explicit cast would suffice to indicate the expected type. Still, if needed, no-op functions can be provided for type asserts to be read by the translator, e.g. typed_local(x, int).

    133. Re:007087 by AzN1337c0d3r · · Score: 1

      Because Python's dynamic typing makes a maintenance nightmare when abused by poor programmers.

    134. Re:007087 by Anonymous Coward · · Score: 0

      Don't foret about the Global Interpreter Lock!

    135. Re:007087 by Anonymous Coward · · Score: 0

      Because it's significantly faster in terms of development time, or in terms of cost (having the less skilled, cheaper programmers work on it).... That's why languages like python and perl make doing so so simple.

      A few yeaars ago I would have aagreed. But times are changing. Today there are two things thaat lead me to disagree with you.

      1. Modern IDEs with good refactoring and code generation support are making static languages easier to program in. Eclipse does about half the work of writing a tyoical java program for me! Such systems are much less advanced for dynamic languages because they have a llot less information to work wuth... this is negating an awful lot of the advantage dynamic languages are supposed to have.

      2. z
      Finding developers who are competent to work with them can be a lot more expensive.

    136. Re:007087 by igomaniac · · Score: 1

      That's just bullshit - compilers often get it wrong because of things like alias analysis and register spilling/rematerialization. Not to mention the really crappy autovectorization they do. If you really care about performance you use vector intrinsics and check the assembly output of the compiler for any obvious cockups.
      There are also many programmers writing code for embedded procesors and DSPs that don't have compilers as mature as those for x86 and doesn't have any cycles to waste.

      --

      The interactive way to Go -- http://www.playgo.to/iwtg/en/
    137. Re:007087 by igomaniac · · Score: 1

      Yeah, C++ and Java is probably equivalent in the time it takes to solve the actual problem -- but then you spend 4 times as long debugging your C++ code because you have some weird write-past-the-end of an array or use-after-free bug that somehow works most of the time and when it goes wrong it only affects some completely unrelated piece of code from where the bug is that got it's data structures ruined. These classes of bugs can bring down novice programmers who can spend weeks trying to figure out where it's going wrong, and they just don't happen with Java or C# or Python.

      --

      The interactive way to Go -- http://www.playgo.to/iwtg/en/
    138. Re:007087 by vipw · · Score: 1

      I'd like to see some numbers for that bullshit.

      I'm going to assume that far more often is 99% of the time in about .01% of the code. This doesn't invalidate your point; it strengthens it. But it bothers me to see such a statement which seems so contrary to my experience and, dare I say, common sense.

    139. Re:007087 by TheRaven64 · · Score: 1

      I've hacked on the Python interpreter a bit for a customer, and it's shockingly bad code (and I'm no fan of the language either), but Guido is correct. Most applications spend 90% of their time in less than 10% of the code. It makes sense to use a high-level language and sacrifice performance for the 90% that is not performance critical, and use a faster language that lacks some of the high-level features for the 10% that is. Developer time - especially maintenance time - is expensive, so writing the bits that are not performance critical in a high-level language can save a lot of money without really impacting performance.

      --
      I am TheRaven on Soylent News
    140. Re:007087 by jbolden · · Score: 1

      He said 3 or 4 orders of magnitude, that's a casual way of talking about log base 10. I.E. his statement translates to 1000-10000 times slower, not 3 times slower. I actually assume it is more like 2 to 3.5.

    141. Re:007087 by jbolden · · Score: 1

      That's mainly because version 6 has taken so long. Perl 6 is not backwards compatible.

      As an aside there were some minor problems moving from 4 to 5. I caught the tail end of that.

    142. Re:007087 by TheRaven64 · · Score: 1

      Very rarely, though. On modern architectures, writing high performance assembly language requires a deep knowledge of how everything fits together. Compiler writers spend a lot of time becoming experts in this field

      Speaking as a compiler writer... yes and no. The compiler is only as good as the information that it has available to it. For example, I recently tweaked some of my code to be quite a lot faster than the compiler was generating, because I knew several things about the possible input data that were not possible to encode in C.

      The compiler has the advantage that it can often look at a large part of the code (including things that seem distantly related in the source) and can perform optimisations everywhere, where a human would probably only apply them in parts that were performance critical. The human has the advantage that the compiler has to be very conservative about the transforms it can apply. The compiler can only do optimisations it can prove - from the visible code - won't alter the program semantics. The human can take shortcuts.

      That said, it's very rare for even 1% of the total code to benefit from this kind of optimisation, and it's often already been written in assembly in things like math libraries.

      --
      I am TheRaven on Soylent News
    143. Re:007087 by Anonymous Coward · · Score: 0

      Not only that, but grandparent's assertion that

      "A lot of the (common) libraries out there are poorly documented, inconsistent, buggy, or incomplete."

      could not be further from my experience.

    144. Re:007087 by Anonymous Coward · · Score: 1

      Wow, when was the last time you studied optimization, the fucking 80's? I write real-time, embedded systems and I say, you're full of shit. Modern compilers do an amazing job at optimization, much better (on large system) than you'll ever do by hand. People think they know what they are doing, but they don't. With a modern processor, there is just too much to keep track of if you want efficient code. As for DSPs, I spent several years writing for those, and you're STILL full of shit.

    145. Re:007087 by bug1 · · Score: 1

      I suspect there are a lot of myths out there. I wonder if there have been objective studies done comparing the long term development resource required for High and Low level languages.

      Pretty much all languages have libraries available of existing work, so im not convinced there.

      If you need to learn a different language for 1% of your program you need to hire a programmer who isnt dedicated to splits his expertise, so suddenly that 1% of code is a bigger problem than before.

      My opinion is that the greatest limitation on any employable programmer is their ability to design, the way code is designed has more effect on the software than the language its written in.

      High level langues limit design possibilities so it eliminates extremes, with two designers of similar experience, the good designer will create a better product in the same time with a low level language. Of course the reverse is true also, bad designers dig themselves into holes with low level languages. High level language is a safe choice, like training wheels.

    146. Re:007087 by Courageous · · Score: 1

      Can a LUA object be treated like a hash table?

      I.e:

      myobject.i = 3
      j = myobject['i']

      Where j is then set to 3?

      Python treats all namespaces as hash tables, which makes optimization very difficult.

    147. Re:007087 by Anonymous+Brave+Guy · · Score: 2

      Sorry, but I think your information is at least 5-10 years out of date.

      Code generators in compilers obviously aren't perfect, and there are plenty of optimizations they don't do as well as they theoretically could yet. Still, compilers have been using the kinds of technique you describe for years now, even on some specialist chips used for embedding. I doubt many programmers, even those who work in the embedded space, have the skill to consistently outperform a compiler these days.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    148. Re:007087 by Anonymous+Brave+Guy · · Score: 1

      I completely agree with you. However, I think the long-term solution to that problem is to use higher-level programming languages that can express more advanced concepts explicitly, so the compiler can make more of the kinds of assumptions you're talking about. Training every programmer who wants to produce fast output code in the intricacies of modern process/memory architectures is not a viable long-term proposition; most programmers have other things to worry about. However, all programmers ultimately write their code in some language, so designing better languages and letting a few specialist programmers worry about implementing them is much more realistic.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    149. Re:007087 by Alef · · Score: 1

      Can a LUA object be treated like a hash table?

      Yes, you certainly can. In fact, that is a very fundamental concept in Lua, around which the entire language is built. It goes even further than Python: there are no other data structures than (hash) tables in Lua, not even arrays or lists (unless you count string). Classes and objects are implemented using tables and are thus fully dynamic -- the core language actually has no concept of objects at all, but is flexible enough to allow the user to implement object orientation.

    150. Re:007087 by Alef · · Score: 1

      I though we were discussing dynamic versus static languages, not interpreted versus native. I'm not going to deny that if you compare LuaJIT (dynamic language) to a state-of-the-art Java JIT interpreter (static language), Java wins. But not by any wide margin, especially if you consider that LuaJIT is developed by one guy (Mike Pall) more or less as a hobby project, whereas Java has received major corporate backing and development resources for more than a decade.

    151. Re:007087 by Alef · · Score: 1

      So that the compiler/JIT will only try extra-hard on the small section of code you really need to be fast.

      That's how JIT compiling interpreters typically work. Most code is interpreted -- only functions that are executed often gets translated to machine code.

      Some JIT compilers (called tracing compilers) take this a step further, and detect and translate hot code paths rather than functions. These paths can go across function calls, conditionals and loops, and as a result the most commonly executed code paths are essentially inlined as a machine code sequence. LuaJIT 2 is one example of a JIT compiler using this strategy. I believe Mozilla's TraceMonkey is another.

    152. Re:007087 by Courageous · · Score: 1

      Is the local stack context always treatable as a hash table also?

      I'm asking because while theoretically hash tables and simple object offsets are the same O(), pragmatically these things are expressed as O(1)+K, where hash tables are amortized O(1) with high K. Now as it so happens we know from years of lisp-family optimizing compilers that there are ways to optimize that, it's considered both very very hard as well as a bit of a lost art. One of the main reasons that python is slow is that every time you lookup a variable in any context it is actually a hash table lookup. Not to say that there isn't a way around this, but the optimizations for this are rather nightmarish.

      C//

    153. Re:007087 by TheRaven64 · · Score: 1

      True, to a point, but it eventually gets to the stage where you're implementing a compiler optimisation that is only relevant to a single program, and then there's little advantage in putting it in the compiler rather than the code. One of the things we're working on at the moment is a half-way stage, allowing you to write compiler transforms as plugins, so you can write optimisations for code - write in the high-level language and then a custom transform to do the optimisations you need. This means that you can have different people responsible for the high-level code and the optimisation.

      --
      I am TheRaven on Soylent News
    154. Re:007087 by Anonymous+Brave+Guy · · Score: 1

      That makes sense too. It's not that low-level optimisation isn't important any more -- on the contrary, as we increasingly rely on stacked architectures and intermediate steps like virtual machine bytecode, it's probably more important than ever -- I just think we need to change long-standing assumptions about who does it. I think we're both saying the same thing in the end: dealing with assembly-level optimisation is no longer a task that makes sense for most programmers, and is best left to specialists. My default "specialist" in this case is someone working on the compiler tool chain, but your idea of allowing pluggable optimisers creates a related role with similar requirements.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    155. Re:007087 by shutdown+-p+now · · Score: 1

      I though we were discussing dynamic versus static languages, not interpreted versus native.

      Let me just quote GGP (to whom I replied, and to which reply you then replied):

      Maybe I'm missing something here, but one big difference I see between Python and JVM, for instance, is that Python is an interpreted language, not a compiled one.

    156. Re:007087 by Anonymous Coward · · Score: 0

      Jersey girls aren't trash. Trash gets picked up.

    157. Re:007087 by Alef · · Score: 1

      I believe the local stack context in Lua is indexed. Because of lexical scoping, "local" variables don't necessarily reside on the stack, though -- they might be up-values captured by some function context which has subsequently escaped the stack frame where it was crated. I've never taken the time to learn exactly how they have solved that, but unless I'm grossly mistaken there are never any hash lookups for symbols that were declared local.

      Global accesses always result in a hash lookup, however. I should mention "global" in this context may still be rather local, as you can replace the global environment (which is just a hash table) rather arbitrarily, for instance giving a set of functions their own shared global sandbox.

      Nevertheless, I can't really see any reason why a language such as Python would fundamentally need to do hash table lookups for stack variables to keep its flexibility. It sounds more like bad language design. So I think my original point that dynamic languages can be fast still holds true (not that you were necessarily arguing against that).

    158. Re:007087 by Vanders · · Score: 1

      That's pretty much exactly what I ended up doing. Iterating over the string one character at a time (& printing a ':' every two characters) would have been far easier.

    159. Re:007087 by Courageous · · Score: 1

      Oh yes, certain varieties of smalltalk and lisp were known to be within 100% additional margin of compiled. Unlike Python which is 10X or worse (for the worst cases, such as benching a high N count for loop or what not).

      Python has some features which make it difficult to optimize, is all. I personally think you could write a near-Python that is less than 100% additional overhead versus C if one wanted to. There'd be compromises you'd have to make, however.

      There is the matter of most of the talent for such absolutely great compiled dynamic language optimization having been lost for the most part (IMO; admittedly I haven't been keeping track lately).

      C//

    160. Re:007087 by Anonymous Coward · · Score: 0

      What a pathetic rebut, saying languages suck is childish and simplistic. ... Oh wait I'm on the Internet, carry on.

    161. Re:007087 by bored · · Score: 1

      That is true when your ripping through a lot of code.

      If you have a routine consuming the majority of your time, it doesn't really take that much to rewrite it a few times in C look at the assembly outputs, run them through vtune, and try moving the bottleneck around with some custom assembly. Usually you can get a nice incremental improvement doing that, and sometimes doing that work forces you to rethink the problem and come up with a different way of approaching it that can yield multiple order of magnitude improvements. But without the time spent understanding the problem and the way it is behaving on real hardware, knowing which way to approach a rewrite isn't necessarily clear.

    162. Re:007087 by Daniel+Phillips · · Score: 1

      That argument defeats itself. If developer time is expensive, then it should not be wasted interfacing one language to another to overcome needless implementation deficiencies.

      --
      Have you got your LWN subscription yet?
    163. Re:007087 by TheRaven64 · · Score: 1

      Why do you think interfacing one language with another is hard? I'm pretty sure it's fairly easy for Python. The Smalltalk compiler that I wrote can seamlessly (and with no overhead) call Objective-C methods and C functions (actually, calling a C function form it is cheaper than sending a Smalltalk message). Taking a Smalltalk program, profiling it, finding the expensive parts, and rewriting those in C is a lot faster than writing the whole thing in C.

      Interfacing languages is a solved problem. It can be totally automated. Writing new code is not.

      --
      I am TheRaven on Soylent News
    164. Re:007087 by Anonymous Coward · · Score: 0

      Having straddled all three worlds for a long time, your assertion is far from generally being true. Factually, its almost always faster, usually by a minimum of 2x, to write in Python than it is to write in C++ or Java. It used to be that Java was more productive than C++, but modern coding styles and toolkits have leveled the field. I would even say C++ is typically even with Java, if not slightly better from a speed of creation perspective these days. There is just so much tedium in writing Java. That said, on an average day, a proficient Python coder is still roughly twice as fast as a C++ coder doing the same work. By far, its the exception rather than the rule for the speed of writing code in Python vs C/C++ to be on par. The safe assumption is 2x faster, on average, to write in Python than MODERN C++. If you're not seeing at least that, something with your process and/or coder is broken or you're using Python where its just a very poor match for the problem domain. Of course, it could be you're just an exceptional C++ coder and a crappy Python coder.

      That's just a fact of life. C++, for all the greatness, is still a relatively low level language. Python, by far, is a rather high level language with a very robust standard library. Meaning, all things being equal, typically the higher level language is faster to use. That is, after all, the primary purpose of a higher level language.

    165. Re:007087 by Daniel+Phillips · · Score: 1

      Why do you think interfacing one language with another is hard?

      Having a great deal of experience with it - it may be easy, it may be hard. Usually harder than you expect. But it is always a waste of time, if the only reason you are forced to do it is a language implementation deficiency. Which seems to be almost glorified by Python fans, but that is just stupid.

      --
      Have you got your LWN subscription yet?
    166. Re:007087 by Tough+Love · · Score: 1

      It was a typo, I actually meant 2-3 orders of magnitude. And yes, I mean 100-1000 times slower. Well, actual measurements show Python stuck overall about 2 orders of magnitude slower than C++ with some excursions out in the general direction of three orders of magnitude. That is for compute intensive work, which of course is the topic here. I personally have measured Python running up to a thousand times slower than C++, running things like the good old sieve bench.

      So no, expecting a Python program that actually does any significant amount of computation to come as close as 2-3.5 times slower than C++ is wild fantasy.

      --
      When all you have is a hammer, every problem starts to look like a thumb.
    167. Re:007087 by Daniel+Phillips · · Score: 1

      The Smalltalk compiler that I wrote can seamlessly (and with no overhead) call Objective-C methods and C functions.

      This is emphatically not the case with Python. The interface to c-linkage code is really, really, really show. Like having to process an ascii string to get at an integer parameter.

      --
      Have you got your LWN subscription yet?
    168. Re:007087 by jbolden · · Score: 1

      I meant 2 to 3.5 orders of magnitude. We aren't disagreeing.

    169. Re:007087 by Anonymous Coward · · Score: 0

      xs = [1,2,3]
      squares = [x * x for x in xs]
      print "\n".join(squares)

      Does anybody really think this is comparable with your code?

    170. Re:007087 by shutdown+-p+now · · Score: 1

      The main difference between this code and mine is the absence of type annotations. Well, there's is also that list comprehension. GP was talking about not having to "think about pointers", functional programming and iterating over things, all of which have been demonstrated.

      Also, I could print out the values more concisely than that - I just wanted to demonstrate the range-for loop. Idiomatic C++ would instead be:

      copy(xs.begin(), xs.end(), ostream_iterator<int>(cout, '\n'));

      For large number of elements, this would also be much more efficient, because it avoids constructing a temporary string from joined values to output.

      Ultimately, the point is that C++ version may well be more verbose, but it still uses all the same concepts - i.e. it's conceptually not lower-level than Python version. And yet it will run much faster (like, order of magnitude faster).

    171. Re:007087 by lgw · · Score: 1

      It will never be as easy to maintain code in a dynamically typed language as a statically type language. Python puts far less documantation about how a function must be called into the code itself, enforced by the compiler. It relies on comments where other languages give you compiler assistance.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    172. Re:007087 by lgw · · Score: 1

      If you don't understand what types the function accepts (and whether nulls are OK, and so on), no amount of ducks will help. Catching those very common errors at compile time is a Good Thing for maintenance.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    173. Re:007087 by SolitaryMan · · Score: 1

      IMO those are just examples of language either being generally fucked up or just not being the right tool for the job. If you are using the language in a way in which it is not supposed to be used, it does not make you more skillful, it makes you a fool. There are tasks that would require less skill to do in Assembler that in Perl (by your definition of skill).

      The assumption here was that both languages (Python and C++) were equally apt for the job.

      --
      May Peace Prevail On Earth
    174. Re:007087 by lgw · · Score: 1

      If your function needs a number for the first argument, it needs a number. Passing "green" is always going to fail. So how do you make sure the caller understands this - with comments, or in the code itself? Comments and code tend to diverge over time, so having it in the code itself makes it easier to maintain over time.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    175. Re:007087 by lgw · · Score: 1

      then you spend 4 times as long debugging your C++ code because you have some weird write-past-the-end of an array or use-after-free bug

      No. That's C code! And C++ written like C (which happens a lot). C++ done right simply doesn't have those problems. Really.

      These classes of bugs can bring down novice programmers who can spend weeks trying

      Yup, there's a learning curve with C++, to be sure.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    176. Re:007087 by lattyware · · Score: 1

      Really? Instead of having to make 50 interfaces, I just have to say 'any class that acts like x' - that's easier to maintain. No, it doesn't *force* you to maintain it, but do you really need to be forced to write good code?

      --
      -- Lattyware (www.lattyware.co.uk)
    177. Re:007087 by Grishnakh · · Score: 1

      The Anonymous Coward OP says that it doesn't take more skills to write the same operation in ANY language. I don't see how you're supporting his argument. Obviously, Assembly is generally not a good language for writing a lot of string-matching operations.

      Every language has its advantages and disadvantages, and as another said here, the idea that it doesn't require more skills to write a "hello world" program in assembly as in QBASIC is ludicrous and stupid.

    178. Re:007087 by lgw · · Score: 1

      Really? Instead of having to make 50 interfaces, I just have to say 'any class that acts like x

      Wait, isn't "any class that acts like X" the very definition of an "interface"? Maybe I'm missing your point here?

      No, it doesn't *force* you to maintain it, but do you really need to be forced to write good code?

      Ahh, a large project virgin. Imagine the codebase: much of it written by people who no longer work here, then maintained for years by people in the cheapest available country, whose manager shout at them hourly if that bug isn't fixed yet. Sturgeon's law prevails - 90% of the code is as crappy as the compiler allows it to be.

      Some quality can be maintained by objective, rigorously-enforced code review, but that means tons of boilerplate in any language, and the advantages of Python on small projects are drowned in the checklist.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    179. Re:007087 by SolitaryMan · · Score: 1

      If you get paid writing print "Hello" programs, please tell me where to sign up.

      (My point being that dumb artificial examples do not add any value to the argument)

      --
      May Peace Prevail On Earth
    180. Re:007087 by SolitaryMan · · Score: 1

      The idea that writing a real-world program in Python somehow requires less skills is equally stupid

      --
      May Peace Prevail On Earth
    181. Re:007087 by jgrahn · · Score: 1

      you can write the code in python several times in the same amount of time it takes to write it in C or C++.

      Or C++? Maybe if you don't know C++, otherwise I would have to say that is a wild exaggeration or at best an over generalization. I find that Python development generally progresses somewhat faster than C++, but not enormously faster. And the quality of result is generally better with C++.

      I know and like both languages, and I disagree. I can write idiomatic Python code significantly faster than the equivalent idiomatic C++ code. List comprehensions, duck typing, a much bigger standard library ... The problem, for me, with the Python code is that it's harder to maintain, due to the lack of static typing.

    182. Re:007087 by jgrahn · · Score: 1

      Also most people don't realize these were the same arguements given back in the 80s for writing stuff in assembly instead of C, and given that people have moved on to C++ since with the same things being said 'If it's too slow in C++ then optimize that routine in C'[...]

      I've never heard that last statement. It's rather well known that C++ is as fast as or faster than C.

    183. Re:007087 by eriqk · · Score: 1

      No, he really means "literally". I've seen python coders run circles around c coders several times, it's pretty disturbing really.

    184. Re:007087 by Tetsujin · · Score: 1

      You're missing something here. Python compiles to PYC files ("Python Compiled"). File timestamps are used to see if .PY code has been updated since the last compile to .PYC.

      It doesn't do a huge degree of "compiling" as I understand it, in large part because of the extremely dynamic nature of Python.

      --
      Bow-ties are cool.
    185. Re:007087 by Tetsujin · · Score: 1

      Because he has all that free time with which to do so, having completed his programming assignments much faster than his C/C++ counterparts.

      And since he now has to wait for his program to run, he has even more time to kill!

      --
      Bow-ties are cool.
    186. Re:007087 by Anonymous Coward · · Score: 0

      And those same benefits are given by languages like ocaml and haskell, while offering performance only 2-3x worse than C instead of 50 times worse than C like python.

    187. Re:007087 by lattyware · · Score: 1

      I'm sorry, are you actually trying to say Haskell is as easy to read and write as Python? I can't even begin to describe how much I disagree with that.

      --
      -- Lattyware (www.lattyware.co.uk)
    188. Re:007087 by Anonymous Coward · · Score: 0

      No, I am not trying to say that. I very clearly did say it. Haskell is generally cleaner and easier to read than python, as it offers more powerful abstractions while being incredibly similar syntactically. You are confusing "I don't know haskell so I don't understand haskell code" with "haskell code is hard to understand". Just because you haven't learned to read kanji doesn't mean it is hard to read.

    189. Re:007087 by lattyware · · Score: 1

      Ah, but that's the issue. Python is designed to be obvious - most of Python works how you'd expect it to, not as a programmer, but as a person. Haskell is very much a language you need to learn - and while I don't claim any great level of experience with it, I have done enough with it to know this much - it's simply not as clear. Sure, after a lot of time learning it and getting used to it and the concepts behind it, it might be easy to work with, but it's not clear at that starting level.

      Which is more obvious [number+1 for number in numbers if not x == 0] compared to [number+1 | number ? The Python reads better. This may not be too important for a single line of code, but reading through an entire application, Python is much easier to work with.

      Moving on from that, while functional languages allow for graceful descriptions of some problems, they don't express most problems in a way I find natural, and others I have talked to agree with me on this. Again, you can teach yourself to think in the right way, but why?

      Python also provides a lot of flexibility and power, there is a massive standard library to do a variety of complex tasks (everything from pulling web pages; parsing XML, JSON, CSV; through to decompressing data) very easily. Python makes writing applications to do what you want extremely quick and easy, and then keeps them easy to maintain and update.

      I'm not saying it's the only language worth using, I'm not saying that it's perfect for every job, but Python is an excellent language that more than justifies it's slower execution speed - which is a minor problem in most cases.

      --
      -- Lattyware (www.lattyware.co.uk)
    190. Re:007087 by Anonymous Coward · · Score: 0

      No, python is not obvious. Python seems obvious if you already have a background in imperative programming. There is a huge difference. And your list example is terrible as python comes out clearly worse in that comparison. Adding extra words doesn't make the code clearer, it makes it longer.

      Functional languages don't fit your existing imperative bias, that doesn't mean it is "natural" or "unnatural", it means you learned one way and not the other. And I already explained the reason to teach yourself "to think the right way", because you get to use a vastly better language that lets you write the same amount of code as python, while getting an order of magnitude less bugs and an order of magnitude better performance. The fact that it will make you a better python programmer as well is a nice side benefit though.

      I know you are saying python justifies its slower execution speed. And I am refuting exactly that claim. It has execution speed 10-30 times slower than other languages with the same expressive power. So "it is highly expressive" fails as a justification for the terrible performance.

  2. Yeah, right by stanlyb · · Score: 0, Flamebait

    Like what, calculator? Or Spreadsheet? Or gmail.com? Now i see why Google does not have any C/C++ developers

    1. Re:Yeah, right by jmerlin · · Score: 1

      Have you seen V8, BigTable, etc?

    2. Re:Yeah, right by WilCompute · · Score: 1

      Wait, Google doesn't have any C/C++ developers?! But, how do they contribute to projects like LLVM and Linux. How did they create the Native Client for Chrome?

      There abilities just went up by major points in my book!

      O_o

      --
      NDxTreme Content on the Edge.
    3. Re:Yeah, right by NatasRevol · · Score: 1

      Duh!!

      It's not Chrome, it's Chrome.py

      --
      There are two types of people in the world: Those who crave closure
  3. Language Philosophies by Anonymous Coward · · Score: 1

    How much of Python is just straight-up "slow", and how much comes from the fact that Python devs prioritize readable code over efficient code? In C, you usually try to squeeze as much memory out of each line as possible, but Python is designed to be human-readable first and machine-executable second.

    1. Re:Language Philosophies by timothyb89 · · Score: 1

      Strictly speaking, the language itself shouldn't have any effect on how fast it executes, it's the implementation that really matters. Some languages might be more difficult to parse but in the end it's what the interpreter does with it that really matters. The whole sentiment that "fast code equals C/C++" is a little fishy to begin with, modern interpreted languages compile down to machine code via JIT anyway and often don't have a significant performance decrease compared to the same code in C/C++. Not that I'm against the notion completely, as native code (and specifically native code modules embedded in other languages) has its benefits, but it shouldn't be used as an excuse for a slow interpreter.

    2. Re:Language Philosophies by Teckla · · Score: 3, Informative

      Strictly speaking, the language itself shouldn't have any effect on how fast it executes, it's the implementation that really matters.

      This is nonsense.

      Language syntax has a huge impact on how hard or easy it is for a compiler (ahead-of-time, just-in-time, or hybrid) to produce fast native code.

      If that effort is too large, in terms of development effort and/or compiler analysis effort, you will simply never see a compiler written for those kinds of languages that produces fast executables. This is the reality.

      So, in pragmatic terms...yes, some languages are slow.

    3. Re:Language Philosophies by Anonymous Coward · · Score: 0

      This is nonsense.

      Language syntax has a huge impact on how hard or easy it is for a compiler (ahead-of-time, just-in-time, or hybrid) to produce fast native code.

      Not only that, it may also be provably imposible to prove properties of the program in certain overly expressive languages, and then you simply cannot optimize it.

      I haven't seen a thorough analysis of Python, but I did see a superficial one that indeed found lots of issues with static analysis of python code. Dynamic analysis is another matter, check pypy.

    4. Re:Language Philosophies by Anonymous Coward · · Score: 0

      Two words: You're wrong.

    5. Re:Language Philosophies by marcosdumay · · Score: 1

      In Python everything is a string, and everyhing is kept in a hash table somewhere. There are no symbols and no constants at the interpreter. Python will never be fast.

    6. Re:Language Philosophies by styrotech · · Score: 1

      In Python everything is a string

      Huh? Not even close.

      It sounds like you're thinking about TCL rather than Python.

    7. Re:Language Philosophies by smellotron · · Score: 1

      In Python everything is a string

      Huh? Not even close.

      I believe the GP is referring to how variables are referenced from within the program. Consider the code import re; re.compile("...") (and sorry in advance if I miss any gritty details): the re.compile lookup first searches for "re" in the local and global symbol dictionaries, then once it finds one it searches for "compile" within that dictionary, then it searches for "__call__" within that dictionary, then it invokes the result as a function. So in that sense, the language is dictionaries all the way down. It also means that you can micro-optimize python code by creating local references to deeply.nested.things.in.modules to avoid doing the entire lookup chain in a tight loop.

      Contrast this with dynamically-linked executables (e.g. C-family and probably anything else that requires a linker), where only undefined functions/variables are strings that need to be looked up in a symbol table. In this system there is one symbol dictionary per executable/shared-library, and any run-time name lookups occur on first load or first use. All other function and variable references are resolved into addresses at compile- or link-time.

    8. Re:Language Philosophies by dkf · · Score: 1

      In Python everything is a string

      Huh? Not even close.

      It sounds like you're thinking about TCL rather than Python.

      It's not especially accurate about Tcl in the past decade or so either, where values are dynamically tagged with an interpretation that makes repeated accesses efficient. It's a string the first time (well duh! you typed it or had it saved in a file!) but afterwards it's fast as the implementation code can check type-correctness with a single comparison. (Well, there's more to it than that when dealing with numbers or dynamically-recompilable code but the principle still holds.)

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    9. Re:Language Philosophies by Anonymous Coward · · Score: 0

      The thing is, most computing doesn't require anything fast. That's a myth. Which means, for the majority of programs, even though Python isn't the fastest, its all too often fast enough. Furthermore, aside from a few tiny nitches of computing (scientific/computation sciences), a tiny portion of the actual program is what slows everything down. So by combining the best of both worlds, you get rapid development, easy to read and maintain code, and only a tiny section of code which isn't python and you still get the required performance. And if you need help with the scienfic aspect of things, there are already tons of highly optimize libraries which are easily accessable via python; meaning they are really, really fast. Which is, of course, why python is popular in scienfic circles.

      About the only thing Guido really screwed up royally with Python is threading. They insist on making it a second order feature when it needs to be treated as a first order feature. And they did this specifically because he doesn't like and is afraid of threads. So because of his biases ignorance, anyone who wants to do threads on Python suffers. And yes, I know about processing, etc., but they are a pain in the ass compared to threads. And no, jython is not an opion for any serious application because its so slow. Jython on average is 4x slower than cpython. Which means, on average, you need to have four cores pegged and everything running concurrently just to break even with cpython. Its a joke and a solution in search of a problem. Interestingly enough, jython's performance problems and implementation details are precisely by cpython avoided that implementation approach fromt he beginning.

  4. Agreed. by Anonymous Coward · · Score: 5, Insightful

    Now that that is settled we can get back to the real problem with python: Type errors.

    1. Re:Agreed. by Anrego · · Score: 0

      That was covered in the article as well (kinda) .. with the same kind of "just do more testing" type answers you hear from the PHP guys.

      Personally I like my languages strongly typed, with as much idiot proofing and compile time checking as I can get and still have a usable language. Not as a substitute for testing/QA as the article would imply.. but as an additional layer.

    2. Re:Agreed. by randallman · · Score: 5, Informative

      Python is strongly typed. Maybe you mean statically typed.

    3. Re:Agreed. by thetoadwarrior · · Score: 0, Flamebait

      As someone who's worked with Python for years both in personal projects and professionally, I've never had an issue with that. Maybe python attracts more intelligent programmers than the dime-a-dozen .Net / Java programmers being pumped out of university.

    4. Re:Agreed. by Anonymous Coward · · Score: 0

      Python IS strongly typed. It isn't statically typed.

    5. Re:Agreed. by Wattos · · Score: 1

      As someone who's worked with Python for years both in personal projects and professionally, I've never had an issue with that. Maybe python attracts more intelligent programmers than the dime-a-dozen .Net / Java programmers being pumped out of university.

      just as javascript and php does ^^

    6. Re:Agreed. by Anonymous Coward · · Score: 0

      same thing C coders said about C++

    7. Re:Agreed. by tpotus · · Score: 1

      True, and like the saying goes; Never a mod point when you need one.

    8. Re:Agreed. by Teckla · · Score: 1

      That was covered in the article as well (kinda) .. with the same kind of "just do more testing" type answers you hear from the PHP guys.

      Personally I like my languages strongly typed, with as much idiot proofing and compile time checking as I can get and still have a usable language. Not as a substitute for testing/QA as the article would imply.. but as an additional layer.

      Well said. Developers should think of static typing and strong typing as testing built right into the code -- testing your boss can't make you skip writing in order to meet a deadline, because if you have type errors, your code will not even compile.

    9. Re:Agreed. by sjames · · Score: 2

      You can do a few interesting things with duck typing that don't work very well in a static type system. My object may not be a foo, but it does have a bar method that needs calling and that's all that matters. If it bothers you, just type check it: if not has_method(var, 'bar'): or just catch the exception.

      It's better than C++ where you cast a pointer and the code happily treats random gibberish as the type you cast to.

      That said, a static analysis tool would be a nice thing to have.

    10. Re:Agreed. by Teckla · · Score: 2

      As someone who's worked with Python for years both in personal projects and professionally, I've never had an issue with that.

      Because your anecdotal experience means that the debate is over. Your single, biased data point is plenty to draw sweeping conclusions.

      I hope you write better program logic, because your logical thinking skills are definitely lacking.

      Maybe python attracts more intelligent programmers than the dime-a-dozen .Net / Java programmers being pumped out of university.

      Oh. You're one of those "I'm smarter than everyone else" types.

    11. Re:Agreed. by thetoadwarrior · · Score: 1

      You're right and I don't have problems with those either. A lot of people do because both those languages attract newbs. But guess what, newbs fuck things up in strongly typed languages too.

    12. Re:Agreed. by LDAPMAN · · Score: 1

      The real problem I have with it is that white space is syntactically significant. This makes drives me up a wall....especially when using a basic text editor.

    13. Re:Agreed. by Anonymous Coward · · Score: 0

      Google has practically moved away from Python because it has a shitty implementation and dynamic typing. I guess they're just idiots right?

    14. Re:Agreed. by thetoadwarrior · · Score: 1

      Feel free to prove me wrong. Thousands if not millions of people get by just fine with Python. Even PHP, which perhaps attracts more idiots than any other language and has loads of issues probably wouldn't be any better at all if it were strongly typed and there is nothing that stops you from validating your types and handling incorrect types in Python.

      I'm no better than anyone that genuinely enjoys programming but yes, I am better than someone who doesn't really care about programming and is only in it for the money. It stands to reason that in any trade someone who cares about it will be better.

    15. Re:Agreed. by Anonymous Coward · · Score: 0

      > My object may not be a foo, but it does have a bar method that needs calling and that's all that matters.

      Scala does exactly the same thing, and it also needs no extra declaration boilerplate to make that happen.

      "Duck typing" is really more like "if it walks like a duck, and quacks like a duck, just go ahead and interrogate every damn thing to make sure if it really is a duck because sometimes you want to pass in a donkey anyway and it's better to just break at runtime even if the code could have never worked"

      Sorry, the analogy runs off the rails there. True duck typing is type inference.

    16. Re:Agreed. by Anonymous Coward · · Score: 0

      Google for pylint.

      Then google for "manifestly typed".

    17. Re:Agreed. by Anonymous Coward · · Score: 0

      There are libraries that do type analysis for python. It's not impossible, it just could benefit from type annotations, there's even a PEP for supporting them.

    18. Re:Agreed. by sjames · · Score: 1

      If the needed method is 'walk', then a donkey might well do the job. No need to interrogate quack if I won't be needing it to make a sound.

      Meanwhile, in Python, I can potentially teach a particular donkey to quack at runtime with donkeyobject.quack=Duck.quack (provided quack is fairly self contained).

    19. Re:Agreed. by Anonymous Coward · · Score: 0

      Instead you just miss your deadline because you are going through contortions to wrestle with the type system to do something which can be expressed very simply.

    20. Re:Agreed. by Anonymous Coward · · Score: 0

      So, I take it that you don't indent anything in whatever language you use? All Python did was turn something that every programmer already does when using a language with block structures and codified it in the syntax.

    21. Re:Agreed. by thetoadwarrior · · Score: 1

      How have they moved away? I've seen no signs of that and in fact they've finally bumped AppEngine up to 2.7. Not that I'd go back to it largely because the only way to contact Google for support is through their rubbish support forums which is still done in python btw.

      Personally I would have expected a bigger conversion to Go within Google purely to promote it more.

      And btw, I don't dislike using static typed languages. I just don't dismiss dynamic typed languages because both sorts of languages can easily produce solid code and idiots and produce shit in both.

    22. Re:Agreed. by shutdown+-p+now · · Score: 1

      You can do a few interesting things with duck typing that don't work very well in a static type system. My object may not be a foo, but it does have a bar method that needs calling and that's all that matters.

      You can statically type things like that, you just need structured typing for objects. E.g. in OCaml, the following:

      let foo x y = x#bar y;;

      defines a function taking x and y such that x is an object having method bar, that takes a single argument of the same type as y. Note that this is actually a static type, and it will be verified at compile-time when you invoke it. The return type of foo will also be the same as the return type of x#bar, and that is also statically computed for every call site and used in further type checks.

    23. Re:Agreed. by ceoyoyo · · Score: 1

      Agreed. Perhaps those of us who learned to program in Assembler are just used to not depending on the compiler to make sure we don't do anything stupid.

    24. Re:Agreed. by ceoyoyo · · Score: 1

      Ah, no. The best feature ever. Everyone's code is either readable or doesn't run. Awesome.

      If white space is driving you up the wall you're clearly using spaces instead of the tabs the diety intended.

    25. Re:Agreed. by ultranova · · Score: 1

      Meanwhile, in Python, I can potentially teach a particular donkey to quack at runtime with donkeyobject.quack=Duck.quack (provided quack is fairly self contained).

      But if quack is self-contained, how is this useful? Why would whatever function you're passing donkeyobject to call donkeyobject.quack() rather than quack(donkeyobject), if quacking is self-contained enough to be crafted into generic donkeys just like that?

      Besides, there is no reason why a static type system can't simply take function assignment into account when determining the type of an object.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    26. Re:Agreed. by sjames · · Score: 1

      Real world example, I sometimes stuff a readline method into a socket object to make it look enough like a stdin file object. Both of those are part of the standard library. I don't want ALL sockets to have a readline and if I accidentally pass one in that shouldn't do that, it's preferable to have it throw an exception. Note that I only know if the socket should or should not readline AFTER I instantiate it and begin the protocol init.

      As I said, a PARTICULAR donkey. Perhaps I don't want all of the donkeys quacking. I certainly don't want to pollute the namespace with the function when I can keep it confined to where it's relevant.

      Perhaps I want to make a pig sound more mallard-ish.

    27. Re:Agreed. by icebraining · · Score: 1

      You should check out Go: it's essentially static duck typing. You can pass any type of a function as long as it implements all the methods that function uses, but all is checked at compile time.

    28. Re:Agreed. by Coryoth · · Score: 1

      Personally I like my languages strongly typed, with as much idiot proofing and compile time checking as I can get and still have a usable language.

      So I take it you use SPARK/Ada, or Java with JML and ESC/Java2, or C/C++ with Frama-C? I mean there's way more static compile time checking you can do with a little bit more comprehensive annotations than just types (say a nice formal language with appropriate first order logic quantifiers).

    29. Re:Agreed. by Anonymous Coward · · Score: 0

      So, I take it that you don't indent anything in whatever language you use?

      Just because somebody dislikes Python's whitespace requirements doesn't mean he also dislikes indentation.

      I dislike the whitespace because there is no end marker for blocks. This means, in part, that my editor cannot figure out where a block ends. If I'm auto-indenting code, it falls apart on Python. I have to be careful and select just the block that needs indenting before I hit > or <. If I'm pasting code, I can't just highlight it and hit =. I have to remember to turn "paste" on and off, and then manually make sure the indentation level of the whole new block is right. With most languages I can just paste, highlight, and hit =.

      I also find it much more tedious to hit C-t or C-f (my mappings for "move in/out one indentation level" than } (for C) or end (for Ruby). Why? I don't know, but I often find myself cursing Python over this.

      I wouldn't mind it at all if there were forced indentation but also end-of-block markers. I always indent, but I hate Python's whitespace requirements. OK? Can you just accept that not everybody shares your style preferences?

    30. Re:Agreed. by Anonymous Coward · · Score: 0

      Agreed.

      I use Microsoft Word for my programming and I have no end of problems with languages like Python.

    31. Re:Agreed. by mbkennel · · Score: 1

      It's a PITA for machine-generated source code, and given that Python is an interpreter, this seems like an important use case.

    32. Re:Agreed. by Anonymous Coward · · Score: 0

      I'm not sure about the implementation issues, but barely anyone at Google uses Python anymore and there have been several internal memos about not starting new projects with it. I believe one of the earliest memos was even leaked publicly on Hacker News.

    33. Re:Agreed. by smellotron · · Score: 1

      It's better than C++ where you cast a pointer and the code happily treats random gibberish as the type you cast to.

      Funny that you mention C++ instead of C for this argument. In C, pretty much all you can do is cast the pointer and cross your fingers. In C++, you can correctly handle run-time polymorphism with dynamic_cast (or just use a virtual function to begin with, dynamic casting is usually a code-smell); or you can handle compile-time polymorphism with templates which rely on more-or-less the same duck typing that Python does. The compile-time polymorphism is admittedly much hairier (cryptic syntax, potential surprises from ADL/Koenig lookup, and some nastiness with function overloading vs. template specialization), but your characterization of C++ sounds like a straw man borne out of some unnecessarily bad programming experience.

    34. Re:Agreed. by sjames · · Score: 1

      It's no straw man. All of that is just a thin veneer over type casting. If C++ is polymorphic, Python is metamorphic with proper reflection. It won't get even slightly confused if I create an array of arbitrary objects for example. I can then scan the list and call the run method on just those objects that happen to have such a method. Later, without touching that code again, I can define another class with a run method and it all still works. I can stuff a run method into an object whose class doesn't have a run method. I can override the run method of a particular object whose class does have a run method. I need not have anticipated all of the potential object types the callrun function might encounter.

      Necessarily, you can do that in c++ if you use enough bailing wire and duck tape (since C++ can compile to C and at least one Python interpreter is written in C), but it starts to look like a 2nd rate implementation of Python (without the proven history) at that point.

    35. Re:Agreed. by Raenex · · Score: 2

      Thousands if not millions of people get by just fine with Python.

      Yes, and the same goes for C/C++ or Java. The code for the moon landings was also written in assembly. The simple fact is that you can get the job done in any language, but that doesn't mean there aren't advantages and disadvantages to particular languages.

    36. Re:Agreed. by Anonymous Coward · · Score: 0

      Go is interesting but they fucked it up by insisting on a terrible indent style.

    37. Re:Agreed. by smellotron · · Score: 1
      You've successfully described how reflective Python is. I don't disagree or attempt to claim otherwise.

      C++ where you cast a pointer and the code happily treats random gibberish as the type you cast to.

      This is a strawman. This is a language feature for portability with C that only shows up in poorly-written C++ programs.

    38. Re:Agreed. by sjames · · Score: 1

      Or if you try to do anything "interesting". Besides which, I see it plenty. Perhaps it's just a crap-ton of really bad C++ code. It's not my code and it's not a strawman. It is a documented "feature"

    39. Re:Agreed. by Peter+Harris · · Score: 1

      Most runtime errors in carelessly-written Python are not TypeError. Usually it will be AttributeError or NameError.

      There are good reasons why the Python compiler doesn't reject a program just because it can't *prove* that it's valid. You can always use pylint to warn you about things you might be doing wrong, and it's pretty good at it.

      This is a design choice about the tools used for developing in Python, not necessarily a problem in the language itself.

      --

      -- What do you need?
      -- Gnus. Lots of Gnus.
    40. Re:Agreed. by indeterminator · · Score: 1

      The real problem I have with it is that white space is syntactically significant. This makes drives me up a wall....especially when using a basic text editor.

      If you cannot make your intendations match you need to cut down substance use, or get stronger glasses. No matter what language you write in, your intendation must be correct to pass the "does it look like crap" test.

      (because in 9 out of 10 cases, if it looks like crap, it is crap)

    41. Re:Agreed. by smellotron · · Score: 1

      Or if you try to do anything "interesting".

      Which usually is the type of thing you simply cannot do in Python, such as deliberate aliasing to avoid copies or known downcasts based on meatspace knowledge (i.e. compiler can't optimize away the RTTI lookup for dynamic_cast, but programmer knows that static_cast will always succeed because of some external constraint). But that is neither here nor there. Your assertion appears to be that Python has safe dynamic run-time type support, and C++ only has raw pointer casts. Yet, C++ specifically added the features I mentioned so that programmers could get more of the "Python" safety you espouse, and less finger-crossing with C-style casts. But the old behavior still exists for backwards compatibility and for extreme optimization (because really, dynamic_cast shouldn't ever be the bottleneck). So that is why I am calling your argument a strawman: you are ignoring critical language features in order to make your point! After all, one could also cherry-pick the worst of Python: code which doesn't handle duck-typing gracefully, in particular anything that assumes values are floating-point numbers without doing anything to "coerce" them. The whole thing with / vs. // in Python3 is focused on this particular issue.

      Your argument would be better suited against C. C++ is a different beast.

    42. Re:Agreed. by sjames · · Score: 1

      Yes, C++ bolted a great many things on later. Many of them 'feel' like they're duck taped on. The point you're missing w/ C++ is that ALL of that flexibility goes POOF! as soon as you compile. Whatever types were referenced then are the ones that compile in. In Python, types are fully malleable. Old modules can deal with novel classes and objects without any special pre-arrangement other than the programmer knowing what he's doing and making sure that either the types being passed in have the needed attributes or that exceptions arising from mis-matches are caught and handled in a reasonable way. Try that in C++ and you won't get graceful handling, you'll either crash or you'll be forced to obfuscate the program logic in a bunch of scaffolding.

      Python doesn't have to care if a foobar is descended from a baz, just that it has method X. Even if a module is inmplemented in C, it doesn't need a re-compile to do the right thing with a foobar even if it was compiled before foobar was defined.

      That doesn't mean C++ has nop place in the world, just that it isn't a substitute for Python.

    43. Re:Agreed. by Anonymous Coward · · Score: 0

      And Armstrong had to take control because the assembler monitor was flooded with interrupts and didn't know how to handle them Sound familiar?

    44. Re:Agreed. by sjames · · Score: 1

      That certainly looks like a step in the right direction. It is a bit different in Python since x may be instantiated from a class that has no bar method, but it can acquire one later:

      x.bar = lambda x: fn(x)

      In that case, x but no other instantiation from it's class will have bar.

    45. Re:Agreed. by PCM2 · · Score: 1

      Google has practically moved away from Python because it has a shitty implementation and dynamic typing. I guess they're just idiots right?

      Where are you hearing that? Maybe for consumer-facing applications, but tons of internal tooling at Google is still done in Python. Plus they don't pay Guido for nothing.

      --
      Breakfast served all day!
  5. It's like they always say... by Anonymous Coward · · Score: 0

    Two languages are better than one!


    ...Right?

    1. Re:It's like they always say... by NatasRevol · · Score: 0

      Two ladies are better than one!

      3 weeks a month. Then things get slow. Just like Python.

      --
      There are two types of people in the world: Those who crave closure
  6. Logically Logical Logic by l0ungeb0y · · Score: 5, Funny

    "It is usually much more effective to take that one piece and replace that one function or module with a little bit of code you wrote in C or C++ rather than rewriting your entire system in a faster language"

    Ahh -- yes, I see, so I should write my Apps in Python, except where they need to be rewritten in C/C++ because that will run faster than when written in Python, but Python is not slow when you rewrite portions -- so don't rewrite in a faster language because Pyton is fast enough.

    Alrighty then.

    1. Re:Logically Logical Logic by Cogita · · Score: 5, Insightful

      Ahh -- yes, I see, so I should write my Apps in Python, except where they need to be rewritten in C/C++ because that will run faster than when written in Python, but Python is not slow when you rewrite portions -- so don't rewrite in a faster language because Pyton is fast enough.

      Alrighty then.

      Essentially yes, that's it exactly. It's a lot simpler to write a 5000 lines of python and 300 lines of C than it is to write 20,000+ lines of C. Plus Python manages most of the memory management for you so you have less chance of memory leaks. I would argue that the reduction in bugs memory bugs and more maintainable code would justify saying that one should use two languages in this case. It's not a matter of which is better overall, it's that python is easier to read, whereas C is faster. Use both where their benefits are most powerful.

      --
      -- "The Price of Freedom of Speech, of Press, or of Religion is that we must put up with a good deal of rubbish."
    2. Re:Logically Logical Logic by Frnknstn · · Score: 5, Informative

      Yes, that is correct. You should write your apps in Python.

      Your libraries, you should write in Python first, because it is also a great prototyping language. If they work fine (which they will in most cases) you have saved yourself a bunch of time. If they are too slow, you have saved yourself a bunch of time by fixing algorithmic bugs in a flexible language like Python. It is now trivial to convert it to bug-free C or C++.

      --
      If it's in you sig, it's in your post.
    3. Re:Logically Logical Logic by vgerclover · · Score: 1

      What you are missing is that you can easily connect to C/C++ code from Python and vice versa. So you can write all your code in Python, find through profiling which small pieces of code are hot/heavily used, and replace that with C code.

    4. Re:Logically Logical Logic by Anonymous Coward · · Score: 0

      Yes. C does not have any libraries you could use. And automatic memory management is always a good idea... it is of course not possible to know better than the garbage collection how to manage memory.

    5. Re:Logically Logical Logic by Lunix+Nutcase · · Score: 1

      Plus Python manages most of the memory management for you so you have less chance of memory leaks.

      And so does C++ if you use the language as you are supposed to rather than writing C code and compiling it as C++.

    6. Re:Logically Logical Logic by Terrasque · · Score: 2

      So you can write all your code in Python, find through profiling which small pieces of code are hot/heavily used, and replace that with C code.

      Or write it a bit smarter. There was a poster on one forum that had a python program doing some image processing. Basically finding the nearest pixel from center within a certain variance of a color.
      It took ~60 seconds on a test image he had, and he had found out that the majority of the time was spent doing color convert (RGB to LAB). Removing that step ran the code in 4 seconds.
      When I stumbled over the thread, people had been improving parts of it for 3 days already, and it was down to ~55 seconds run time on that test image.

      At that point they were talking about rewriting things to C/C++, precomputing all possible values, multithreading.. Along with comments like "it's python, what can you expect?"
      I suggested a simple result cache (using a dict for storing results of already converted colors, and check that first). 4 lines of code to add - and the run time went from 55 seconds to 6 seconds.

      I've noticed that in many cases, if things are too slow, you're using a wrong approach. Sure, they could have rewritten it in C, and it would probably be fast enough to offset the chosen approach.
      But sometimes the simplest solution can also be the best solution :)

      --
      It's The Golden Rule: "He who has the gold makes the rules."
    7. Re:Logically Logical Logic by vgerclover · · Score: 1

      I totally agree, but I also acknowledge that there are sometimes that you've just hit the ceiling regarding algorithmic improvements, and you just have to start tweaking against your platform/environment. Then again, most people can go through their entire careers never facing this issue. Most task are algorithm bound.

    8. Re:Logically Logical Logic by Cajun+Hell · · Score: 1

      And the GIL doesn't necessarily keep you from using the parallelism of a multicore processor, because it doesn't actually block other threads -- when they're waiting on I/O. ;-)

      I love python but I wish they'd do something about the GIL. It's not a total deal-breaker (there are .. usually .. things you can do, and Guido mentions one of them) but it really is a weakness.

      --
      "Believe me!" -- Donald Trump
    9. Re:Logically Logical Logic by icebraining · · Score: 2

      It's also possible to write better x86 than a C/C++ compiler, so I hope you're writing everything in Assembly.

    10. Re:Logically Logical Logic by Daniel+Phillips · · Score: 2

      The Blender project has some pretty nice boolean operations written in Python, but they are history because of performance issues. And it would seem, they were not significantly less buggy than the buggy C code they attempted to replace.

      --
      Have you got your LWN subscription yet?
    11. Re:Logically Logical Logic by ohnocitizen · · Score: 1

      Why do we need to compromise? There is a clear need out there for a language with the simple syntax of python, and the speed of c. The People(tm) want a fast, clean, beautiful language. It is this desire that has lead to efforts like http://nimrod-code.org/, which I think are promising and hope mature (and gain great third party support). Because right now, there are use cases where you want the speed of c/c++, but don't want the hassle of writing in c/c++.

    12. Re:Logically Logical Logic by LS · · Score: 1

      Yeah, as if running C/C++ compiled code from python is a trivial operation. I agree, lame solution.

      --
      There is a fine line between being a cultivated citizen and being someone else's crop. - A. J. Patrick Liszkie
    13. Re:Logically Logical Logic by drolli · · Score: 1

      Yes, the usual strategy is like the following:

      a) write your application as clear and as high-level as possible. Only focus on a clear representation of the problem and the semantics.

      b) determine if the ressource usage is ok

      c) if its not ok, then use a profiler to identify the part of the code where you spend significant amounts of the time.

      d) optimize and structure the code within the high-level language until you can identify clear interfaces where low-level construct can help (but implement them in the high-level language as a reference)

      e) rewrite these parts in C or whatever; goto step b)

      I wrote measurement software in jython/java/C,matlab/C,labview/C,perl/C, matlab/tcl/C and i always profited from a clear structure instead of writing it in C directly (which i also did...)

  7. Python: Not Much Worse Than Ruby by busyqth · · Score: 5, Funny

    I'm waiting for the article:

    Van Rossum: Python Not Much Worse Than Ruby
    "Python creator Guido van Rossum discusses the prospects and criticisms of Python, noting that critics of Python should supplement with Ruby rather than re-engineering Python apps into a better language."

    1. Re:Python: Not Much Worse Than Ruby by Anonymous Coward · · Score: 1

      Supplementing with Ruby will make your program slower, not faster.

    2. Re:Python: Not Much Worse Than Ruby by Anonymous Coward · · Score: 2, Insightful

      That's the problem with Python. Ruby is expressive and object-oriented, C is fast. Python is neither.

    3. Re:Python: Not Much Worse Than Ruby by MattBD · · Score: 2

      It's faster than Ruby, and it most definitely is object oriented. Expressive is rather more subjective, but I've used it to some extent and I've found it very expressive.

    4. Re:Python: Not Much Worse Than Ruby by Anonymous Coward · · Score: 0

      That's the joke, dingleberry.

    5. Re:Python: Not Much Worse Than Ruby by Anonymous Coward · · Score: 0

      It's faster than Ruby, and it most definitely is object oriented. Expressive is rather more subjective, but I've used it to some extent and I've found it very expressive.

      Definitely, depending on your definition.

    6. Re:Python: Not Much Worse Than Ruby by pankkake · · Score: 1

      But it will be cooler!

      --
      Kill all hipsters.
    7. Re:Python: Not Much Worse Than Ruby by rrohbeck · · Score: 2

      Corollary:
      Van Rossum: Python Not Much Worse Than Perl
      Just had to be said.

    8. Re:Python: Not Much Worse Than Ruby by subreality · · Score: 1

      Object oriented is apparently subjective too. How else do you explain: ','.join(array)

      The way Pythonistas usually try to defend this is also enlightening.

      On the other hand, I can certainly agree that it's faster than Ruby. Ruby is miserable in that regard.

    9. Re:Python: Not Much Worse Than Ruby by Anonymous Coward · · Score: 0

      ','.join(array) is something that needs defending?

    10. Re:Python: Not Much Worse Than Ruby by subreality · · Score: 1

      Yes, it's backwards. array.join(',') is more sensible: join is always performed on an array (so why is it in class string instead of class array?), and ',' is a detail on how you're doing it. You are far more likely to: createlistofstuff().join(',') than: createseparator().join(listofstuff) .

  8. Kinda digging Python by XxtraLarGe · · Score: 4, Insightful

    I'm signed up for the CS101 course @ Udacity, and I was surprised they were using Python for the course. It does seem a bit weird using whitespace for blocks, especially when you're used to writing stuff like
    if(a > 0) { return a + 1; } else { return a -1; }
    for the simple stuff. I do really like things like being able to return multiple values from a procedure, etc., but Python seems more useful for rapid prototyping rather than anything else.

    --
    Taking guns away from the 99% gives the 1% 100% of the power.
    1. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      return a+1 if a>0 else a-1

    2. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      You can still write in-line in that manner, it's just not recommended. I try to avoid it for anything for complicated than one or two nested comprehensions.

    3. Re:Kinda digging Python by XxtraLarGe · · Score: 1

      return a+1 if a>0 else a-1

      Just starting out, so they didn't teach us that syntax. We've been shown:

      if (a > 0):
      return a + 1
      else:
      return a - 1


      Pretend that there are 4 spaces before the 2nd & 4th lines, since Slashcode doesn't recognize non-breaking spaces.

      --
      Taking guns away from the 99% gives the 1% 100% of the power.
    4. Re:Kinda digging Python by AuMatar · · Score: 1

      Being able to return multiple values is nice (although you can do that in C++ with a Pair template object, it isn't frequently done). Just remember there's a lot of pitfalls. For example, if you use the frequently used for loop replacement

      for x in range(len(somearray)):

      you're actually doing this in C

      int size = length(somearray);
      int array = new int[size];
      for (i = 0; i size; i++) {array[i] = i;}
      for (i =0; i size; i++){ j = array[i]; //do loop body on j}

      If size is big, you're hosed on memory and time.

      Now try and do the whitespace issue in a large company with people who aren't used to Python. It's cost me at least a month of my working life. I once spent 2 weeks debugging a 100K program where the sole author left, it turns out on 1 line out of 100K he tabbed instead of spaced.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    5. Re:Kinda digging Python by Anonymous Coward · · Score: 1

      return a>0 ? a+1 : a-1;

      Kinda what they made it for.

    6. Re:Kinda digging Python by vgerclover · · Score: 1

      Specially considering that you can rewrite that as return a + (a > 0) - (a <= 0) or return a + 1 if a > 0 else a - 1 or a multiplicity of other options :)

    7. Re:Kinda digging Python by buchner.johannes · · Score: 0

      return a+1 if a>0 else a-1

      Just starting out, so they didn't teach us that syntax. We've been shown:

      if a > 0:
              return a + 1
      else:
              return a - 1
      Pretend that there are 4 spaces before the 2nd & 4th lines, since Slashcode doesn't recognize non-breaking spaces.

      You don't need the brackets. I'm a bit unsure about the "return a+1 if a > 0 else a-1" syntax. It's a bit harder to read. numpy.where is probably the right thing for the job if you have more than one a for which you want to calculate.

      --
      NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
    8. Re:Kinda digging Python by Anonymous Coward · · Score: 1

      yes, obviously you should use:

      for x in xrange(len(somearray)):

      or more likely you are better off with:

      for element in somearray:

      if you don't need to know the index of the element.

    9. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      Specially considering that you can rewrite that as return a + (a > 0) - (a 0 else a - 1 or a multiplicity of other options :)

      I like the readability of this. A++++++++++++++

      /S

    10. Re:Kinda digging Python by AuMatar · · Score: 1

      The second I definitely agree with (and if you don't need to know the index). Or even

      index = 0
      for i in somearray: //do loop
          index++

      If you don't need to know the index, the python style for loop is awesome. But there's a very common need to do things N times even when not dealing with arrays. Not having a traditional for loop is kind of silly.

      As for xrange- I think there's a large percentage of python users who don't know xrange exists. It also has some fancy behavior behind the scenes- it takes constant memory but takes more time than a simple list iteration. The right answer in python is to use a while loop.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    11. Re:Kinda digging Python by TheGothicGuardian · · Score: 1

      You could always do:
      return [a - 1, a + 1][a > 0]
      but that isn't necessarily very Pythonic.

    12. Re:Kinda digging Python by Terrasque · · Score: 1

      if(a > 0) { return a + 1; } else { return a -1; }

      Here's yet an alternative way to write it in python :o)

      return a > 0 and a + 1 or a - 1

      >>> for a in range(-1,3):
      ... print a, a > 0 and a + 1 or a - 1
      ...
      -1 -2
      0 -1
      1 2
      2 3

      --
      It's The Golden Rule: "He who has the gold makes the rules."
    13. Re:Kinda digging Python by Hentes · · Score: 1

      Being able to return multiple values is nice (although you can do that in C++ with a Pair template object, it isn't frequently done).

      But you can't deconstruct the returned values, like in Python: x,y=f().

      Just remember there's a lot of pitfalls. For example, if you use the frequently used for loop replacement
      ...
      If size is big, you're hosed on memory and time.

      Not exactly true. In Python3, range only returns an iterator, not a list. And in Python2 there is xrange that does the same.

      Now try and do the whitespace issue in a large company with people who aren't used to Python. It's cost me at least a month of my working life. I once spent 2 weeks debugging a 100K program where the sole author left, it turns out on 1 line out of 100K he tabbed instead of spaced.

      In my experience Python3 doesn't seem to mind mixed whitespace (although I don't recommend doing it). And Python2 explicitly states when there are tabs and spaces mixed, after that it's just ctrl+f->\t.

    14. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      Use ternary operator in C, dammit!
      return a+(a>0 ? 1 : -1);

    15. Re:Kinda digging Python by vrt3 · · Score: 4, Informative

      If you do need to know the index, you should write

      for i, element in enumerate(sequence):
          print i, element

      It pays off to spend some time learning not only the syntax when you learn a new language, but also often used idioms in that language.

      --
      This sig under construction. Please check back later.
    16. Re:Kinda digging Python by sjames · · Score: 1

      That's why in python 3 range() returns an iterator.

      Of course, in python, you're much more likely to do:

      for x in somearray:

      or even:

      newarray = [ fn(x) for x in somearray ]

      Both of which will use an iterator.

    17. Re:Kinda digging Python by thetoadwarrior · · Score: 1

      You can do that in Python and it won't have the braces. There is nothing saying you can put things on one line.

    18. Re:Kinda digging Python by SQLGuru · · Score: 4, Informative

      return (a>0)?a+1:a-1;

      Tertiary operator FTW!

    19. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      Just write:

      for index, i in enumerate(somearray):
              # do something with i and index

      and you're done.

    20. Re:Kinda digging Python by Terrasque · · Score: 1

      If you don't need to know the index, the python style for loop is awesome

      Also if you do need to know the index :)

      for index, item in enumerate(AllTheThings):
        print index, "=>", item

      also, it's really easy to make custom iterators:

      def my_enumerate(items):
        i = 1
        for x in items:
          yield i, x
          i+=1
       
      >>> for a, b in my_enumerate(range(3)):
      ... print a, b
      ...
      1 0
      2 1
      3 2
      >>>

      --
      It's The Golden Rule: "He who has the gold makes the rules."
    21. Re:Kinda digging Python by LDAPMAN · · Score: 1

      THIS!! is exactly why I'd sooner cut my head off than use Python! White space should NOT be syntactically significant!

    22. Re:Kinda digging Python by Forbman · · Score: 1

      maybe not, but how much spitting vinegar do you do when you get code that, while syntactically correct, is not indented at all, or was coded by someone using spaces instead of tabs (or vice versa) for indents, or they set up their code editor to use a non-fixed pitch typeface, and thus whatever indenting they've done is incredibly whacky, and your tool set does not have very good code indenting functionality available to fix it?

    23. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      Different language different syntax.
      If you won't adjust to that then stop programming now. You're in for far worse later if you stay (omg! algorithms, optimisation, design)

    24. Re:Kinda digging Python by LDAPMAN · · Score: 1

      Those things annoy me but are usually easily fixed. Working code is parseable by definition so cleaning it up is relatively easy.

    25. Re:Kinda digging Python by XxtraLarGe · · Score: 1

      Tertiary operator FTW!

      Yeah, but you can do the exact same thing in C/C++, etc. My example was purposely simple because of the hassle of typing in anything significant on the message board.

      --
      Taking guns away from the 99% gives the 1% 100% of the power.
    26. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      In Python, that line is: "return a+1 if a>0 else a-1"

      You can even make it an entire function in one line, with just a slight altercation: "lambda a: a+1 if a>0 else a-1"

    27. Re:Kinda digging Python by rrohbeck · · Score: 1

      Meh.
      return $a-1+2*($a>0);

    28. Re:Kinda digging Python by rrohbeck · · Score: 1

      Then add a disagreement on tab width or tab vs space indentation between different editors and you're in deep doodoo.

    29. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      Have some python

              return a + 1 if a > 0 else a - 1

      And done.

    30. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      Have you ever used Python? You get over it. Quickly.

      It basically comes down to this: You're already going to use indentation to delineate your code (and if you don't, your code isn't intended to be maintainable, which means it's probably un-Pythonic anyway), so why not have that indentation actually mean what it implies: Here's a block of code. It's subordinate to the block of code before it.

      If you want the same sort of scanability in C/C++, you have to put braces on their own lines so that you can easily, visually match pairs.

      Actually _try_ programming in Python before you cut your own head off.

    31. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      None at all. I just pipe it through indent.

    32. Re:Kinda digging Python by icebraining · · Score: 2

      Nitpick: Python can't actually return multiple values; it's just that the comma create a single value - a tuple - that aggregates the values passed to it.

      When you do "return a, b", you're actually creating a tuple (a, b) and returning that.

      In practice, it's mostly irrelevant, though.

    33. Re:Kinda digging Python by Daniel+Phillips · · Score: 1

      I presume you meant:

          return a > 0 ? (a + 1) : (a - 1);

      --
      Have you got your LWN subscription yet?
    34. Re:Kinda digging Python by caseih · · Score: 2

      Actually Python has found quite a niche in web-based applications. There are a fair number of large Django-based sites out there. Also RedHat writes most of their system utilities, including their installer, Anaconda, in Python. Of course since Guido works for them, this is understandable. But RH was using Python in RH system utilities back in the Python 1.5 days. Virt-manager is written in Python with C-based modules to interface with libvirt. Anaconda itself uses c-based modules for hardware interfacing. In short, Python is definitely more than just for rapid prototyping.

      Python is an incredible glue language. It also helps that extending python in C is very easy, and even embedding Python in your C app is easy (the same API is used for both use cases).

      I think these days if I needed to rework some python modules for speed I'd try to write them in Cython, which is a python subset that compiles to straight C.

    35. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      I think you mean ternary :)

    36. Re:Kinda digging Python by qxcv · · Score: 1

      Oh my. Udacity is certainly *not* the best way to learn Python. They tend to try and keep it simple, but often this is to the detriment of readability. Here's an example from CS373 (most of the example code is like this):

      if x2 >= 0 and x2 =0 and y2

      Which could have been written like this:

      if 0

      Or another example:

      next = open.pop()
      x = next[1]
      y = next[2]
      g = next[0]

      Which could just as easily be:

      g, x, y = open.pop()

      Hell, even

      for i in range(len(delta)):
          x2 = x + delta[i][0]
          y2 = y + delta[i][1]

      is nicer as

      for dx, dy in delta:
          x2 = x + dx
          y2 = y + dy

      And your example

      if(a > 0) { return a + 1; } else { return a -1; }

      ==

      return a + 1 if a > 0 else a -1

      Udacity's approach is great for teaching theory, bad for teaching Python. If you want to write idiomatic Python, do some research on iterators, generators, functools, list unpacking, etc. Sorry if the code samples here screw up, but /.'s markup system blows hard.

      --
      "The most dangerous enemy of a better solution is an existing codebase that is just good enough." -- Eric S. Raymond
    37. Re:Kinda digging Python by qxcv · · Score: 1

      Welp, that looks horrible. Here's a pastebin of my original post: http://pastebin.com/uuj5Awpv

      --
      "The most dangerous enemy of a better solution is an existing codebase that is just good enough." -- Eric S. Raymond
    38. Re:Kinda digging Python by qxcv · · Score: 1

      ...with just a slight altercation...

      This is the real problem with Python, the amount of violence.

      --
      "The most dangerous enemy of a better solution is an existing codebase that is just good enough." -- Eric S. Raymond
    39. Re:Kinda digging Python by boxxertrumps · · Score: 1

      The point is, working code wouldn't need to be cleaned up.

    40. Re:Kinda digging Python by sqldr · · Score: 1

      They spent 3 years arguing about that one, then just said 'just use if' :-)

      Anyway, you could do this:

      return { true:a+1, false:a-1 }[a>0]

      --
      I wrote my first program at the age of six, and I still can't work out how this website works.
    41. Re:Kinda digging Python by sqldr · · Score: 1

      Then add a disagreement on tab width or tab vs space indentation between different editors and you're in deep doodoo.

      Not at all. Indentation only has to be consistent within a single block. If you suddenly change from tabs to spaces within a block, you get "unexpected indent error" pointing at the exact line that used the wrong indent.

      --
      I wrote my first program at the age of six, and I still can't work out how this website works.
    42. Re:Kinda digging Python by sqldr · · Score: 1

      it turns out on 1 line out of 100K he tabbed instead of spaced.

      Bullshit. You would've got "unexpected indent error" pointing at the exact line that was wrong.

      --
      I wrote my first program at the age of six, and I still can't work out how this website works.
    43. Re:Kinda digging Python by rrohbeck · · Score: 1

      I've had to prettify more C/C++ sources than I care to remember because the indentation was all screwed up. At least that didn't change the semantics of the program.

    44. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      Wow. What is it with C++ and templates? I don't use C++ and had to lookup what the Pair template is. It's basically an fscking structure! You don't need C++ or templates or the Pair template to do that in C. You could pass and return structure objects (not just references) since C89. In fact, in C99 it's even easier because of compound literals, which C++ lacks.

      Yeesh. I need to get out of this business before my head explodes. C++ has become the new crack, no thanks to the legions of Windows coders and their spawn infecting the Unix and FOSS camps.

    45. Re:Kinda digging Python by sqldr · · Score: 1

      At least that didn't change the semantics of the program.

      It doesn't. It changes the syntax and errors are picked up by the interpreter. Try this:

      for I in (1, 2, 3):
      [4 spaces]print I
      [tab]print I

      I get this.

      $ python foo.py
          File "foo.py", line 3
              print I
              ^
      IndentationError: unexpected indent

      This above complaint is only ever written by people who don't know how the indentation works. As for the former half of the statement, if it was written in python, you wouldn't have to clean up badly indented code, because it wouldn't have got past a syntax check in the first place. So it's actually doing you a favour.

      --
      I wrote my first program at the age of six, and I still can't work out how this website works.
    46. Re:Kinda digging Python by AuMatar · · Score: 1

      A pair template is just already written for you. Avoids the overhead of writing 20 small little structures if you have 20 different return pairs types, without using void pointers and losing type safety.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    47. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      Just so, fellow AC. Operators are unary, binary, or ternary. "Tertiary" comes from the sequence "primary, secondary, tertiary".

    48. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      2 weeks to fix whitespace in a python program? you fail at life.

    49. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      Actually _try_ programming in Python before you cut your own head off.

      Speaking as a Python developer who's heard this nonsensical argument by too many times, I'd much prefer if he did it the other way around.

    50. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      return (a > 0 ? a + 1: a -1);
      return a + 1 - 2 * (a=0);

      PS: like your first option.

    51. Re:Kinda digging Python by psavo · · Score: 1

      return (a-1, a+1)[a > 0];

      --
      fucktard is a tenderhearted description
    52. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      It's ternary operator, and Python has had one since 2006.

      result = x if a > b else y

    53. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      As for xrange- I think there's a large percentage of python users who don't know xrange exists.

      Really? Python comes with a tutorial that explains it. In the library reference 'Built-in functions' explains it, and that is a very reasonably sized single html page. How do these people get anything done?

      On second thougth I shouldn't be surprised, I've seen enough examples of people not rtfm *at all*, just blindly copying things from existing programs, including bugs. I've seen simple bugs (such as passing a wrong value to an API, resulting in *documented* undefined behaviour) become huge problems (such as undefined behaviour changing from something that accidentally worked to something that definitely didn't) because the bug turned out to be copied to hundreds of locations, while inexperienced programmers who hadn't taken over the copy culture yet and did bother to read the manual consistently did the same thing right the first time.

      On third thougth I'll keep being surprised, that's a symptom of not accepting this as normal behaviour for programmers.

    54. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      there's a bug in all of these rewrites. the op's code didn't
      return if a==0.

    55. Re:Kinda digging Python by Anonymous Coward · · Score: 0

      return [ a+1, a-1 ][ bool(a) ]

      Boolean switch FTW

    56. Re:Kinda digging Python by sxtynnmach1 · · Score: 1

      Tertiary operator FTW!

      Ternary operator. But yes, quite handy. As are the sensible-default operators some languages have such as the Elvis-operator ?: in Groovy and ?? in C# :)

  9. bass ackwards by Eponymous+Hero · · Score: 1

    "oh, our language engine sucks? uhh, you fix it!" yeah right.

    --
    insensitive clod overlords obligatory xkcd car analogy russian reversals whoosh pedant fanbois ftfy in 3...2...1..PROFIT
  10. Not the big problem by Anonymous Coward · · Score: 0

    Python is slow, but that's not its biggest problem. It's biggest problem is stability. My biggest complaint with Python apps is that they tend to crash a lot. More so than any other apps on my systems. In fact, most of the apps I've seen crash in the past couple of years have been Python utilities. Every once in a while I'll consider learning Python, but then I ask myself if I really want to develop slow and crashtastic programs and the answer is no.

    1. Re:Not the big problem by sjames · · Score: 1

      Then write better apps! If it's crashing it's because someone didn't try harder to not crash. It's not Python itself that's causing the problem.

      Perhaps the high level of the language allows or even encourages people to reach further than their grasp.

  11. usually? by v1 · · Score: 5, Insightful

    It is usually much more effective to take that one piece and replace that one function or module with a little bit of code you wrote in C or C++ rather than rewriting your entire system in a faster language, because for most of what you're doing, the speed of the language is irrelevant.'"

    I have a lot of experience in code optimization, and I would dispute this generalization. "often" is a lot more realistic than "usually". The most common thing I see is where one particular segment of an operation is coded by someone that doesn't understand their O's and is doing something like multilevel lookup loops instead of a hash table. Fundamental mistakes in algorithm choice are the biggest "HERE is the biggest problem" issues I find.

    Once you're past the stupid implementation mistakes, it goes just slightly in favor of "it's a little bit of everything" land. Something running significantly slower in one language than another often boils down to the coder not understanding how to make things scale in the chosen language. I can make C move slower than BASIC if I want to. Sometimes it's just knowing how the compiler is going to react to your structures. Little things like "roll up the loops when coding in VB" can produce an order or two of magnitude in speed improvement, and if you don't realize this you may think you're comparing identical implementations when you're not. "this language sucks!" often translates into "I don't know how to do it so it runs fast!"

    My last project was reduced from 23 hrs per run to 21 minutes by a small but complex change in implementation. From there, getting it down to 4 minutes required a LOT of little changes all over the place, to nickel-and-dime it down. I'll trade you my "guy that knows how to recode it in C" for your "guy that knows how to code, and REALLY knows his compiler" any day.

    --
    I work for the Department of Redundancy Department.
    1. Re:usually? by Billly+Gates · · Score: 1

      But the other guy in India did it for 1/5th the price!

      Think about the shareholders, managers, and the CEO? Not not to mention that big bonus for the person who is so smart for going cheap.

      Who cares about quality. How does making it better reduce the share price or pay for the CEOs kids college tuition?

    2. Re:usually? by jmerlin · · Score: 2

      Sometimes, sometimes the language you're working in really is the bottleneck. I've written a log parser in JavaScript that runs entirely in the browser and can process >200MB of text logs with full aggregation per second. That's an enormous amount of work (it's actually bottlenecked by the disk). V8 is enormously fast when used correctly. Later, for fun, I wrote an application that deciphered simple strings (
      A large chunk of that is the raw speed of C. Another (larger) chunk is because strings in JS are immutable and the algorithm is almost entirely string manipulation (fixed length, per-character manipulations). Combine language limitation + raw speed = wtf improvement.

    3. Re:usually? by jmerlin · · Score: 2

      Wow /. really butchered that one. The strings are encrypted with a fixed-length repeating pattern of XORs. The brute-force (try every pattern) then match against a word dictionary took 8 hours. Modifying the algorithm to be smarter and to look for the pattern rather than accepting/rejecting the result lowered that to 10 minutes. But the original algorithm in C finishes in 5 seconds.

    4. Re:usually? by cowdung · · Score: 1

      But the other guy in India did it for 1/5th the price!

      You assume the guy in India is less capable than you are. In many cases they could be much MORE capable than you!

    5. Re:usually? by wrook · · Score: 1

      Totally off topic, but it is very true that there are extremely capable people all over the world (not just India). These capable people will often work for much less than capable people in more "developed" countries. My experience has been that the problem with outsourcing to these capable people is that software development is a task requiring a lot of communication. Outsourcing parts of the process is almost always a disaster. You need to outsource the entire thing (middle management, QA, project management, documentation, etc, etc).

      There is also one other problem. I've worked for a so-called "body shop" before in Canada. These consulting companies do not hire in the same way that an ordinary company would hire. They aren't looking to fill specific roles, but rather they want a hodge-podge of skills that will enable them to win contracts. Then, when they are trying to fill a contract, they don't put members on the team with the thought of creating success, but rather with the thought of keeping a range of skills available to win other contracts. The resultant teams can often be non-functional.

      I think it is entirely possible to reduce development cost by moving development to a cheaper location. But you have to move lock, stock and barrel and hire permanent teams in the same way that you would do in your home country. Outsourcing only a part of your development to an agency in a far away, foreign country is pretty much a recipe for failure.

    6. Re:usually? by boxxertrumps · · Score: 1

      No one cares about quality. But just like the quality of roads, the electrical grid, water, customer service, hospitals, ambulances, fire fighting, police, banking, automotive repair, plumbers, construction contractors, food and wine, safety equipment, drugs, corrective lenses, shoes and erotic literature, people will notice when the quality isn't there.

      And they will bitch. Probably even at the CEO.

    7. Re:usually? by Anonymous Coward · · Score: 0

      What about Perl?

  12. Misleading article with fluf by Anonymous Coward · · Score: 0, Insightful

    Actually the only problem with python is the last question and honest Guido answer: python doesn't scale. That's where it is slow, you have these multicore machines and you can't fully use them. Having to go to C/C++ is a shame. Even cython which can speed up a lot python code is limited by the global lock of death. So yeah, people migrating to python-like languages without this drawback.

    1. Re:Misleading article with fluf by Anonymous Coward · · Score: 0

      Yup, tis the elephant in the room the python guys won't acknowledge.

      Meanwhile people are burning countless cycles and energy writing code that will have to be re-written at some point in a _real_ programming language with, you know, threads, and stuff.

      Anecdotal evidence, but I'm sick and tired of poorly performing buggy crashy python desktop apps (e.g. openshot video editor).

      It's like the programmers get as far as getting the GUI mocked up and then throw the python behind it for a few buttons. "That'll do, it's close enough".

      Meanwhile, you can't CTRL-C it, and there's no logging about what's going on behind the scenes...

      rant off

  13. Personally by ciascu · · Score: 5, Informative

    As someone simulating fluid-structure interaction with a number of constituent models and a lot of finite element (i.e. big matrix problems; using FEniCS - fenicsproject.org), using Python makes my overall quite-long algorithm much easier to flick through. Invaluable for debugging the theory as well as the implementation. FEniCS' Python interface ties into the standard C/C++ libraries using SWIG and, in simple cases, saves me working in C++. Very clear, well-written C++ is great for this application but I find it takes considerably longer to write than clear Python.

    When I hit a more intricate problem, I realized I was going to have to solve a series of FE matrices by hand (with PETSc, written in C). It turned out to be pretty straightforward to pick up SWIG, write a short module in C and a Python interface. Done! Particularly useful as I believe getting FEniCS and petsc4py to play well is tricky.

    So, I'd agree - having written a C++ version of my (simpler) problem and a Python/C version of the complicated one, the latter was definitely easier, and all the rate-limiting stuff is in C anyhow.

    Doubt it would be true for every situation but +1 from an FE perspective.

  14. Purists! by macraig · · Score: 3, Insightful

    To bend a cliche: Purists! Can't live with 'em, can't live without 'em!

    Seriously, we live in an era when programmers are no longer bound to the use of a single language for an entire project, as was the pragmatic case once upon a distant time. Why not just use the language for each module which best suits the need? If performance outweighs simplicity of code management, then use the better performing language for that module. No language is perfectly suited for all goals, so own your chosen criteria and don't 'blame' a language creator for having different criteria.

  15. Duh... by Anonymous Coward · · Score: 0

    This is the case with all modern (java, c#, ruby) languages, you find the "simple" algorithm X isn't performing, find out the the language you are using doesn't optimize for that structurized implementation. Find out there is some memory optimized algo in C (c++) and decide to use it and then it is a measure of how well your crap integrates with the real machine code crap.

  16. Metaphor by Ukab+the+Great · · Score: 3, Insightful

    Arguing about whose interpreted scripting language is slower is like arguing about whose rich delicious cheesecake is less fattening. When you eat the cheesecake, you accept the tradeoff of tastiness for five minutes off your total lifespan.

    1. Re:Metaphor by Anonymous Coward · · Score: 0

      can you express that as something I understand better, like cars? TIA

    2. Re:Metaphor by Anonymous Coward · · Score: 0

      Arguing about whose interpreted scripting language is slower is like arguing about whose 'smart car' is more stylish. When you get a smart car, you accept that everyone who isn't in a smart car is laughing at you, you accept the tradeoff for the easier parking.

    3. Re:Metaphor by Anonymous Coward · · Score: 0

      I'm always happy to hear my competitors aren't using python. It's good when others handicap themselves.

    4. Re:Metaphor by Anonymous Coward · · Score: 0

      Arguing about whose interpreted scripting language is slower is like arguing about who can suck the most gay cocks. When you suck gay cocks, you will die from AIDS.

    5. Re:Metaphor by Anonymous Coward · · Score: 0

      Solution: Take ten minutes to eat delicious cheesecake.

  17. world needs a better high performance language by Anonymous Coward · · Score: 1

    As far as high performance languages go, we have:

    FORTRAN: King of the performance hill, but so annoying to use that nobody really does outside some scientific circles.

    C++: This is what everybody uses to write high performance applications, but it's a mess of special cases and annoying syntax and megabyte-long error messages from deeply nested templates.

    We need a modern language, with things like functions as first class objects and introspection, but with the performance and "to-the-metal" nature of C++ when you care about designing for optimal cache efficiency and so on.

    1. Re:world needs a better high performance language by Anonymous Coward · · Score: 0

      FORTRAN is as you put it "king of the performance hill" largely because of its different aliasing assumptions compared to C++. Compilers can do more agressive scheduling and other optimizations if they can assume lack of aliasing, which (generally speaking) you can't in C++ and many other languages.

      There are other minor reasons, but that one aliasing issue is a big reason why FORTRAN rules the performance roost after 50+ years. That being said, I never use it because it lacks modern language features. C++ at least *tries* a little bit, and is a good balance between non-sucky performance and a language that's not stuck in the 1950's.

    2. Re:world needs a better high performance language by lgw · · Score: 5, Insightful

      As far as high performance languages go, we have:

      FORTRAN: King of the performance hill, but so annoying to use that nobody really does outside some scientific circles.

      C++: This is what everybody uses to write high performance applications, but it's a mess of special cases and annoying syntax and megabyte-long error messages from deeply nested templates.

      We need a modern language, with things like functions as first class objects and introspection, but with the performance and "to-the-metal" nature of C++ when you care about designing for optimal cache efficiency and so on.

      This is entirely true. What C++ does is excellent. The standard libraries are great - self-resizing arrays and sane strings at bare-metal speeds (if used with just a bit of skill). All the common algorithms . But the C baggage is really a problem.

      There's a lot of syntax and just "tricks" that are needlessly complex becuase of the history. The learning curve is not just steep, but pointlessly steep. The level of control you get does not require the level of complexity thrown at you.

      And the worst is - people still write C-style code in C++! Because C-style coding is obious in the language, and RAII is not, you still see people thinking exceptions are bad, and programming like it's 1989. Because template syntax is the worst macro langage ever, you don't dare use templates outside of seldom-changing library code.

      All of the downsides of C++ are fixable with a from-scratch language with the exact same feature set, but no legacy syntax.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    3. Re:world needs a better high performance language by Rising+Ape · · Score: 1

      FORTRAN: King of the performance hill, but so annoying to use that nobody really does outside some scientific circles.

      F90's not so bad, it got rid of most of the nastiness of F77 - or at least made it non-compulsory.

      These ultra-high level languages like Python are all very practical, but are so abstracted that it doesn't even feel like programming to me, more like connecting together pre-built black boxes. Where's the fun in that?

    4. Re:world needs a better high performance language by shutdown+-p+now · · Score: 1

      We need a modern language, with things like functions as first class objects and introspection, but with the performance and "to-the-metal" nature of C++ when you care about designing for optimal cache efficiency and so on.

      http://claylabs.com/clay/

    5. Re:world needs a better high performance language by shutdown+-p+now · · Score: 1

      All of the downsides of C++ are fixable with a from-scratch language with the exact same feature set, but no legacy syntax ...

      ... and semantics.

      Hence, Clay.

    6. Re:world needs a better high performance language by Anonymous Coward · · Score: 0

      "All of the downsides of C++ are fixable with a from-scratch language with the exact same feature set, but no legacy syntax."

      I think they called it D.

    7. Re:world needs a better high performance language by Cajun+Hell · · Score: 1

      so abstracted that it doesn't even feel like programming to me, more like connecting together pre-built black boxes. Where's the fun in that?

      The fun is in building bigger things out of the boxes. Even working in a lower-level language you get up to some part of your project where you're just making lots of function calls. All that lower-level codeis stuff you built for the purpose of finally getting to work with abstractions.

      --
      "Believe me!" -- Donald Trump
    8. Re:world needs a better high performance language by betterunixthanunix · · Score: 2

      you still see people thinking exceptions are bad

      Well, there are two things at work here:

      1. Exceptions as they exist in C++ are bad. The Lisp way is better: find the exception handler, then (possibly) unwind the stack. When throwing an exception could cause the program to abort, there is no way that you can use exceptions in any large project.
      2. Exceptions make it very hard to figure out what will happen. When an exception is raised, program flow branches to an unknown location; you could call the same function twice, with the same arguments, and end up in two totally unrelated exception handlers.

      Now, in practice exceptions are better than the known alternatives, for the simple reason that large amounts of code are simple hacked together without formal development methods. Still, I have seen projects that simple do not use exceptions, because they had too many problems with the weirdness that exceptions cause (although I suspect that if C++ and Java had Lisp-like exceptions, where the stack is left intact for the exception handler, things would be different).

      --
      Palm trees and 8
    9. Re:world needs a better high performance language by Anonymous Coward · · Score: 0

      Check this out: http://digitalmars.com/d/1.0/index.html

    10. Re:world needs a better high performance language by Anonymous Coward · · Score: 0

      All of the downsides of C++ are fixable with a from-scratch language with the exact same feature set, but no legacy syntax.

      Give a look at D programming language. Basically its goals are what you described. (has nicer syntax then c++, makes some stuff a bit easier, but still allows to get ' performance and "to-the-metal" ' if needed)

      Couple of links:
      Home Page
      Wikipedia Entry

  18. Python's problem by spiffmastercow · · Score: 4, Informative

    The problem with Python isn't the speed -- he's right about optimizing with bits of C. The problem is the GIL. Without good multithreading support, I have to give up on Python for a large number of application domains.

    1. Re:Python's problem by Hentes · · Score: 2

      Multithreading is only a problem in CPython. Other interpreters like Jython, IronPython or PyPy all have facilities for multithreading.

    2. Re:Python's problem by Terrasque · · Score: 1
      --
      It's The Golden Rule: "He who has the gold makes the rules."
    3. Re:Python's problem by Artraze · · Score: 1

      You can free the GIL from a C extension module as long as you promise to behave (e.g. don't modify refcounts). As a result, the GIL becomes a relative non-issue in many performance applications, as you're likely going to be most of the performance critical stuff in C on C data. I've found that this actually tends to improve performance versus, pure C++ for example, because it requires a clear understanding of what data is constant or owned by what thread or how it is shared. In C++ people seem to have a bad habit of just slapping a critical section on every one of their accessors, for instance, injecting quite a bit of overhead for even trivial operations.

      That's not to say that the GIL isn't a bad thing, but practically speaking it's not a significant limitation for many applications.

    4. Re:Python's problem by impaledsunset · · Score: 1

      The problem with the GIL has the same solution as the problem with speed: C extensions can turn off the GIL and run multithreaded.

      Granted, that's not a great solution if your CPU-heavy code is a lot code using Python dictionaries for example, but you still have the option of doing what Guido suggested.

      And for those who say that this is just a hack - the heavy loop and/or the part with the GIL switched off can be written in a language like Cython. It has Python-like syntax, it supports a subset of real Python and can have subsections that translate into pure C. So the end result will still be consise, won't look like a hack. You also have the option to implement your whole module in Cython in many cases, with optimisation directives only for the respective part.

    5. Re:Python's problem by Anonymous Coward · · Score: 1

      Well, your extension module solution is not particularly attractive to me. It still does not allow you to write any kind of multithreaded server software where the actual work is supposed to be done in Python and scaling should be more or less proportional to the number of cores you throw at the problem. Think web servers under high load.

      Multithreaded code is becoming more and more relevant these days because the computing power of single cores have reached a barrier by now. If the GIL does not go away, Python may well become unattractive for all kinds of serious apps, not just high performance stuff.

    6. Re:Python's problem by defcon-11 · · Score: 1

      There are plenty of domains where threads aren't very useful. For example Python is extremely popular in scientific computing and other big number crunching jobs. If you're running on a cluster or 'in the cloud' without shared memory like many modern data analysis algorithms, threads aren't very useful. Another popular domain for Python is networking code which is usually non-threaded and asynchronous in order to handle many connections smoothly (ala node.js).

    7. Re:Python's problem by Cajun+Hell · · Score: 1

      You can free the GIL from a C extension module as long as you promise to behave (e.g. don't modify refcounts). As a result, the GIL becomes a relative non-issue in many performance applications, as you're likely going to be most of the performance critical stuff in C on C data.

      You're right, of course, but looking at it that way requires that you think of "performance applications" as a special case, and then use the right tool for the job (C) instead of the tool that you want to (Python). As pros or "advanced" enthusiasts that's ok, but it's kind of regrettable that some 12-year-old kid who just wants to write a game with pyglet has to either learn C or stick to one core. I don't wanna tell some budding novice "oh, didn't you know? Your game is a 'performance application' and if I knew you wanted to write a game that might be able to use non-multi-process parallelism, I would have given you a different toolbox instead."

      "Kind of regrettable." Ok, I know: Learning is good, we all had to do it, and the 12-year-old probably learns faster than we old farts do now. But let's remember the point of languages like Python is to make things easier and get away from some kinds of details. If you don't value that, you have little reason to use Python in the first place.

      Compare this to a situation without a GIL. Switch to Jython, throw hardware at your problems in the form of cores (and the passing years seem like they're throwing plenty of hardware right at us, very cheaply), and you don't have to think about the "right tool for the job" because you're already using a perfectly adequate tool. That's how things should be.

      CPython's failing to deliver something that, no, I'm not entitled to or anything, but sure would be sweet. That's a shame, boo hoo.

      --
      "Believe me!" -- Donald Trump
    8. Re:Python's problem by naturaverl · · Score: 1

      Indeed one of python's problems is the GIL, but that only applies to multithreaded apps. In contrast, multiprocess apps are unaffected. The python standard library "multiprocessing" module makes it trivial to spawn child processes and messaging through pipes & queues, so the whole GIL thing really becomes kind of a non-issue.

    9. Re:Python's problem by gladish · · Score: 1

      If you ever write a module extension that requires interaction with the GIL, you'll find yourself trolling through the interpreter source code trying to figure out when you should acquire/release the GIL. I can say, the experience was pretty fun and educational, but it just seems like concurrency within the interpreter itself was an afterthought. I would think that a relatively modern language like python would have 1st class support for threading in it's "official" runtime. (CPython). I agree with the original post, that the GIL is a huge shortcoming. As someone who's also written a lot of .NET wrappers around c++ libraries, I can tell you that in theory it's great, but in practice it's no where near as nice as having a fully "managed" implementation. For starters, portability now relies on that wrapper being available on your target platform. If you own the entire stack, that's fine, but there's still an additional maintenance cost. Also, a lot of people writing python code don't have the expertise to simply drop into c/c++, re-write a critical section of code, THEN write the language binding. No to mention when they're debugging, their code goes into this sort of "black whole" method call and comes back out... hopefully in a good state.

    10. Re:Python's problem by spiffmastercow · · Score: 1

      There's a ton of overhead that goes into communicating between processes. If you can, its much more efficien (and pleasant) to use threads. The point of using Python is that it's supposed to be simple. Setting up a complicated inter-process communication mechanism every time you need to run a background thread makes it not so simple.

  19. Isn't this what all the scripters do? by istartedi · · Score: 2

    Don't most users of these scripting languages (the good ones anyway) profile and write the speed-critical sections in C or C++ anyway? That's not Python specific. It's not even specific to scripting languages. It's the same thing that C programmers do when they use inline assembly. It's like this all the way down the line. You start with rapid development at a higher level, then profile and optimize what you need.

    --
    For all intensive purposes, "whom" is no longer a word. That begs the question, "who cares"?
  20. It's still too slow, despite what he says. by Animats · · Score: 4, Informative

    Says the guy whose whole life is tied up in the language, and whose project, at Google, to speed it up, crashed and burned.

    Python is slow because von Rossum refuses to cut loose the boat-anchor of "anything can change anything at any time". The straightforward implementation of Python, CPython, boxes all numbers (everything is a CObject, including an int or a float) and looks up functions, attributes, and such in a dictionary for every reference. And only one thread is allowed to run at a time. This allows one thread to dynamically patch the objects and code of another thread. Which is cool, but useless. 99.99+% of the time, there's no need for a dynamic lookup. Most program dynamism is shortly after program startup - once things are running, they don't change much. If, sometime shortly after startup, the program said "OK, done with self-modification", at which point a JIT compiler did its thing, the language would be much faster. But no. That's "un-Pythonic".

    PyPy, the newer Python implementation, uses two interpreters and a JIT compiler to try to handle the dynamism with less overhead. They're making progress, but they need a very complex implementation to do it, and they're many years behind schedule.

    Python, as a language, is very usable. But it's too slow for volume production. That's not inherent in the basic language. Python could remain declaration-free if there were just a few more restrictions on unexpected dynamism. By this is meant ways the program can change itself that aren't obvious from looking at the source code. For example, if a module or class could only be modified from outside itself if it contained explicit self-modification code (like a relevant "setattr" call) most modules and classes could be nailed down as fixed, "slotted" objects at compile time. The other big win is using enough type inference to decide if a variable can always be represented as a machine type (int, float, char, bool, etc.). That's a huge performance win.

    Claiming that the "slow parts" should be rewritten in C is a cop-out. It makes the program more fragile, since C code can break Python's memory safety. Except for number-crunching, or glue code for existing libraries, it's seldom done.

    (I have a Python program running right now which will run for over a week, parsing the street address of every business in the US into a standard format. The parser is complex enough that rewriting it in C would be a big job. There's no "inner loop".)

    1. Re:It's still too slow, despite what he says. by Hatta · · Score: 1

      (I have a Python program running right now which will run for over a week, parsing the street address of every business in the US into a standard format. The parser is complex enough that rewriting it in C would be a big job. There's no "inner loop".)

      This would be a good application for Perl. Perl handles regexps about 4 times faster than Python.

      --
      Give me Classic Slashdot or give me death!
    2. Re:It's still too slow, despite what he says. by Anonymous Coward · · Score: 0

      Unladen Swallow was not his project. Get your facts straight fuckwad!

    3. Re:It's still too slow, despite what he says. by steveha · · Score: 5, Interesting

      Says the guy whose whole life is tied up in the language

      That's fair.

      and whose project, at Google, to speed it up, crashed and burned.

      That's completely wrong. Unladen Swallow was not GvR's project, and it didn't "crash and burn". Unladen Swallow found that their approach was not speeding up Python as much as they had hoped, and the two Google employees were moved on to other projects. The code lives on, and I think people are still doing things with it, although it's clear that PyPy is a better approach.

      To me at least, "crash and burn" implies a horrible failure with catastrophic consequences, and Unladen Swallow was considerably less dramatic than that. If you just meant to say "they didn't accomplish their goals", that would be a fair statement.

      Python is slow because von Rossum refuses to cut loose the boat-anchor of "anything can change anything at any time".

      That was a basic decision way back when, and it would be a profound change to make (the language wouldn't really be Python anymore). I personally don't make much use of this, but supposedly there are some programs that do.

      PyPy, the newer Python implementation, uses two interpreters and a JIT compiler to try to handle the dynamism with less overhead. They're making progress, but they need a very complex implementation to do it, and they're many years behind schedule.

      There is a very small group of people working on PyPy, and they are doing ambitious things. I'm not overly worried about their schedule.

      You failed to mention that PyPy has already achieved great speed when compared to CPython. The latest PyPy is, on average, over 5x as fast as CPython.

      http://speed.pypy.org/

      if a module or class could only be modified from outside itself if it contained explicit self-modification code (like a relevant "setattr" call) most modules and classes could be nailed down as fixed, "slotted" objects at compile time.

      This is an interesting idea. But I am not aware of anyone working on something like this.

      Claiming that the "slow parts" should be rewritten in C is a cop-out.

      I disagree. Way back at the dawn of time, GvR designed Python to make it easy to interface C code, just exactly as this sort of "escape hatch" to help projects that work well but are too slow, and also for libraries.

      I think that the ability to link in C code was an important feature that helped Python win hearts and minds. It's slower than C, but at least you knew there is an escape hatch if you wind up having trouble with it.

      Except for number-crunching, or glue code for existing libraries, it's seldom done.

      Yeah, but that's kind of like saying that except for stop signs and traffic lights, you usually don't use the brake pedal in a car.

      There are all sorts of useful libraries that have been glued into Python, and a major part of Python's popularity is that you can use powerful libraries from a convenient and friendly language.

      SciPy is a great example: they took ferociously powerful libraries (written mostly in Fortran) and made them usable from Python. I know I for one can get more work done in Python than in Fortran.

      As another example, a few years ago I worked on a project to make a DVD player with some fancy features, and we were doing our development in Python. It was fast enough, even on a cheap embedded processor, because all the heavy lifting was being done by C library code. And we got a lot of work done quickly.

      (I have a Python program running right now which will run for over a week, parsing the street address of every business in the US into a standard format. The parser is complex enough that rewriting it in C would be a big job. There's no "inner loop".)

      This sounds interesting.

      Can you run this in PyPy?

      Can you fan it out to multiple processes using the multiprocessing

      --
      lf(1): it's like ls(1) but sorts filenames by extension, tersely
    4. Re:It's still too slow, despite what he says. by Anonymous Coward · · Score: 0

      Or, if you find your hand-written parser to be the hot spot of your workload, perhaps you should be using a highly optimized parser-generator and high-level, grammar-based parser definition... it's sad how many applications abuse regular expressions and regular expressions w/ strange non-regular extensions to do things that fit much better into context-free grammars.

    5. Re:It's still too slow, despite what he says. by Anonymous Coward · · Score: 0

      Can you run this in PyPy?

      Unfortunately PyPy only supports the legacy Python 2 dialect, not Python 3. Given that Python 2 is a dead end and all new code should be written in Python 3, this makes PyPy a non-starter for many people.

    6. Re:It's still too slow, despite what he says. by steveha · · Score: 1

      Unfortunately PyPy only supports the legacy Python 2 dialect, not Python 3. Given that Python 2 is a dead end and all new code should be written in Python 3, this makes PyPy a non-starter for many people.

      This is unfortunate, but not a total deal-breaker. The recommended compromise is to write in Python 2.x, but plan on using the 2to3 tool to convert to Python 3.x once you no longer need the Python 2.x support. And, you can run 2to3 as a check, to make sure you aren't writing any code that is too horribly tied to Python 2.x.

      The 2to3 tool can port most Python 2.x code for you, so it isn't hard to avoid the hard-to-convert bits of Python 2.x. As long as you only use new-style classes, you use lazy iterators as much as possible (use xrange() instead of range(), etc.) and you don't do any deep magic with exceptions, Python 2.x code is a lot like Python 3.x code and the conversion is smooth.

      http://wiki.python.org/moin/Python2orPython3

      steveha

      --
      lf(1): it's like ls(1) but sorts filenames by extension, tersely
    7. Re:It's still too slow, despite what he says. by Anonymous Coward · · Score: 0

      #golang

      (Han-Wen ducks)

    8. Re:It's still too slow, despite what he says. by Anonymous Coward · · Score: 0

      (I have a Python program running right now which will run for over a week, parsing the street address of every business in the US into a standard format. The parser is complex enough that rewriting it in C would be a big job. There's no "inner loop".)

      This sounds interesting.

      Can you run this in PyPy?

      Can you fan it out to multiple processes using the multiprocessing [python.org] module? (It seems like an embarrassingly parallel [wikipedia.org] problem, since each address is independent and there are very many of them. Am I missing something?)

      For what he does, I think it's more I/O bound than CPU bound.

    9. Re:It's still too slow, despite what he says. by marcosdumay · · Score: 1

      Have you looked at Haskel? It is great for parsing.

    10. Re:It's still too slow, despite what he says. by Anonymous Coward · · Score: 0

      For what he does, I think it's more I/O bound than CPU bound.

      Yet GP post was using it as a counter-example to Guido van Rossum's claim that you can usually rewrite the hot spots from your programs in C.

      If it were I/O bound, then Python would be as fast as anything else, but GP was claiming that Python is slow for it.

    11. Re:It's still too slow, despite what he says. by Anonymous Coward · · Score: 0

      Says the guy whose whole life is tied up in the language, and whose project, at Google, to speed it up, crashed and burned.

      Not really. They got a speedup, their chosen approach was working - it just wasn't working as well as pypy was and is. At the outset of Unladen Swallow, they weren't expecting Pypy to take shape so quickly, or to ever do C extension modules - but it does.

      Python, as a language, is very usable. But it's too slow for volume production.

      You may need to substantiate this.

      That's not inherent in the basic language. Python could remain declaration-free if there were just a few more restrictions on unexpected dynamism.

      Which could probably be done pretty easily using a decorator.

      By this is meant ways the program can change itself that aren't obvious from looking at the source code. For example, if a module or class could only be modified from outside itself if it contained explicit self-modification code (like a relevant "setattr" call) most modules and classes could be nailed down as fixed, "slotted" objects at compile time. The other big win is using enough type inference to decide if a variable can always be represented as a machine type (int, float, char, bool, etc.). That's a huge performance win.

      This is what Cython is for.

      Claiming that the "slow parts" should be rewritten in C is a cop-out.

      Not really, no. He's claiming that the critical sections should be profiled, and recoded if beneficial. I cut my teeth on BASIC and 6502 machine language - it was pretty much the same deal there.

      It makes the program more fragile, since C code can break Python's memory safety.

      Cython.

      Except for number-crunching, or glue code for existing libraries, it's seldom done.

      Actually, if you camp out on the Pypi RSS feed for a while, I think you'll find most of the reusable code for CPython is C extension modules.

      (I have a Python program running right now which will run for over a week, parsing the street address of every business in the US into a standard format. The parser is complex enough that rewriting it in C would be a big job. There's no "inner loop".)

      Any reason you're not using Pypy or Cython?

    12. Re:It's still too slow, despite what he says. by steveha · · Score: 1

      I have a Python program running right now which will run for over a week, parsing the street address of every business in the US into a standard format.

      If you have a big machine with lots of cores, the Python multiprocessing module could speed that up quite a bit. (At work, we have one computer with two 12-core Opterons, and if you can get all 24 cores working together, it can really crunch some data. It's fun to run make -j 25! Sadly, it doesn't see much use.)

      But here are two ways you might be able to split the work up across multiple computers, possibly on the Amazon E2 cluster or some other rented cluster. The first one uses Hadoop, which should already be available on a rented cluster. The second one I've never heard of before, but likely you could install it on your own cluster if you have one. Interestingly, they wrote the map/reduce system in Erlang, but user jobs are submitted in Python.

      http://www.michael-noll.com/tutorials/writing-an-hadoop-mapreduce-program-in-python/

      http://discoproject.org/

      steveha

      --
      lf(1): it's like ls(1) but sorts filenames by extension, tersely
    13. Re:It's still too slow, despite what he says. by hanwen · · Score: 1

      The original poster works at google (like me). We have lots of cores, and something that works quite like hadoop.

      --

      Han-Wen Nienhuys -- LilyPond

    14. Re:It's still too slow, despite what he says. by steveha · · Score: 1

      Yes, I believe I've heard of Google MapReduce once or twice.

      Why is he complaining that his Python job will take a week to run then? Can't he throw some extra cores, extra cluster nodes, or perhaps extra data centers at it?

      Have I missed something... is his problem actually not embarrassingly parallel? Or is he already running it in parallel and it will take a week anyway? I don't run jobs that big and I don't know how to estimate how long it should take.

      steveha

      --
      lf(1): it's like ls(1) but sorts filenames by extension, tersely
    15. Re:It's still too slow, despite what he says. by Animats · · Score: 1

      The original poster works at google (like me).

      I am not, nor have I ever been, a Google employee.

  21. Static vs. Dynamic Typing by Teckla · · Score: 5, Insightful

    I was a little bit disappointed by Guido's response regarding static vs. dynamic typing:

    InfoWorld: You talked about the arguments for and against dynamic typing. You said that if you trust your compiler to find all the bugs in your program, you've not been doing software development for very long. So you're satisfied with Python being dynamic?

    Van Rossum: Absolutely. The basic philosophy of the language is not going to change. I don't see Python suddenly growing a static subdivision or small features in that direction.

    Proponents of static typing do not claim that compilers, combined with languages that use static typing, will find all the bugs in your program. This is nothing more than Infoworld erecting a straw man and Guido knocking it down.

    However, static typing does make a huge number of potential errors stick out like a sore thumb (the compiler will refuse to compile the code, and will emit appropriate error messages).

    Some people (rightfully) argue that dynamic typing makes for shorter, prettier, easier code.

    Some of us believe the primary concern should be correctness, and that shorter, prettier, easier code are secondary concerns -- almost always. People should think about this every time their computer crashes, or an application crashes, or something is acting up and needs to be rebooted, or they get a virus through no fault of their own, or their data gets corrupted.

    Will users be thinking, "Gosh, this sucks, but I'm sure glad the programmer used a dynamic language, because it made it easier on him (the programmer)."? No, they'll be thinking, "Damn buggy programs! I just lost X (hours,minutes,seconds) of work, and now I'm frustrated!" Programming languages are a means to an end, not an end in itself. Don't be a self centered developer: the fruits of your labor are for users, not so you can write the code equivalent of poetry.

    Not to mention, statically typed languages allow for easy refactoring possibilities that make it possible to fix all sorts of serious issues, including architectural ones, with reasonable effort expended. Dynamic languages, while they have made some progress in the area of refactoring, are really in the dark ages here.

    I know dynamically typed programming languages are the hotness right now, and I'm sure my opinion will be hammered relentlessly, but I do ask that if you disagree, don't mod me down, but instead, bring forth a reasonable argument for a different position. This should not be a popularity contest, where the loser is not heard, no matter what side the loser is on.

    1. Re:Static vs. Dynamic Typing by kisielk · · Score: 2

      As someone who's been working on a fairly large scale application suite in Python for the last 4 years I would say that dynamic typing is both a blessing and a curse during development. It certainly makes writing and reusing code easier to an extent, but it can make some things more difficult especially when you have code that deals with objects of several different types and there's the potential to get things confused.

      However, I could probably count the number of times I've seen a part of our system fail in production due to a type error on one hand. The type errors usually crop up during development or in the test suite. They're more of a pain when developing than anything.

    2. Re:Static vs. Dynamic Typing by MrSteveSD · · Score: 3, Insightful

      However, static typing does make a huge number of potential errors stick out like a sore thumb (the compiler will refuse to compile the code, and will emit appropriate error messages).

      Absolutely. Do you really want to be wasting company resources tracking down bugs that could easily have been found by the compiler in a statically typed language?

      I've never really been a fan of dynamically typed languages. What exactly is the point? To save a few seconds on declaring the type of a variable? You may save a few seconds, but most time tends to be spent debugging code, not writing code. You end up saving seconds in the writing stage and losing hours in the debugging stage. If you really need a variable to be able to change types, many statically typed languages have some kind of built-in variant/object type that can do exactly that if you really need it.

    3. Re:Static vs. Dynamic Typing by Anonymous Coward · · Score: 0

      I'm pretty sure, 99.999% of all times, when a programm crashes today, it's either a segfault or a not catched exception. On mission critical apps you are still right, i guess.

    4. Re:Static vs. Dynamic Typing by tgv · · Score: 1

      I agree. I've gone from very strict languages to "a pointer is a pointer" in C to correct type checking C and C++, and static typing definitely helps. Take Javascript: a lot of APIs don't give a clue what kind of data they expect and fail silently when you supply the wrong one. That's really going to make users happy...

    5. Re:Static vs. Dynamic Typing by dbc · · Score: 1

      Agreed. Bugs are caused by poor thinking, not by lack of type checking. Strict static type checking gets in the way of more sophisticated code, especially specialized container classes. I note that people who work in statically typed languages rarely think of doing their own container classes. In Python, a container class is often a huge win for code readability and maintainability.

      Where you pay the price for duck typing, IMHO, is in testing and validation. Duck typing requires good unit testing discipline. When I hear people say "static type checking finds my bugs", I think, "There is a person who is too lazy to think about the problem up front and to write good unit tests during development."

    6. Re:Static vs. Dynamic Typing by PiMuNu · · Score: 2

      Well, as a C++/python developer I spend 90% of my time in C++ wrestling with the obscure syntax and memory management to tell the compiler what I want to do. That 90% of my time in python - well I spend it writing tests and documentation and all the good things that squash bugs. Like a couple of days ago I spent 3 hours trying to figure out why the compiler was spitting back my code - turns out I forgot to declare a function const. Fine, that's an error, but it's not like it actually makes a difference to the code. Better to spend 10 minutes writing a test that checks for constness if that's what I want.

      Shorter prettier easier code is less likely to be buggy. If I can read my code in 5 seconds, chances are I can spot bugs. If it takes 5 minutes well that's a problem.

      Decent error handling makes code robust. Ack, I ran over the end of my std::vector. Better hope I tested for that. Ack, I ran over the end of my list. Lucky python throws an error for me. That's not static vs dynamic typing, just about general robustness of the language/libraries. But sure as hell makes a difference.

    7. Re:Static vs. Dynamic Typing by kisielk · · Score: 1

      Totally. I find the biggest difference for me when writing static versus dynamically typed languages is when the type errors crop up. In a statically typed language such as C or Haskell, I'll see them when I run the compiler. In a dynamically typed language like Python or Clojure I'll see them when I run my unit tests. Both of those are things I always do before finalizing a changeset so either way the type errors caught.

    8. Re:Static vs. Dynamic Typing by Teckla · · Score: 2

      Well, as a C++/python developer I spend 90% of my time in C++ wrestling with the obscure syntax and memory management to tell the compiler what I want to do.

      C++ evolved into a monstrosity. I share your dislike of C++. I won't touch it unless I absolutely have to.

      Shorter prettier easier code is less likely to be buggy.

      In general, I agree; however, when it comes strictly to static typing vs. dynamic typing, I think giving up static typing for a little less code is a false economy.

      Decent error handling makes code robust. Ack, I ran over the end of my std::vector. Better hope I tested for that. Ack, I ran over the end of my list. Lucky python throws an error for me.

      I, too, use a language that does bounds checking for me (that language is not C or C++, is also statically typed, and outperforms Python by miles). I will only "drop down" into C if I need absolute top performance -- which is pretty rare, these days.

    9. Re:Static vs. Dynamic Typing by Anonymous Coward · · Score: 0

      How many of the programs that crash, force reboots, or are open to infection are written in dynamically typed languages? I was under the impression that many of those are caused by poor handling of memory or poor sanity checking in languages like C. I'm not debating the point that static typing can make a difference, I just take exception to a blanket statement that blames every application crash on one class of language.

    10. Re:Static vs. Dynamic Typing by steveha · · Score: 3, Informative

      Will users be thinking, "Gosh, this sucks, but I'm sure glad the programmer used a dynamic language, because it made it easier on him (the programmer)."? No, they'll be thinking, "Damn buggy programs! I just lost X (hours,minutes,seconds) of work, and now I'm frustrated!" Programming languages are a means to an end, not an end in itself. Don't be a self centered developer: the fruits of your labor are for users, not so you can write the code equivalent of poetry.

      It's true that static type checking can catch bugs for you. That's why, in C, I'm rigorous about declaring const for anything that ought to not change; I like it when the compiler catches a bug for me.

      But the world isn't as binary as you make it out to be. It's not a choice between poetry-like code or more correct code; there is more to it than that.

      Python's "duck-typing" can let you write one function where you would need to write several in C or C++. As a contrived example:

      def add5(x):
          return float(x) + 5.0

      It doesn't matter what you pass to this function, as long as it can be converted to a float. In C++ you would have to write multiple versions of this with different type signatures. In C you would have to write multiple versions of this with different names! And it would truly suck if just one of the various versions had a bug in it; in Python, with just one function, you have one place to look for bugs.

      (You could probably do this contrived example with templates in C++, or even with a macro in C. And this is a useless example. But I think it makes the point, and real examples need not be as useless and trivial.)

      Not to mention, statically typed languages allow for easy refactoring possibilities that make it possible to fix all sorts of serious issues, including architectural ones, with reasonable effort expended. Dynamic languages, while they have made some progress in the area of refactoring, are really in the dark ages here.

      I have no idea what you are talking about here. Dynamic languages, which impose fewer limits on what you can do, have some sort of disadvantage over statically-typed languages for refactoring? How does that work?

      And let me counter that with an example. In Python, you are encouraged to simply read and write member variables directly, rather than writing getter and setter functions. But if you ever need to "hook" the getting or setting, you can write a property descriptor and run a getter or setter function, without needing to rewrite any code; the property descriptor does an implicit function call for you can you can do any checking you need.

      And finally, every language has its best practices. In the Python community, self-tests are strongly encouraged. Yes, with Python, type errors aren't caught until runtime; but you can easily add self-tests that exercise the code and catch the type errors pretty much immediately after you introduced them.

      http://docs.python-guide.org/en/latest/index.html

      No language is perfect, but in my experience Python hits a sweet spot. I can get a lot of work done in a few lines of Python, I can write those lines quickly, I can read them when I go back later, and I enjoy the coding more than C. I don't think my Python code is buggier than my C code per line of code, and in Python I write so many fewer lines of code I think I come out ahead on bugs.

      steveha

      --
      lf(1): it's like ls(1) but sorts filenames by extension, tersely
    11. Re:Static vs. Dynamic Typing by pavera · · Score: 2

      All I can say is you've obviously never built a large scale system in either a static or dynamic language... The number 1 correlation between bugs and code is the number of lines of code. More lines of code == more bugs. Always, every time. The fact that I can write the same thing in python in 1/5 or 1/7th the code vs Java or C++ means on average I'll have less bugs.

      As someone who's spent the last year rebuilding in python the middle and frontend tiers of a large system that integrates a large number of C/C++ modules on the backend, I can tell you that the number of "dynamic" type issues that have leaked into QA (IE beyond automated test cases) are... 0

      The number of null pointer dereferences, linking errors (which end up building successfully, but as soon as you try to call a function crash), and other various segfaults that have been found in the C/C++ modules.. well over 100

      dynamic typing is *easy* to deal with compared to pointer math. Maybe if the C/C++ coders didn't have to spend all their time making sure they were passing char pointers instead of wchar pointers they could have spent a little time bounds checking arrays and verifying pointer math.

      As to all the contentions that python isn't a "real" language, I would say the middle and frontend of this application are much better designed than anything that is in the backend. The code is clean, well documented, easily maintainable, much more flexible, modular, and for the most part 90%+ covered by automated tests. It is a solid OO design with a decent chunk of functional programming thrown in where it makes sense. The C code has a 75 page testing manual that must be run by hand after every QA build (takes 2-3 weeks)... I'm not surprised by this at all, because C requires you to spend all your time making trivial things work, so you don't have any time to actually do design. And once you get something "working" you can't touch it, because nothing is modular and everything is set in stone. I've written a decent amount of C in my life, I'm pretty fluent in it, and in writing python I've had to drop down to C to optimize a number of things. You do it when you have to, just like C coders used to drop to assembly when they had to.

      Sure I'm generalizing in the paragraph above, I'm sure you *can* write well designed C, I've just never seen it in practice in the real world in 15 years of real life experience... I've seen "OK" designed C++, and well designed Java... I can recreate those designs in less than half the code in python, and VS java I'll use 1/10th the RAM, and vs C++ I won't have memory leaks or bad pointer math, and an average developer can read the code.

      I believe Guido is spot on, in my experience the part of the code that has to be fast and isn't already a C module in python is tiny, and most of the time can be built in a day or two. Compare that to the 8 months I'm under budget building these middle and frontend tiers in python (they budgeted based on the last implementation which took 3 years in C++)... And I'd say python is a win, the interface is just as responsive, I'm well within all SLA metrics in the business logic tier, and in a number of places the python implementation is faster than the old C++ (just using better algorithms). I'm going to be at feature parity in the next month with the existing system... well except that now our system is 100% cross platform compatible (tested on OS X, Various linux flavors, Various bsd flavors, and Windows)... Vs the old C++ that made extensive use of win32 only functionality and was 100% windows only. Getting cross platform support was the reason for the redesign/rebuild... The fact that I built a prototype in python faster than the C++ guys could decide on a cross platform GUI toolkit gave my team the win to implement it in python.

    12. Re:Static vs. Dynamic Typing by Anonymous Coward · · Score: 1

      I've never really been a fan of dynamically typed languages. What exactly is the point? To save a few seconds on declaring the type of a variable? You may save a few seconds, but most time tends to be spent debugging code, not writing code

      I absolutely agree. Furthermore, most time ends up being spent *reading* code, rather than writing it. Python may have its own standard of elegant and beautiful -- but it is meant -- by design, intent, and "zen" to be readable. To have lots of white space

      (hint -- spaces between words, periods, and paragraphs are a relatively modern invention that immensely improved world knowledge and literacy )

      GVR's talk/keynote with the same topic is up at pyvideo.org -- it's an hour long, but he covers some of this--better than I am capable of.

      But frankly, most basic analytic tools I use IN PYTHON already handle the basic type issues. And that's just in vim. I'm sure if I screwed around with pyclipse or ninja, it'd probably do better, but I'm happy with my pep check and linter.

      What they don't capture well are most interfaces. But That isn't the problem--and talking in those terms is somewhat 'unpythonic' -- I don't need an interface.

      If the object should have a method--I call it. If it throws an exception, I handle it appropriately. If it shouldn't have a method... I shouldn't have called it to start with. Type checking could catch that at compile time--but it's not a language failing, it's my screwup.

      [Many] Statically typed languages still fuck up units constantly -- unless you're using something as strong as Ada, and even then it's up to the programmer not to do a lazy thing and implement a generic type. Just because I should declare my int type implementing meters doesn't mean some bumfuck kid won't just do a generic 'length' type.

      Unit tests and coverage tests will catch most anything. You aren't saving your employer time. You're costing them time in development. Time in deployment to market. Time to the next feature update. Time to identify and resolve a bug. Time to cross-port to other platforms. Time to deliver prototype-to-user and get earlier feedback.

      You're costing them -- a little bit more hardware. And in your assertion, a little more debugging time.

      I have *never* *had* to use a debugger in python. I have in C, Java, and Fortran. Maybe because I didn't know those as well. Most likely because I ended up with very /large/ programs in them in the real world.

      I chose to use one once. The largest app I had to work with was 75k LOC in Python.

      In Java I'd estimate it would have taken about 500k, although I really only have about three years paid Java experience and did not work on an app of that magnitude.

      Now -- I don't want to be all...trying to convert people. I do the job, I use the right tool for the place.

      But your argument about saving time doesn't hold much water. It is at worst, an unfounded trollish criticism from avoidance of use and experience. Not because I think you'll magically like python if you hate it -- but because if you were actually half as good as you claim-- you wouldn't be needing your compiler to check types that often.

      At best, it's idle academic sophistry saying "this feature would be better". Okay--maybe true. Over the course of a project of any interesting scope -- I'm nearly certain to save time with reasonable use of Python assuming competent devteam. Language design encourages development practices. Dynamic typing is not just a compiler issue -- it's a philosophy issue.

      If you want it, add some introspection on hungarian warts (eewe--but easy) to an import, or do it with a decorator (if it hasn't been done already--it wouldn't surprise me...I've built entire grammars with decorators).

      What exactly is the point. The point is to make the duck quack. What's the point with polymorphism, late-binding, operator overloading -- I mean hell, I can write it all in MIPS with pointers and function lookup tables...

      Oh right. The point is to get the job done efficiently. Don't rip the sledgehammer because you can't use it to drive your penny-nails.

    13. Re:Static vs. Dynamic Typing by shutdown+-p+now · · Score: 2

      Static typing can be shoehorned on Python by an external tool - it already has everything necessary in the syntax to provide type annotations, you just need something to actually enforce them. E.g. you can write, today:

      def foo(x: int, y: int) -> int:
          return x+y;

      but it doesn't really mean anything special to Python itself. It will stuff those things up into __annotations__ property of the function, and so a decorator can be written that wraps the function and verifies types at run-time. For compile-time, you need a tool.

    14. Re:Static vs. Dynamic Typing by pavera · · Score: 3, Interesting

      The point is I can (and have) replaced 100k lines of C, 150k lines of java, or 110k lines of C++ with 10-15k lines of python.

      I don't care who you are, its easier and faster to write 15k lines of code than 100k lines of code, significantly faster. Its easier and faster to debug 15k lines of code than 100k lines of code, again significantly. Most bugs are not type errors. Most bugs are logic errors. Sure, is a type error annoying? Yes, but it annoys *me* as a thinking person that I changed the assumed type of a function argument and didn't go change a caller, its not the languages fault that I forgot, just like its not C/C++/Java's fault when you walk off the end of an array and segfault... automated tests find these bugs just as reliably as a compiler, and you have to write automated tests to test logic even in a statically typed language, so its not extra work.

      The tradeoff is that my python code might run slower (if the modules I'm using aren't already C which a lot of them are), but vs Java, startup time is significantly faster, and memory usage in python is significantly better, like an order of magnitude at least. vs c/c++ I don't have to deal with pointers, null dereferencing, memory management, or any of those headachy things that a large proportion of developers do wrong, and end up with insecure programs. So... to me at least the choice is clear. Shorter code that is easier to read, easier to debug, quicker to write, easier to maintain, and generally has less bugs, python gets all those things 100% of the time vs C, C++, or Java. The only downside is it might be slow... and if it is, you write a couple hundred lines of C, write all manner of tests around it to make sure it deals with all the pointer stuff correctly, and you're still way ahead of a pure C program.

    15. Re:Static vs. Dynamic Typing by Anonymous Coward · · Score: 0

      However, static typing does make a huge number of potential errors stick out like a sore thumb (the compiler will refuse to compile the code, and will emit appropriate error messages).

      http://en.wikipedia.org/wiki/Code_coverage#Software_tools

      Some of us believe the primary concern should be correctness, and that shorter, prettier, easier code are secondary concerns -- almost always.

      I know dynamically typed programming languages are the hotness right now, and I'm sure my opinion will be hammered relentlessly, but I do ask that if you disagree, don't mod me down, but instead, bring forth a reasonable argument for a different position.

      http://en.wikipedia.org/wiki/Technical_debt

      Dynamic languages, while they have made some progress in the area of refactoring, are really in the dark ages here.

      Personification never links to anything!

      Programming languages are a means to an end, not an end in itself.

      This is why I value simplicity.

    16. Re:Static vs. Dynamic Typing by defcon-11 · · Score: 1

      The buggy language thing is total BS. Bugs per line is pretty constant across all languages, and lower level languages require many more lines of code than Python. You do the math.

    17. Re:Static vs. Dynamic Typing by pavera · · Score: 1

      The problem with your argument is it isnt "a little less code". I regularly over 10 years have had at least 50% code reduction when converting from C/C++/Java to python. Currently I'm converting 250k lines of C++ to python... I'm on course for a 75% reduction in code.

      Now python is not a magic bullet, you do have to know how to use it... as an example at a previous job my team re-wrote a python program in python, and reduced lines of code by 50%... The original devs were C developers who were told "you will write this in python". They thought in C, the wrote in C, they took zero advantage of the standard library, they reimplemented the "lower" method all strings have.... The only reason it was python was the syntax was python. If you're thinking in Java, and writing Python, your code won't get shorter. You have to embrace functional programming where it makes sense to eliminate lines of code. You have to think in python and understand the standard library and what it can do for you to really get lots of code shrinkage. But it is possible to massively decrease the amount of code for the same feature set.

    18. Re:Static vs. Dynamic Typing by marcosdumay · · Score: 2

      You can't just make general statements about dynamic x static types. The problem is that altought they are well defined concepts, their advantges and disadvantages depend more on the choosen idioms than on any other thing, and the idioms change a lot from one language to the other.

      When you ask a Java developer what he thinks, he'll likely answer you that static types are essential for architecturing a system, and somebody would be crazy to go without them.

      If you ask a Perl developer, why he should have the extra work of telling the compiler what it already knows?

      For a Haskel developer, it is very important to catch bugs, but slows him down, that is why he likes to have the option of declaring types, but not the obligation.

      If you ask a Python developer, he'll certainly refuse to comment, and go away wondering why somebody would code functions that know the type of their arguments at compile time (if ever).

    19. Re:Static vs. Dynamic Typing by Daniel+Phillips · · Score: 1

      Agreed. Bugs are caused by poor thinking, not by lack of type checking.

      If you think that then maybe you should write all your code in assembly language. Just stay sharp!

      --
      Have you got your LWN subscription yet?
    20. Re:Static vs. Dynamic Typing by pavera · · Score: 1

      Sorry for the double reply... what is your language of choice? In the end I don't think this is a static vs dynamic competition... I'm just comparing python to the "big" statically typed languages (java, c, c++). There could easily be a statically typed language that offers a better trade off in terms of code length and performance than the "big" three, but I don't know about it...

      I don't think C, C++, and Java get their verbosity only from being statically typed. And the code shrinkage I've achieved with python has not generally been due to dynamic typing. I'm willing to learn, if there is something better out there that allows for short code, and is faster than python, I'd agree with your argument.

    21. Re:Static vs. Dynamic Typing by Coryoth · · Score: 1

      I think it's a matter of taste and need. Many people who want static typing will cry foul if I suggest they use either a language that has sufficiently powerful static types (such as Coq) to allow proper theorem proving with automated theorem provers, or that they annotate their code with an appropriate specification language (Frama-C for C, JML for Java, SPARK for Ada, HasCASL for Haskell) that will allow automated theorem provers to (at the very least) catch whole classes of errors that are impossible to find with static types alone (even with, say, Haskell's type system) or (at best) formally prove correctness up the specification. They feel those would be too much work for too little gain. And the reality is that, for the sort of code they write and the sort of problems they tackle, they may well be right. And, of course, for the sort of problems fans of dynamic typing tackle and the sort of code they write, static typing is similarly too much overhead for too little gain. It really depends on how badly you need to be absolutely correct, and how mcuh work you're willing to put in to get there -- and there's a very big slope of different options.

    22. Re:Static vs. Dynamic Typing by dbc · · Score: 1

      Agreed. Bugs are caused by poor thinking, not by lack of type checking.

      If you think that then maybe you should write all your code in assembly language. Just stay sharp!

      Assembly has it's place. Here's a clue: for most things, Python is better. But I happen to work in imbedded software -- ANSI C with inline asm as needed gets products shipped. On balance, I probably do more assembly than C++. For compact, high-performance code, write clean C and unleash the optimizer. For day-to-day problem solving: Python. The niche where C++ buys you anything but headaches is vanishingly small IMHO.

    23. Re:Static vs. Dynamic Typing by Anonymous Coward · · Score: 0

      I work at Google on the ads infrastructure. We use Python for many tangential things and love it (test systems, internal tools, etc.).

      But even if Python were fast enough (it's not even close) for the main servers that serve ads, the dynamic typing is pretty much a deal breaker. When I am looking at a function in a code base that is millions of lines long, I want to know exactly who is calling it and with exactly what objects, and when this is serving production traffic, I do not under any circumstances want surprises at run time.

      Python is a great language for many purposes, but it is *not* the right tool for all jobs.

    24. Re:Static vs. Dynamic Typing by Anonymous Coward · · Score: 0

      >the fruits of your labor are for users, not so you can write the code equivalent of poetry.

      Nobody meant that. The point is that if the code is clear, you can read it and find out whether it's correct.
      Maintainance is more important than writing new code. So if one can't read the code because of all the noise (Perl, C++), what good is it?
      (Note that C++11 makes the noise less bad at some places - and Haskell doesn't have this noise at all)

      >Some of us believe the primary concern should be correctness, and that shorter, prettier, easier code are secondary concerns -- almost always

      That's what shorter, prettier and easier mean: easier to reason about, easier to approach correctness checks.

      >Not to mention, statically typed languages allow for easy refactoring possibilities

      What is this about? In dynamic languages, you are in the REPL and do "refactoring" all the time, every minute you are in there. Am I missing something?

      >I know dynamically typed programming languages are the hotness right now

      They are the hotness since 1970. The only time we put up with static languages at all is when we hadn't come far enough yet to just compile the dynamic language to the static one with dynamic parts.

      That said, there have always been two camps of programmers: The ones that prefer dynamicism and do the thinking themselves and the ones that prefer static type checking to do the thinking for them (they hope), even though the type system has to be Turing complete for it not to be in the way - and usually it isn't Turing complete - so you better believe it will be in the way AND not do what it promised.

    25. Re:Static vs. Dynamic Typing by captain_sweatpants · · Score: 1

      This is one of the most informative posts I've ever read on slashdot! It's a shame it's so far down that few people will read it. I think someone has finally convinced me to use python. informative++; thanks!

    26. Re:Static vs. Dynamic Typing by Anonymous Coward · · Score: 0

      When I am looking at a function in a code base that is millions of lines long

      Why would anyone write a function that is millions of lines long?

      I want to know exactly who is calling it and with exactly what objects

      1. Documentation is core. Period.
      2. Python type annotations.
      3. [ Inspect, Pyrasite (!), nose-IPDB ]

      and when this is serving production traffic, I do not under any circumstances want surprises at run time.

      Are you implying that "suprises at run time" are a function of data typing?

      Python is a great language for many purposes, but it is *not* the right tool for all jobs.

      Agreed. Without traces or profiling data, I feel that it is safe to assume that HLA is the right tool for all jobs.

    27. Re:Static vs. Dynamic Typing by Courageous · · Score: 1

      Not only do I agree with your assertion that the correlation for bugs is mostly with lines of code, there are various studies out there showing that larger systems reach a maintainability limit at about 1,000,000 lines of code, at which point they become far too fragile to maintain.

      I do wish there was an after-the-prototype method of cementing down python variables and namespaces, and I do wish there was way to 'compile it better,' perhaps in a final publication step. Python namespaces would need to be 'sealed' to have any chance of performance-optimizing a final python compilation pass; this has something to do with the way that all python namespaces are by contract with the current interpreter treated as mutable hash tables. That's immensely useful for a variety of purposes, but once a certain part of the design is finished, it would be useful to be able to pin that down and speed it up.

      Python does have one major weakness in today's day and age: the python interpreter is not reentrant, meaning that it is all but useless for a significant multithreaded programming effort. Guido should totally work on that. And he needs to lose his 'tude about threading. It is holding Python back.

    28. Re:Static vs. Dynamic Typing by Anonymous Coward · · Score: 0

      (You could probably do this contrived example with templates in C++, or even with a macro in C. And this is a useless example. But I think it makes the point, and real examples need not be as useless and trivial.)

      I have a real example. You have an object with some stuff on it that you pass around - now you need to attach something extra to it. With a static language, you have to figure out about how this affects the types - should I make a new class or add it to the existing, or something else?

      In Python, you just say o.foo = bar and pass on o. Job done. I use this all the time with Django (a web framework).

      I have no idea what you are talking about here. Dynamic languages, which impose fewer limits on what you can do, have some sort of disadvantage over statically-typed languages for refactoring? How does that work?

      I think the point is that with a static language, if you are just moving code around, you can do a recompile and just fix all the ensuing errors one by one, and then usually have a working program afterwards. With Python, you need to be more careful and make sure you visit all the call sites.

      That said, without all the type info, there's usually much less of the mundane kind of refactoring going on in my experience.

    29. Re:Static vs. Dynamic Typing by 1jpablo1 · · Score: 1

      One problem here is comparing python vs C/C++/Java only. Because those languages are very verbose on their own. An interesting comparison would be python vs Scala, for example. In my own very limited testing of scala, I'd say it requires marginally more code than python (for simple things, at least).

    30. Re:Static vs. Dynamic Typing by badkarmadayaccount · · Score: 1

      Your C++ guys should look into Qt - rarely is it the case it wont't do great job. Oh, and (vanila) python - no lockless programming, less space efficient GC than any platform nomad would respect - lame. And where is the decent static compiler which time has show is mandatory for Serious Work (TM)?

      --
      I know tobacco is bad for you, so I smoke weed with crack.
    31. Re:Static vs. Dynamic Typing by alexo · · Score: 1

      Python's "duck-typing" can let you write one function where you would need to write several in C or C++. As a contrived example:

      def add5(x):
              return float(x) + 5.0

      It doesn't matter what you pass to this function, as long as it can be converted to a float. In C++ you would have to write multiple versions of this with different type signatures.

      What's wrong with:

      template<typename T>
      float add5(T x) { return float(x) + 5.0; }

    32. Re:Static vs. Dynamic Typing by Anonymous Coward · · Score: 0

      What's wrong with: [a template-based solution]

      (You could probably do this contrived example with templates in C++, or even with a macro in C. And this is a useless example. But I think it makes the point, and real examples need not be as useless and trivial.)

    33. Re:Static vs. Dynamic Typing by indymike · · Score: 1

      Do you really want to be wasting company resources tracking down bugs that could easily have been found by the compiler in a statically typed language? It's never been much of a problem because I don't have to compile to find these kinds of bugs :) A significant fraction of C code (C is my first language) is purely focused on implementing and manipulating structures... which is why in many cases there is a large difference in the number of lines of code between functionally equal C and Python code. Code implementing and manipulating data structures is also where you are most likely to run into type errors. It's not better or worse, it's just different.

      --
      -- Mike
    34. Re:Static vs. Dynamic Typing by Anonymous Coward · · Score: 0

      >Some people (rightfully) argue that dynamic typing makes for shorter, prettier, easier code.

      No, there is nothing right about that. That is a strawman and is absolutely false. Static typing does not mean explicit typing, nor does it mean "has a primitive type system". Haskell is a strictly and statically typed language, and is just as concise as python (and easier to read). Just because java is a bad language and is statically typed, doesn't mean all statically typed languages have the horrible crippling limitations of java.

    35. Re:Static vs. Dynamic Typing by Anonymous Coward · · Score: 0

      >Most bugs are not type errors

      This is not true. You are simply assuming a very poor type system. All sorts of "logic" errors are in fact type errors if you use a language with an expressive type system. Null pointers? That's a type error. Not checking for error conditions? That's a type error. To take a more obviously "logic" problem: imagine you are writing a game of monopoly. Trying to do things when it isn't your turn is a type error. You simply need an expressive type system that allows you to encode the rules of the system as types.

      This ties in to the false dichotomy you are creating above, where you act like C/C++/Java is one side, and scripting languages are the other. This is not the case. I can write your python 10-15k lines as 10-15k lines of haskell, and have an order of magnitude fewer bugs slip into production, while having an order of magnitude better performance.

  22. GuidoVR is wrong and this is why by eminencja · · Score: 1

    I have similar problems with Perl -- it is too slow -- and it is impossible to fix it by re-writing parts of the system in C.

    Here's the catch: you manipulate large data structures (e.g. large data sets read from a database). There is a bunch of functions for processing the data. Even if you re-write some of them in C they will still have to manipulate the very same stuff -- for example: a number in Perl is a scalar; a scalar has a string representation, a numeric representation, a reference count, etc. If you manipulate it in C you still have to take care of all this crap. So what's the point in writing that in C? Perl interpreter is also written in C. (Perl C API is way harder to use than Python's but that's irrelevant.)

    So, it's like saying: if your program (in whatever language is too slow), run it through the profiler, find the routine that uses 90% of the CPU time and optimize it. Anyone who has used a profiler will know that this not always that easy.

    1. Re:GuidoVR is wrong and this is why by Forbman · · Score: 1

      ...and you can't work with the data inside the database itself?

    2. Re:GuidoVR is wrong and this is why by Anonymous Coward · · Score: 0

      Maybe it's just me, but when I manipulate numbers in C, I don't worry about the reference count or string representation. And when I'm driving my car, I don't worry about my buggy whip matching my top hat and riding goggles.

    3. Re:GuidoVR is wrong and this is why by Anonymous Coward · · Score: 0

      This is slightly missing the point of why C and C++ are fast languages. If you've ever looked at the asm code generated by C++ compilers, you'll notice two important things: All the memory addresses and offsets inside data structures are handled in compile-time. It's just constants that do not change on the runtime. This means that any dynamic language is always going to be very much slower, assuming it does not follow the compile-time restrictions. The 2nd thing that makes C and C++ fast is that there just does not exists any slow primitives in the languages. All the slow stuff is inside libraries. Because of this, you need to write large amount of c++ code to make your program slow -- computers execute so many asm instructions in a second that you'll have to manually write large amounts of c++ code to make it slow. Optimizing simple innerloops is not enough. C++ can ensure your whole program is fast, not just the innerloops. The slowest operation in C++ is probably dynamic_cast or typeid() or throw, and even those are so amazingly fast compared to what dynamic languages are doing. The optimizations that c++ are doing are modifying behaviour of your whole program.

      Noone writes c++ code that needs to handle string and numeric representation of an object interchangeably. If you're doing something like that in C or C++, you have big problems understanding the languages. Knowing which part of the language changes on runtime and which is compile-time is important information for a programmer. Trying to fight it is like shooting yourself to the foot.

    4. Re:GuidoVR is wrong and this is why by ThePhilips · · Score: 1

      For some things indeed Perl is pretty slow. But unlike Python, if you code in Perl tutorial examples, you would never have to wait minutes for them to finish. Python? Love that range() function which can easily eat gigabytes of RAM. Love that dynamic function/method look-up - on every f-ing call. In Perl, though I have seen slowness, I yet to encounter any corner as stupidly implemented as in Python.

      Also, unlike Python, in Perl there is a workaround for some cases: one can generate on the fly and eval a dedicated subroutine. That works well if you have lots of data coming from the configuration which does not change over the program life time. E.g. last time I used it was to improve implementation of a black list. Originally, black list was supposed to be very short - few entries, probably with regexps. But later, on some tasks it was needed to be as large as an input, leading to O(n^2), which was unbelievably slow in Perl. Rewriting the match against the black list into an eval'ed function literally removed the bottleneck. It's still O(n^2), but nobody notices that anymore.

      --
      All hope abandon ye who enter here.
  23. This why we are stuck with Perl by eminencja · · Score: 1

    My friend from Belgium (who speaks Dutch as the first language) said once: "oh, so the guy who created python is from the Netherlands? Well, I don't wanna touch it then".

  24. Donald Knuth by JohnWiney · · Score: 3, Informative

    Donald Knuth made this point in 1971, in his Empircal Study of Fortran Programs - virtually none of most programs has any significant effect on performance.

    1. Re:Donald Knuth by Animats · · Score: 1

      Donald Knuth made this point in 1971, in his Empircal Study of Fortran Programs - virtually none of most programs has any significant effect on performance.

      That's much less true than it used to be. In batch number-crunching programs (which is what people wrote in FORTRAN), there are typically inner loops that use most of the CPU time. However, a browser, a window system, a parser, an OS, or a GUI application usually has a much flatter profile. Then the speed of the language matters.

    2. Re:Donald Knuth by Anonymous Coward · · Score: 0

      ...and you win the award for worst possible wording of Knuth's conclusion. "Virtually none" does not mean "a small core".

    3. Re:Donald Knuth by JohnWiney · · Score: 1

      No - most of the work in most modern code is done in the (presumably) highly-optimized libraries. The application-specific code typically has little effect on performance. (The application design probably does, though.) That's a lot of the reason programming isn't as interesting as it used to be. Young uns just don't know what they missed.

    4. Re:Donald Knuth by Geeky · · Score: 1

      And for probably the majority of applications most of the work is being done outside of the computer on which they're running.

      Most of the code I've written recently spends it's time hanging around waiting for responses from the network, calling external web services or interacting with databases. The time spent anywhere I could actually optimise it in a lower level language is such a tiny fraction of the overall runtime it's not even worth considering.

      It's like comparing browsers for speed - yes, some are faster than others, but your experience of the internet will usually depend far more on your bandwidth (and that of the site you're connecting to) than which browser you use.

      Or for the car analogy fans - buying a faster car won't get you to your destination quicker in the rush hour because the speed of your car is not the limiting factor...

      --
      Sigs are so 1990s. No way would I be seen dead with one.
    5. Re:Donald Knuth by wrook · · Score: 1

      Similarly, if you are writing client code (or pretty much anything interactive), the program is spending the vast majority of its time waiting on the user. I have some Ruby code where I have to read in and parse some pretty big files. What I realized was that I could read the file into memory, quickly index the data and leave the majority of the parsing for later. The user isn't going to notice if I slow down giving results from 0.01s to 0.1 seconds when it takes them 2 seconds read the data.

    6. Re:Donald Knuth by Anonymous Coward · · Score: 0

      Fewer and fewer (scientific) number-crunching programs are written in Fortran these days. Its fairly popular still because it is what man of todays older faculty members learned in graduate school and/or as post docs. Today such programs are written in C or C++.

  25. Jon Louis Bentley ``Writing Efficient Programs" by DutchUncle · · Score: 1

    Not that he was the first to say these things, but that book says them so *well*.

  26. Coincidentally by Anonymous Coward · · Score: 1

    "a bad taste about python"

    Coincidentally, "it tastes like python" ['det smakar pyton'] is a Swedish idiom for something that tastes really bad.

  27. I hit a will with the garbage collection by Balial · · Score: 1

    I use python a lot to process large string logs (hudreds of megs or a couple of gigs). The problem is it's all super quick until the working set in the garbage collector gets too big and you fall off a performance cliff. I dunno what they're doing in there, but you easily go from a minute or two run time to half an hour to an hour because of the paging.

    I'm not familiar enough with other garbage collected languages and such workloads to know if this is inherent or just a problem with the Python GC. Either way, I think it's fair to say that Python is too slow under such circumstances. I'd like to see it fixed, though, rather than abandon it :)

    1. Re:I hit a will with the garbage collection by Anonymous Coward · · Score: 0

      Half an hour? Seriously? I wrote a program in C++ to parse multi-gigabyte text files containing polygonal meshes with hundreds of millions of polygons, rasterize them into 3 dimensions using recursive plane splitting algorithims into millions of pieces, and then actually calculate the 3 dimensional hilbert index of each fragment's position and sort the resulting millions of fragments by hilbert index. I used OpenMP (literally like 20 lines of preprocessor pragmas) and avoided using the C++ STL I/O libraries and I was able to run it on what I would consider a slow machine in less than 20 seconds.

    2. Re:I hit a will with the garbage collection by Anonymous Coward · · Score: 0

      Before concatenating, try keeping your strings in a [] and .join() them only when it is really needed.

    3. Re:I hit a will with the garbage collection by ultranova · · Score: 1

      I'm not familiar enough with other garbage collected languages and such workloads to know if this is inherent or just a problem with the Python GC.

      It's inherent. I noticed the exact same effect on Java programs I wrote: once the program starts using swap, garbage collection takes forever. I believe that the problem is because a garbage collector has to, in the worst case, hit every page of the working set to trace live objects, possibly several times (meaning that the page can potentially be swapped in and out several times per collection).

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    4. Re:I hit a will with the garbage collection by K.+S.+Kyosuke · · Score: 1

      What do you consider a slow machine? A dusl core K8 @ 2GHz? A Pentium @ 75 MHz?

      --
      Ezekiel 23:20
    5. Re:I hit a will with the garbage collection by Anonymous Coward · · Score: 0

      Learn to use generators and iterators.
      If you were using C, you wouldn't be blaming the language for your own incomplete understanding

    6. Re:I hit a will with the garbage collection by shutdown+-p+now · · Score: 1

      If you have a big working set in the GC, you're doing something wrong. CPython is reference-counted, so things that go out of scope should be freed right away. It also has a simple GC to detect and break down cycles, but it's not supposed to be used for most of your data. So it sounds like your problem is having cyclical references in your data structures - try dealing with that (i.e. breaking them up manually, or using weakref).

    7. Re:I hit a will with the garbage collection by gbjbaanb · · Score: 1

      Yep, its an inherent property of GC.

      Our .NET apps suffer occasionally, we'll report slowdowns (seconds usually) and the devs say "can you reproduce it", and we can't. Not reliably enough to get them to fix it. Looking at perf stats shows these times are when the GC goes into overdrive.

      But, everybody knows this. GC are designed to speed up allocations, with the performance penalty hitting when it needs to deallocate. Apologists say it's not a problem as the dealloc can take place in the 'slow time' when the CPU is not taxed, but the problem is thaat deallocating memory *is* an IO problem - you have to hit main page RAM to determine the blocks that need collecting, and you need to hit all of it (well, lots of it to check for dependencies between objects)

      Then there's the user problem - when told "the compiler will take care of memory for you, just use it, memory's cheap" most programmers do exactly that, and you see the GC allocating millions of blocks of RAM. Hence all the calls to use stringbuilder type classes for string manipulation - why would a language designer say that except that they know the 'magic' GC doesn't work perfectly, and this string concatentation case is the easiest fruit to pick to improve performance.

      Python's fine, but just use it as a tool for tasks its best suited to - a kind of perl replacement or prototype tool IMHO - and not for high performance computing tasks.

    8. Re:I hit a will with the garbage collection by Anonymous Coward · · Score: 0

      You are probably reading the whole log into memory and therefore swapping. Line IO should not give you any problems.
      I have parsed files much larger than 2 gigs with Python and log files are not complex structures.

    9. Re:I hit a will with the garbage collection by badkarmadayaccount · · Score: 1

      Stop the world garbage collector? Here's a nickel, kid, get youself a better VM. Tracing GC is hard to optimize, ref count is hard to implement, take a pick.

      --
      I know tobacco is bad for you, so I smoke weed with crack.
    10. Re:I hit a will with the garbage collection by ultranova · · Score: 1

      Stop the world garbage collector? Here's a nickel, kid, get youself a better VM.

      Use your nickel for coffee and wake up, so you realize that every thread will eventually run out of memory and join the melee for memory, and any ongoing memory access besides the garbage collector will simply make the trashing worse.

      Tracing GC is hard to optimize, ref count is hard to implement, take a pick.

      Ref counting isn't garbage collection. And since you don't actually seem to be disagreeing with me, what's your point?

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

  28. Re:Garbage Language For Shit Coders Like You by madprof · · Score: 1

    Ah, that is a really good troll. :) I am actually quite impressed. :)

  29. And so it died out... by Anonymous Coward · · Score: 0

    Those scripting languages guys are so stubborn when it comes to recognizing mistakes. That's not only that python guy, it's the perl and ruby community, too.

    Instead of building pragmatically and fast vms and new superior copying generational garbage collectors, they say "use C or C++".
    While i have to say that building a binding for your own code is not that hard, distributing them is terror. For example, it takes really much effort to get SDL for perl running on the system. And don't get me started on SDLx.
    While SDL is a must-have, you don't want to have more depedencies in binaries as needed. So in some cases, you just which a bytecode interpreter
      which is a bit faster. And I have those moments, daily.

    And there is a lot room for improvement due to that Euphoria benchmark:
    http://www.rapideuphoria.com/bench.txt

    At least, they should get up to pike or lua. And the fact, that a one-man project (Gambas) can beat all those languages in performance doesn't make it better.

    I hate to say, but PHP seems to learn from their mistakes. But Python, Perl and Ruby? No way. They can be happy, if they don't extinct like Tcl did in ten year.

  30. Monty Python: Not dead, er, too slow yet by UnknownSoldier · · Score: 1

    For some reason the title makes me think of Monty Python's Holy Grail, the "Not dead yet" line.

  31. Disagree by Anonymous Coward · · Score: 0

    I'm not trying to troll, but I hire a compiler to optimize my program. And a profiler to optimize further. What the python fans are saying is python is too slow, so use C++, and do it by hand. I'd much rather have a JIT take care of that for me, and if needed, in rare circumstances, I should intervene to make it even better.

  32. Management! Management! Management! by Anonymous Coward · · Score: 1

    Plus Python manages most of the memory management for you ....

    Python! It manages the management for you!

    Now if only we could get something like that for meatspace...

  33. Surprising by SlashV · · Score: 1

    I always find the statement that most of the time is spent in just a small part of the code tricky. I am not sure it is even true for many programs. I wrote some software for http://aichallenge.org/ and found that very many somewhat intensive operations accumulate, which made the python version of my software prohibitively slow compared to a C++ version I wrote, with no easy single performance bottleneck to blame.

  34. Oh please.. by Anonymous Coward · · Score: 0

    In other news, Pope claims he isn't very Catholic and bears claim they don't sh*t in the woods that often...

  35. Look, someone has to say it... by smcdow · · Score: 3, Insightful

    Integrated multi-language solutions are teh suck.

    I know that Python is much better than a lot of other languages for integrating C/C++ code. But in the end, if you're doing production systems, you'll end up getting bitten by some unforeseen incompatibility caused by some upgrade somewhere.

    It will happen.

    --
    In the course of every project, it will become necessary to shoot the scientists and begin production.
    1. Re:Look, someone has to say it... by Anonymous Coward · · Score: 0

      Yes, it will. Always, also if you just use one "language" (within one single runtime), also if you just update something unrelated. That's why you _test_ updates and only after successful tests roll them into production. No one can save you from that.

  36. Not getting it by Anonymous Coward · · Score: 0

    This is kind of Guido not getting it. He gets a lot of stuff, very smart guy in fact, but not entirely this.

    CPython is not blazing, but it's almost always fast enough.

    Yes, it's excellent to write 95% of your program in Python and then optimize the inner-most loop with C or C++ if that proves beneficial.

    Other important options include using Pypy for the whole program by changing your #! line, or Cython for just the innermost loop by translating your Cython code to C and building a Python "C Extension Module" from that, which can be imported much like normal Python code.

    But more importantly, CPython != Python! It did in the past, but that's really not at all true anymore.

    Pypy is really quite fast for uniprocessor tasks, and is a very compatible version of Python, albeit one that like CPython, still has a GIL.

    Jython and IronPython are Pythons that don't have a GIL, and hence thread well. I've not done much with IronPython since it doesn't have a Python Standard Library, but I found Jython surprisingly fast for long-running programs. Not as fast as Pypy, but pretty good for a VHLL written in Java.

    Nuitka appears to be coming along - it's a Python compiler. I've not yet tried it, but it sounds promising.

    For a microbenchmark comparing many different Python runtimes, check out:
    http://stromberg.dnsalias.org/~strombrg/backshift/documentation/performance/index.html

    The "pyx" rows are Cython. The others are probably pretty apparent.

  37. Not good enough by Anonymous Coward · · Score: 0

    That's still not a good excuse. People take the "optimize only the hot spots" bit too far sometimes. For an application developer, it's mostly a good strategy to only optimize hotspots. For language implementors this still doesn't let them off the hook!

    Think about it like this: your goal with performance optimization is to maximally leverage developer time "wasted" on optimizing. The small inner loop in your application that comprises 5% of the code but uses 95% of the CPU cycles is a clear win: optimizing this leverages your optimization efforts tremendously. Optimizing the 95% of the code that uses 5% of your CPU time does not.

    However, one also has to consider how often something is executed in total, globally. In other words, the more shared your code is, the more important its optimization is. The fluff bits of your one-off application that will probably be re-written or go away in a few years are never worth optimizing. But that shared library you wrote that 334 other projects will use and might last a decade? That's really worth optimizing the hell out of. A language interpreter is the ultimate case of this. The python interpreter is going to be running untold millions of peoples' applications for many years, in some cases decades before being replaced with a newer version of python. The multiplicative factor here is enormous enough that it's worth *every* effort to optimize any part of the language as much as possible.

  38. One problem is that it's unpredictable by Anonymous Coward · · Score: 0

    I replaced a Perl program with a Python rewrite the other day. This is a pretty simple program where most of the time is spent matching a single regex against a file of data. At first the Python version was literally twice as slow as the Perl. Which is ridiculous; both were spending most of their time performing the same amount of IO (written in C) or running a regex engine (written in C). Why was the Python so much slower?

    The answer boiled down to painfully slow method lookups. Python was looking up the "match" method in my compiled regex object every single loop iteration. A simple

    matcher = my_re_object.match

    brought Python up to the same speed as Perl.

    In short, until I applied a hideous optimization, my code was too slow even though most of it was already in C! Writing any more of it in C would have basically meant not using Python at all!

    Performing a basic micro-optimization by hand literally doubled performance. Why doesn't the compiler do that? If they really aren't going to add any optimizations to the Python compiler then I guess the only hope is to introduce a JIT.

    (And I mean "introduce a JIT to the standard Python distribution". Psyco and suchlike are all very well, but if it's not in the standard distribution, it might as well not exist. Most Python code has to make do with the basic installation and never gets any external modules made available. This is the whole reason why "batteries included" counts as an advantage versus Perl's enormous-but-external CPAN, guys!)

    ((Also: hang on, this doesn't even make sense. Why on earth is looking up __call__() faster than looking up match()? What the fuck, Python?))

  39. Same as in Smalltalk - diving below the "C" level by rsborg · · Score: 1

    That's what we used to call it when I was coding smalltalk in the 90s - we would identify sore-spots that couldn't be effectively coded in Smalltalk, rewrite those parts in pure C, and call them via DLL (we used Visual Smalltalk which easily worked with external libraries).

    This doesn't invalidate the assertion that Smalltalk+(a bit of C) is more efficient to develop in, but it does stretch it a bit to say that Smalltalk "isn't slow". The tradeoff in being able to pull up a walkback on any data element in the system (unlike Java, Smalltalk allowed you to convert primitive data elements into full-blown objects only when "inspecting") far outweighed the performance aspect, and we could optimize as needed.

    The downside to such an optimization scheme is that it does tie you to particular libraries, OS and machine architecture if those assumptions are not independent in the C code. It's also a pain to deal with two code languages if you aren't somewhat fluent. Code-generators in the primary (slow) language are somewhat helpful if you have lots of C to write.

    --
    Make sure everyone's vote counts: Verified Voting
  40. C is too slow compared to assembly! by danm_cj · · Score: 1

    To whoever complains Python is too slow compared to C. If you use a screwdriver as a hammer its your fault, not the screwdriver's.

  41. Want a good example? by Sycraft-fu · · Score: 5, Interesting

    Civilization 4. Firaxis wanted to make it nice n' moddable. So they scripted a bunch of it out in Python. Makes it real easy for users to edit in the field. However the AI they couldn't do that with. They wanted the users to be able to edit that too, but it was too slow in Python. So they did that in C++ and made it a DLL, and then distributed the sources. Harder to work on than a Python script, but fast enough that the game didn't bog down. The core of the game engine was C++ too and the Python was integrated with Boost.Python.

    Works really, really well. Again, the right tool for the job. If they'd tried to do the whole game in Python, it would have been a disaster performance wise (and I'm not even sure if it would be possible, if Python can call on DirectX in the way C++ can). However a mixture worked brilliantly.

    1. Re:Want a good example? by Anonymous Coward · · Score: 0

      It can. Rendering is not the problem in Python because you just call opengl or whatever. The problem in Python is things like list iteration which are slower than constipated snails.

  42. Honesty by massysett · · Score: 2

    It's nice when the proponents of a piece of technology can be honest about its shortcomings and acknowledge them, rather than trying to sell their technology. It's the honest response vs. the fanboy response.

    Problem: "It's too slow."
    Honest response: "Yeah, sometimes it is slow. Here are the design compromises that make this slowness necessary. Furthermore nobody has volunteered the manpower to make it faster. If you need something faster, try x."
    Fanboy response: "Yeah well, anytime I try to do something, it's fast enough."

    Problem: "There's practically no static typechecking."
    Honest response: "You're right, there isn't. There are ways you can deal with that, such as writing tests and thinking carefully about your code. The lack of static typechecking allows us to build a language that is better in this way and in that way. If you want static typechecking, try language x. Certainly there are advantages and disadvantages to the way we did things, but it best suited our objectives and if your objectives are aligned with ours, consider using our system."
    Fanboy response: "Yeah well, if you're relying on a compiler to catch all your bugs, you're in trouble."

    I know there are a lot of C++ haters here but having read some of what Bjarne Stroustrup has written, he typically offers honest responses, not fanboy responses. I was impressed with an article on the Arch Linux wiki once for the same reasons, as it gave an honest response to "it takes too long to install" (which was something like "yeah, it takes awhile, which has advantages and disadvantages. Try Ubuntu for quick installs.") rather than a fanboy response ("quick installs, who wants that crap anyway, it will just give you a junk system.")

    To be fair to GVR this was a short informal article; it may not be fair to expect him to expound in this kind of a format.

  43. What about pypy?? by Anonymous Coward · · Score: 0

    Right now, all the hipe in pythonland is centred around Pypy, the python-in-python jitted implementation of python, which is all the rage because of its performance (5.3x faster than cpython on average).
    However, It always surprised me that this project never got the propper attention from Van Rossum itself.
    He almost never talks about it, unless someone explicitly asks him. What's more, he always described himself as someone not worried about performance at all.
    He said he is not a "speed freak" implying that pypy is far from top on his list of cool things to follow.

    And now that Python is getting a lot of attention thanks to pypy's success, he comes up with a cooment like this.
    I'd like to hear once for all from him what he really thinks about the project...

  44. Actually, it works pretty well that way by Anonymous Coward · · Score: 0

    So maybe I'm just one of those idiots, but I've written some code that does heavy number-theoretic work in Python, and the performance is basically what you get out of an assembly-optimized piece of code. Why? Because I did exactly what Guido is suggesting here: I used an optimized C/assembly library for the parts where my code spends most of its time. Python has bindings for the GMP library, and my code spends over 99.9% of its time inside the GMP routines, which are a hell of a lot faster than anything I'm ever going to write.

    The end result? I have code that does elliptic curve calculations with moduli in the 200-kilobit range, running at nearly the same speed as a C program-- but I only had to write about 1600 lines of code in Python, versus a WHOLE lot more if I had written the code directly in C-- allocating, deallocating, dealing with intermediate values, etc. And it's a hell of a lot more clear and maintainable: I can write x = pow(base + 2, (exponenent1 - offset) / 2, modulus) instead of about 4 lines of C code (not counting variable allocation/deallocation). And the performance is basically the same, because 99% of the work is being done in the "pow" operation.

    So my code is indistinguishable from a performance standpoint. It's more easily maintained. How the hell is Guido crazy, here?

    1. Re:Actually, it works pretty well that way by Anonymous Coward · · Score: 0

      So my code is indistinguishable from a performance standpoint.

      Now scale it to 8 cores on an SMP machine.

  45. Oxymoronic by Anonymous Coward · · Score: 0

    This is an oxymoron: "self-resizing arrays and sane strings at bare-metal speeds". That's not bare-metal speed. You get bare-metal speed by using static data structures and static data. C++ doesn't do arrays or strings any faster or slower than a scripting language. That's because the code you need for either of those things is almost identical in all implementations from the perspective of the "bare metal".

    Now C++ can do loops and non-dynamic member function invocation faster than scripting languages. But that's because those things rely on less dynamic data than in the scripting engines. It's just a few jumps already cached and pipelined by the processor.

    Most C++ apps are insanely slow compared to their C counterparts because the C++ folks rely on all this dynamic stuff. They may as well just write their crap in Javascript or Python. All the C++ code written for benchmarks is basically a gussied-up version of the C code, which just gives C++ programmers permission to lie to themselves about why they use C++.

    1. Re:Oxymoronic by russotto · · Score: 2

      Most C++ apps are insanely slow compared to their C counterparts because the C++ folks rely on all this dynamic stuff. They may as well just write their crap in Javascript or Python. All the C++ code written for benchmarks is basically a gussied-up version of the C code, which just gives C++ programmers permission to lie to themselves about why they use C++.

      I use C++ for the STL (despite the awful syntax) and for better encapsulation. Boost scoped_ptr is nice too. Virtual functions are a nice alternative to switch() based dispatchers, but they don't need to be (and shouldn't be) used all the time. C was and is a great language. C++ is a horrible mess with a lot of nice features buried within.

      Exceptions are just plain awful. Either you have to handle them one level up from the throwing function (in which case you could have just returned an error code), or you have to pass them to higher and higher levels, each of which is less likely than the last to be able to handle it sensibly. Or you have to crash the process, which you might as well have done in the first place.

    2. Re:Oxymoronic by Anonymous Coward · · Score: 0

      There many things C++ does better than C; but there are even _better_ languages for those particular things. And it's much easier to integrate those languages with C than with C++. New features like lambdas will only take C++ into the realm of really, really difficult to integrate with. Why use C++ lambdas, for example, when I could use Lua closures and coroutines, both of which play well with C code. Why use C++ string objects when hacking text when I could use Ragel to generate a parser inline, with zero copying and possibly no dynamic memory management required at all? (And an infinitely nicer syntax than Spirit template frameworks.)

      So why use C++ at all? Really, the same reason you use Cobol or Java--'cause you have to.

    3. Re:Oxymoronic by lgw · · Score: 1

      This is an oxymoron: "self-resizing arrays and sane strings at bare-metal speeds". That's not bare-metal speed. You get bare-metal speed by using static data structures and static data. C++ doesn't do arrays or strings any faster or slower than a scripting language.

      Spoken like a C programmer. As long as you understand how C++ vectors and arrays work, they're dynamic or static, as you need. But if you mis-judge a size, you get slightly slower code instead of a security flaw.

      Most C++ apps are insanely slow compared to their C counterparts because the C++ folks rely on all this dynamic stuff

      Reality disagrees with your religion. Yes, if you don't write for performance, performance will be bad. If you do, you'll get compiler output that's the same as your crufty error-prone C.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    4. Re:Oxymoronic by lgw · · Score: 1

      Exception handling is a programming style needed for any modern programming language - C++ is only slightly worse because you don't get the stack trace passed in the exception object. So as a result you typically need to stuff some context information someplace so that the code that throws the error can log a better error message before throwing.

      Of course, don't catch the exception unless you can actually recover the problem. Typically in a job-based system, most execptions will be caught in the job framework, and logged as the reason for the job failure (or for a failure of one target in the job, if you're doing the same task across a set of targets). Crashing the process is fine, but at least you can log why, and do some graceful cleanup!

      Really, if you have some system error, what else are you ging to do? Fail the current task and try the next one. Exceptions mean you don't have to hijack the return value of every function in the world for this purpose, and so you can actually use the return value for ... returning a value!

      --
      Socialism: a lie told by totalitarians and believed by fools.
  46. Guido's wrong. by mbkennel · · Score: 1, Interesting

    "Hence what Guido is saying. You can do that "most stuff" part in python, and then write that "some stuff" part as a C module. You can then use that module from python. Thus you get the benefit of both languages."

    No you don't. If you had written it in C++ you could natively use C++ objects and libraries fluently.

    It takes more skill and system-programming knowledge to deal with the tricky interfaces between the internals of a Python interpreter and an external C++ program. The object structure in Python is obviously alien to the C++ object system. Of course there is always workarounds, but they are inconvenient and require arcane knowledge. Somebody who is an expert at Python internals doesn't think this is hard. Somebody who is an expert at computational algorithms but not compilers does think this is hard, and especially thinks this is something that they really do not have a desire to learn. Me, I have far more interest in spending my time reading a machine learning research paper rather than learning about some crufty programming interface.

    The article is a naive cop-out for not specifying a sufficiently good language in combination with implementation techniques (they go together). Guido could try to implement a whole bunch of new libraries in some external Lisp and see how much he likes it versus writing native Python code. It sucks.

    1. Re:Guido's wrong. by Altrag · · Score: 2

      Sure but if you save yourself 6 months of coding over the course of a two year project, you've got lots of spare time to figure out those internals. And by the time your next huge project rolls around, you'll just be that much further ahead of the game.

      Monoculture is rarely the best option in any large system, including computer systems. It might make things "better" in the short term (by some measure) but if you've used the wrong tool for the job, the cracks will show eventually no matter how theoretically "pure" you can claim your work to be.

    2. Re:Guido's wrong. by Terrasque · · Score: 4, Informative

      It takes more skill and system-programming knowledge to deal with the tricky interfaces between the internals of a Python interpreter and an external C++ program.

      Is this experience talking, or guesswork?

      Admittedly, I haven't had a need for it myself, but it looks easy enough. And you have plenty of options, too!

      1. Extending Python with C or C++

      2. ctypes

      3. Cython

      Examples for 1 and 2

      Example for 3

      --
      It's The Golden Rule: "He who has the gold makes the rules."
    3. Re:Guido's wrong. by MadKeithV · · Score: 1

      If you had written it in C++ you could natively use C++ objects and libraries fluently.

      C++ is pretty finicky when it comes to linking libraries with C++ objects. It's all platform-specific, and some quirks may make certain builds of your libraries incompatible with different builds on the same platform with different settings (e.g. iterator debugging settings, CRT linking, static members in static libraries linked to multiple DLLs in the same exe...). Is it hard? No, not really, it's perfectly manageable for for someone who is an expert at C++ internals.

      It takes more skill and system-programming knowledge to deal with the tricky interfaces between the internals of a Python interpreter and an external C++ program. The object structure in Python is obviously alien to the C++ object system.

      Since the object structure of C++ can be alien to C++ itself if you're not careful (see above), that's obviously true. So you'd try to keep your Python/C (not C++) interface as tight and limited as possible, ideally a single C function call which is actually very easy to wrap (as long as you don't need complex objects in or out). A lot of the things that Guido is referring to would be covered by that one use-case. Not all of them of course.
      Your single C function or a few of them can of course call into C++ objects once across the Python/C boundary.

      Of course there is always workarounds, but they are inconvenient and require arcane knowledge. Somebody who is an expert at Python internals doesn't think this is hard. Somebody who is an expert at computational algorithms but not compilers does think this is hard, and especially thinks this is something that they really do not have a desire to learn. Me, I have far more interest in spending my time reading a machine learning research paper rather than learning about some crufty programming interface.

      I suggest you take a look at boost::python. I have - it works well enough. It's not perfect but it provides an awful lot of the "difficult" scaffolding to expose C++ objects to Python and vice-versa. Once you get it set up it's actually relatively straightforward to use - the first class is the hardest.

  47. f2py by Anonymous Coward · · Score: 0

    I'm writing a very niche CFD code for aircraft design that will advance the state of the art in my particular, tiny, tiny field. It's almost all in Python because I can code up a GUI in a couple of days and use numpy and scipy for some heavy lifting that I would never have the mathematical skills to code myself. The final bit of esoteric number crunching that I do need to code I can write in a couple of hundred lines of Fortran (nothing more than F77 probably) and compile to pyd using the almost trivially easy-to-use f2py.

    I realise my app is not mainstream, but I challenge anyone to find me a better route to getting a usable product to market.

  48. That's not the problem with exceptions in C++ by Anonymous Coward · · Score: 0

    Exceptions are great in a garbage-collected language such as Java or Smalltalk or Lisp, because most programs allocate and manage a lot more little blocks of memory than they do other types of resource, and in a garbage-collected runtime environment it doesn't matter if you're half-way through initializing some complex data structure when something odd happens inside the constructor of one of your object's members and it throws an exception. The half-initialized data structure is just dropped on the floor and is cleaned up by the garbage collector. 95% of a program's resources are memory, and don't need special management to avoid leaking them if exceptions are thrown. In Java or Smalltalk you only need try/finally code to clean up actual resources such as synchronization locks, file handles, sockets, etc.

    But in C++, you don't have the safety net of the garbage collector. So you have to ensure exception safety for ALL of the code you write which calls anything which might possibly throw an exception. This turns out to be really hard, even with RAII techniques. In Java, the availability of exceptions as an error-handling mechanism has small costs and large benefits. For C++ projects with lots of manual memory management, it almost seems like the opposite is true.

    I work in the console game industry, and we don't use exceptions, ever, in game engines. We just completely turn them off, and use C-style return codes for error handling. We do a lot of manual memory allocation (and write our own memory allocators, and our own replacements for STL containers, and systems for defragmenting physical memory, and lots of similar trickery to help us absolutely make the most of the limited amount of RAM that consoles have. In a console game, a memory allocation failure means a hard crash--throwing an exception from operator new would be useless. And the small savings in code size from turning off exception support is nice too. But the biggest benefit, is we don't have to worry about writing exception-safe code. Because let me tell you, I've met some wizardly programmers in the game industry who can hand-optimize large chunks of vector math into unrolled assembly code for these consoles, but I've never met one who can consistently write bug-free, exception-safe C++ code. Some of our target platforms don't even support exceptions properly in their compiler and/or standard libraries.

    1. Re:That's not the problem with exceptions in C++ by lgw · · Score: 1

      But in C++, you don't have the safety net of the garbage collector. So you have to ensure exception safety for ALL of the code you write which calls anything which might possibly throw an exception. This turns out to be really hard, even with RAII techniques. In Java, the availability of exceptions as an error-handling mechanism has small costs and large benefits. For C++ projects with lots of manual memory management, it almost seems like the opposite is true

      If you find writing all exception-safe code all the time even a tiny bit difficult, you're doing it wrong. Really. The last large C++ codebase I architected had just 2 places where resource cleanup was done (and matched with allocation): shared_ptr and a library template. There were 0 memory leaks and 0 handle or other resource leaks, because it was just easier to use self-managing resources.

      II bet you've never seen this coding style. It's a whole different world.

      --
      Socialism: a lie told by totalitarians and believed by fools.
  49. or is it just bad code? by __aaltlg1547 · · Score: 1

    It's an interesting coincidence that I had a conversation just today with my company's software engineering manager. His observation was that most people including software engineers are wrong most of the time about what's making their code run inefficiently. It's easy to imagine that you have a scrap of slow code deeply embedded in your process that is bogging everything down, or that there's nothing wrong with the method, you're just running Python and Python is not as fast as C -- or assembly.

    He said that most of the time, what he found based on the evidence was that slow code was slow because it was doing something the programmer hadn't thought carefully about, like causing unnecessary swaps or having a wait where there shouldn't be one. Rarely did it turn out to be the language at fault.

    But I can see how it might be frequently characterized by the language, given that we all *know* Python is slower than C. But if I went into that inner loop and recoded it in C and made it so much faster, I won't bother to mention the extra steps I found inside the loop that should have been outside, one of which was a system call.. No, it's the LANGUAGE, not the fact that I could have made it run four times as fast in Python and that would have been fast enough.

    There's always the question of how fast is fast enough. If it takes me 40 hours to crunch my code, fix it and retest it and that cost the company $4000, I better be chasing a more-than-$4000 problem. And it better not be keeping me from chasing down a $20000 problem.

  50. Usually it is not Python that is slow by Anonymous Coward · · Score: 1

    Case in point: two months ago I was asked to reingeneer a batch process written in Python because it was too slow when processing large[r] amounts of data. It was designed as a nightly script to process several thousands of records, but when the number of records grew to 500k it started taking hours instead of seconds.
    Surprizingly, profiling showed that the whole slowdown was concentrated in one point where a bunch of SQL statements were appended one to another in a string, which in Python happened to be immutable. Changing a string to a list in one place (approximately 10 minutes worth of work, including diagnostics and changes in the unit test) improved the runtime for 1mln records from (projected) 72hours to 3 minutes.
    And I saved myself the trouble of rewriting a Python app in C++ - not the easiest endeavor.
     

    1. Re:Usually it is not Python that is slow by Anonymous Coward · · Score: 0

      So the problem with python is that people who use it are dumb? Noted.

  51. Python has limitations, just accept it by sirlark · · Score: 1

    There are some situations where optimizing small sections by linking in C/C++ code doesn't work. Callback function for integration/numercial methods libraries spring to mind. Writing the library so that non-professional programmers who are more interested in the science can use it, generally means having them write their callbacks in python. Where does the program spend most of its time? In the callback. Python is too slow.

    Also I've found that python has other limitations. I coded a simple recursive depth first search, and I'm happy to let it run for days/weeks on my data and n=128, but python's memory usage and artificial limits cause the python equivalent of stack overflows. I had to rewrite in C++... Not a speed issue, but python isn't great for everything

    1. Re:Python has limitations, just accept it by Skapare · · Score: 1

      Python is also limit in speed handling large number arithmetic. I've noted huge speed differences for exactly the same algorithm between Python and Pike (didn't need to write in C at all).

      --
      now we need to go OSS in diesel cars
  52. A common awkward case: enumerations by Anonymous+Brave+Guy · · Score: 1

    It does depend a lot on context. The examples you gave are very simple, and avoid any of the awkward areas.

    Consider a different example: calling a C library function that takes an enumeration type for one of its parameters.

    Typically, in C, you will have a file something.h that contains the interface for a library, including things like function prototypes and enumeration definitions.

    Unfortunately, this is all symbolic metadata that Python ctypes can't just read out of a shared object file. There is no handy way to have Python import all the enumerators from the header file and define them as symbolic constants, for example, or for Python to scan the header for function prototypes. Thus in practice we end up with things like ctypes argtypes and restype hassles, and with some sort of duplication of all the enumerators in Python code that then has to be maintained perfectly in sync with the underlying C interface.

    What's more, Python doesn't have a concept of enumerations as such; PEP 354 was rejected. That means the best you're going to do is define a whole bunch of named constants for the enumerators in Python, and have your argtypes indicate the corresponding underlying integer type. Oh, but then the underlying type of an enumeration varies depending on the enumerators themselves, so now the effective prototype of every function that uses your enum as a parameter or return value, and thus the corresponding Python ctypes argtypes and restype data, has to change just because someone added the wrong value to an enumeration.

    In short, Python/ctypes and C/enumerations are not a very happy mix. There are other techniques, as you mentioned, and tools for helping with automatic parsing of header files, and each approach has its own pros and cons. But there are plenty of cases where the overhead of calling from Python down to C code is unpleasant at best. As you can see from the Cython example you linked to, it's delusional to pretend that you can really just compile almost-unchanged Python code down to C, too. It doesn't take much of this hassle before you've lost most of the productivity benefit from writing in a higher-level language like Python, and you start thinking about writing a much wider chunk of your project in C just so you can move the Python-C bridge to a place in your architecture where the interface can be much simpler.

    This isn't to say that I disagree with writing high-level code in Python and calling down to C in specific cases. Sometimes it really does work almost transparently. Most of the time it's not too bad, and if each language is much better for the kind of code you want to write in it (as IME it often will be) then the overheads in both developer time and run-time performance are a modest price to pay. But it's not always as easy as the introductory examples might suggest.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  53. Developer productivity should *not* be dominant by Anonymous+Brave+Guy · · Score: 1

    It turns out that developer productivity is actually more important than almost anything.

    Developer productivity might be more noticeable than almost anything. However, I shudder to think how much safer and more productive the world would be, and what impressive things we might be doing with the computing power available to us today, if we hadn't trained the general population to believe that slow, bug-ridden, insecure, barely usable software is somehow acceptable or even unavoidable.

    These things each contribute a staggering drain on the global economy and the quality of human life. They just aren't as visible as a product that ships late or is missing a feature, because it's accepted as the norm that we wait half a minute each time our software loads a document, or we go and make a coffee while today's security patches are installed and the system reboots, or no-one really understands how to use $FEATURE in our business software anyway so we'll just file a support ticket and get back to it later, or the network is down this morning while MIS contain a virus outbreak (caused because Bob the CEO was too important to to read the IT policy and didn't know how to secure his laptop wireless connection anyway, which let someone install a backdoor, which in turn was exploited when dear old Susan in Accounts brought in the baby photos of her grandkids plus a bonus virus on a USB stick).

    It isn't even clear that doing better would cost much more in either developer time or money. It would, however, require a change in mindset, a demand for higher standards, and much better training, collaboration and support for developers, across the whole industry or at least enough of it to act as a catalyst. Unfortunately, a lot of people don't like change, particularly change that requires questioning ideas they've taken for granted for a long time and acknowledging that they might have been doing a bad job as a result of those ideas. Also, the people most qualified to inspire and set a good example are probably too busy doing real work in niches where their skills and experience are genuinely valued, leaving the mainstream to soak up consultant-driven "best practices" that have an engineering foundation roughly comparable to an inch of sand under a skyscraper.

    So, I think it turns out that developer productivity is more visible than almost anything. The jury is very much still out on whether it's more important.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  54. Loops... by 10101001+10101001 · · Score: 1

    If you write that just as a sort of simple-minded Python loop, at some point you will see that that is the bottleneck in your system.

    Perhaps that's because Python loops suck? I mean, literally, try writing a version of this in various languages and time them:


    value=0
    for i in xrange(1000000000):
      value=i

    At least the last time I tried it, just about every language but Python had a sensible execution time (read, without 20 seconds). Python? It takes minutes to execute. :/ And I don't think it's the result of some optimization either, as you can look at gcc's assembly to see it will at sufficiently low optimization actually produce the one billion loop and it still executes fast.

    --
    Eurohacker European paranoia, gun rights, and h
  55. Comment removed by account_deleted · · Score: 1

    Comment removed based on user account deletion

  56. Use Felix by Yttrill · · Score: 1

    Well of course Python is too slow. Guido clearly has no understanding of performance if he thinks you can simply replace tiny hotspots with C code, and no idea about interfacing either, if he thinks that's an effective way for an application programmer to work. If you want most of the convenience of a scripting language and performance like C you should use join the Felix project. It's a scripting language, but it compiles down to machine code, not bytecode. It's statically typed, though most of the time you'd never notice.

  57. Bundling is a pain by Anonymous Coward · · Score: 0

    Amen to this.
    Python is great until you have to face the bundling/packaging issues.
    Distribution of compiled code (where you can often get away with a single executable or library file) is an order of magnitude easier that distributing a python app where you essentially need to ship the python distribution along with your python code (and any wrapped libraries you add).
    I use pyinstaller for this purpose, but maintaining the packaging over years has been more complex than maintaining the code itself.

  58. Where does this 'slow' come from? by Anonymous Coward · · Score: 0

    Where does this idiot idea that Python is 'slow' come from, apart from whingeing Java ingenues?

    Python is not slow - its fast, literally about ten (10) times faster than Java and with a much lower memory bootprint.

    I don't think a lot of people understand that its a 'callout model' not a full 'virtual machine' like Java, and that has both advantages and disadvantages - mainly advantages.

    It is the most perfect prototyping language ever developed, and yes, if during profiling you find a chunk that needs to be superoptimised then DO it. Its how the language is designed - break that module out and do it in C/C++.

    And PLEASE, stop criticising Psyco. If you are criticising it you are not understanding it - NO, you can't pre-optimise code, the profile will always show you stuff you didn't expect. Psyco is a very successfull attempt at writing an auto-inline-optimizer, and I don't think any other language environment has such a thing.

  59. False dichotomy by Anonymous Coward · · Score: 0

    This is a false dichotomy. You don't have to choose between doing the project in C, or doing it in python + C. You could just use a high level language that offers good performance instead. Write it in ocaml or haskell and your code is just as short (or shorter) than python, but with an order of magnitude (or more) better performance.