Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Python Programming

Van Rossum: Python Not Too Slow 510

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.'"
This discussion has been archived. No new comments can be posted.

Van Rossum: Python Not Too Slow

Comments Filter:
  • 007087 (Score:5, Insightful)

    by Anonymous Coward on Friday March 16, 2012 @04:38PM (#39382529)

    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!

    • Re:007087 (Score:5, Insightful)

      by Pieroxy ( 222434 ) on Friday March 16, 2012 @04:51PM (#39382707) Homepage

      And to add to that:

      Python Not Too Slow

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

    • Re:007087 (Score:5, Insightful)

      by tomhath ( 637240 ) on Friday March 16, 2012 @05:24PM (#39383229)

      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.

      • Want a good example? (Score:5, Interesting)

        by Sycraft-fu ( 314770 ) on Friday March 16, 2012 @07:24PM (#39384657)

        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.

    • 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 d

  • Agreed. (Score:5, Insightful)

    by Anonymous Coward on Friday March 16, 2012 @04:43PM (#39382611)

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

  • by l0ungeb0y ( 442022 ) on Friday March 16, 2012 @04:47PM (#39382657) Homepage Journal

    "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.

    • by Cogita ( 1119237 ) on Friday March 16, 2012 @05:10PM (#39383033)

      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.

    • by Frnknstn ( 663642 ) on Friday March 16, 2012 @05:13PM (#39383075)

      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++.

  • by busyqth ( 2566075 ) on Friday March 16, 2012 @04:47PM (#39382663)
    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."
    • Re: (Score:2, Insightful)

      by Anonymous Coward

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

      • by MattBD ( 1157291 )
        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.
    • Corollary:
      Van Rossum: Python Not Much Worse Than Perl
      Just had to be said.

  • by XxtraLarGe ( 551297 ) on Friday March 16, 2012 @04:50PM (#39382695) Journal
    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.
    • by AuMatar ( 183847 )

      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 t

    • 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 :)
    • 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.

    • by caseih ( 160668 )

      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 interfa

  • usually? (Score:5, Insightful)

    by v1 ( 525388 ) on Friday March 16, 2012 @04:56PM (#39382811) Homepage Journal

    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.

  • Personally (Score:5, Informative)

    by ciascu ( 1345429 ) on Friday March 16, 2012 @04:58PM (#39382835) Journal

    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.

  • Purists! (Score:4, Insightful)

    by macraig ( 621737 ) <mark@a@craig.gmail@com> on Friday March 16, 2012 @05:01PM (#39382903)

    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.

  • Metaphor (Score:4, Insightful)

    by Ukab the Great ( 87152 ) on Friday March 16, 2012 @05:04PM (#39382947)

    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.

  • Python's problem (Score:5, Informative)

    by spiffmastercow ( 1001386 ) on Friday March 16, 2012 @05:04PM (#39382957)
    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.
    • by Hentes ( 2461350 )

      Multithreading is only a problem in CPython. Other interpreters like Jython, IronPython or PyPy all have facilities for multithreading.

  • by istartedi ( 132515 ) on Friday March 16, 2012 @05:05PM (#39382973) Journal

    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.

  • by Animats ( 122034 ) on Friday March 16, 2012 @05:09PM (#39383017) Homepage

    Says the guy whose whole life is tied up in the language, and whose project, at Google, to speed it up, crashed and burned. [wikipedia.org]

    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".)

    • by Hatta ( 162192 )

      (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.

    • by steveha ( 103154 ) on Friday March 16, 2012 @06:30PM (#39384047) Homepage

      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/ [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 [python.org]

  • by Teckla ( 630646 ) on Friday March 16, 2012 @05:11PM (#39383045)

    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.

    • by kisielk ( 467327 )

      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

    • by MrSteveSD ( 801820 ) on Friday March 16, 2012 @05:38PM (#39383427)

      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.

      • by pavera ( 320634 ) on Friday March 16, 2012 @07:21PM (#39384615) Homepage Journal

        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.

    • by steveha ( 103154 ) on Friday March 16, 2012 @06:57PM (#39384349) Homepage

      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 [gomaa.us] 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 [python-guide.org]

      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

    • by pavera ( 320634 )

      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

    • 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 [python.org]:

      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. Fo

    • 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

  • Donald Knuth (Score:4, Informative)

    by JohnWiney ( 656829 ) on Friday March 16, 2012 @05:15PM (#39383121)
    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.
  • Not that he was the first to say these things, but that book says them so *well*.
  • by smcdow ( 114828 ) on Friday March 16, 2012 @06:07PM (#39383805) Homepage

    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.

  • by massysett ( 910130 ) on Friday March 16, 2012 @07:28PM (#39384701) Homepage

    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.

One man's constant is another man's variable. -- A.J. Perlis

Working...