To us, here and now, it appears thus.

rants, ramblings and other things that make life worth living…

Don’t program in python because you can.

with one comment

Removed on request.

  • I am not a C/C++ apologist ( and I generally hate having to use C++)
  • I like modern (and am a fan of) ( or languages which have caught up to the 70/60’s) like Python, Ruby, etc..
  • Infact I am designing something very similar to one, and can appreciate them for what they are.
  • Though I’vent got professional programming experience, I’ve still hacked around sufficient code to make me talk about the issues in this post.
  • I believe in writing efficient solutions to problems, so If it means I need to use C++/C then by all means I shall do that.
  • These are some comments I got when I suggested ‘not’ using python for a particular project. (It is a framework for swarm intelligence). here are some excerpts and my replies. I am not replying in mail because I want to get work done rather than starting unnecessary flamewars. In the process of answering/responding to the issues raised I will also try to show why I came to the descicion. (note, my comments are in blue)

    *************************
    Comment 1:-

    Your student has no clue what he is talking about .
    Hmm.. lets see

    1. Threading : threading in python seems to be at the bytecode level,
    and hence threading is pretty useless for programs with lots of worker
    threads.. So threading has to be handled in C++(meaning loss of
    portability). Its only good for run of the mill programs with a single
    worker thread and one i/o thread.

    yes . This assumes you have to write threads *in python* .If you need
    c threads all you have to do is interface python to (say) pthreads

    And what was I saying when I meant ‘threading has to be handled in C++’, pthreads is not very good on win32 (yes, there is a pthreads win32 port) , and if you want portability you would be better of using a C++ abstraction, or better writing your own.

    .Having said that though,I have never seen a situation where python
    threads were not enough .

    Maybe you’ve never had the need to program a concurrent framework where one of the primary motives is to have ‘ lots (thousands) of concurrent agents’. In that case, bytecode level threading will kill you.

    If you need to hack into OS threading *in
    large nnumbers* there’s probably something wrong with your concurrency
    model and you should look at declarative or message passing
    concurrency before you start fiddling with threads on *any platform* .

    Message passing concurrency! are you kidding me, which is more easier twiddling local variables or setting up huge data structures and passing them around? (Even if it is supported within the language there is this overhead of ‘passing messages’ ). And btw, I don’t really have a cluster handy to do mp anyway.

    “The study of concurrency requirements in software is not as trivial
    as "bytecode threads are bad , os level threads are good" .

    Now assume you have the hardest case, you for some exotioc reason MUST
    HAVE portable , huge numbers of threads. In which case you look for
    something called "Stackless Python" . but thisis very very rare and as
    far as i can see you guys don\’t need it .

    > 2. Speed : Python even though has lots of nice data structures, most
    > of it are comparitively slow for huge numbers.. ( i tried a huge
    > (6000- random values) python dict vs c++ map, and C++ map was way
    > faster, atleast on my comp.) Also, NumPy and SciPy seem to be pretty
    > powerful and quite fast, and most web results say they are as good as
    > C++ code..

    again this is a stupid test . The idea of python is not to compete
    with C++ on speed.
    the reason why Scipy and NumPy are as fast as c code is that the
    executing code *is* written in C/fortran . SciPy and NumPy just layer
    python on top of c/fortran libraries like lapack and blas .

    > I don\’t think that 2 will be such a big problem (we can always convert
    > python data structures to C++ code later), but 1 might.

    Ridiculous.You don\’t need to *convert* . You can tap directly into any
    cpp based ds library .

    > But python seems to be excellent in writing GUI code. So my best bet
    > will be to call C++ code for much of the threaded swarm code and use
    > python as a nice gui over a C++ library..

    As above, this is flawed conclusion based oon inexperience.

    > Also python\’s GL facilities are simply too cool.. maybe we should use
    > python as a nice scripting language for GL.

    doh!

    > I very much would like your thoughts on the above issues that i\’ve
    > been looking.. these are just what i felt from looking into python for
    “,1] ); //The study of concurrency requirements in software is not as trivial
    as “bytecode threads are bad , os level threads are good” .

    This is not about general requirements for software ( I am not writing a web-browser or an e-mail client). I am writing a concurrent agent framework where I need massive concurrent execution. And since I don’t exactly have a compute cluster around to do all the fancy stuff and get sufficient efficiency I need to pump out every ounce that my humble p4 uniprocessor can give me, so
    ‘Bytecode threads are bad, os level threads are good’.

    Now assume you have the hardest case, you for some exotioc reason MUST
    HAVE portable , huge numbers of threads. In which case you look for
    something called “Stackless Python” . but thisis very very rare and as
    far as i can see you guys don’t need it .

    exotic reason : see above.
    “Stackless python : ” – still very much in its infancy, I will be betteroff with C++ (tried and trusted).

    > 2. Speed : Python even though has lots of nice data structures, most
    > of it are comparitively slow for huge numbers.. ( i tried a huge
    > (6000- random values) python dict vs c++ map, and C++ map was way
    > faster, atleast on my comp.) Also, NumPy and SciPy seem to be pretty
    > powerful and quite fast, and most web results say they are as good as
    > C++ code..

    again this is a stupid test . The idea of python is not to compete with C++ on speed.
    And when I need speed its very stupid to use python isn’t it?

    the reason why Scipy and NumPy are as fast as c code is that the
    executing code *is* written in C/fortran . SciPy and NumPy just layer
    python on top of c/fortran libraries like lapack and blas .

    Yup I know, thats why I say they are pretty good. which brings back to my old point, use C++ when you need speed and efficiency.

    > I don’t think that 2 will be such a big problem (we can always convert
    > python data structures to C++ code later), but 1 might.

    Ridiculous.You don’t need to *convert* . You can tap directly into any
    cpp based ds library .

    Agreed. but again, going back to C++ aren’t we?

    > But python seems to be excellent in writing GUI code. So my best bet
    > will be to call C++ code for much of the threaded swarm code and use
    > python as a nice gui over a C++ library..

    As above, this is flawed conclusion based on inexperience.

    Maybe, but tell me something better which gives me the efficiency of C++ and ease of writing a gui front-end using python.

    > Also python’s GL facilities are simply too cool.. maybe we should use
    > python as a nice scripting language for GL.
    doh!
    > I very much would like your thoughts on the above issues that i’ve
    > been looking.. these are just what i felt from looking into python for
    > the past 2 days, and whatever i know of it before.. I could be wrong
    > so i am open to ideas regarding python etc..

    duh you should stop asking inexperienced students to reccomend
    software platforms?

    ********************
    Comment 2:- (In response to the following mail send by you)
    > Respected Madam,
    >
    > I was initially very much excited about python, but digging deeper I
    > already found two problems with python, but what still excited me was
    > that python was garbage collected so I din\’t really have to bother
    > with memory management at all.. And it had a whole bunch of
    > libraries.. but the thing is I still consider C++ way better to
    > python, even after garbage collection because of this Nice little C++
    > trick that I found out..
    >
    > The most common reason for a memory leak (apart from sloppy
    > porgramming is nesting of functions)
    >
    > If a function returns primitive data types it is fine to call them
    > directly because there is no need for memory management, however if
    > they return objects on the heap which will become a problem when there
    > is a nested function call then we can define a class with the
    > function\’s name and make the default constructor have the same
    > function parameters, and overload the casting operator to the return
    > type, also destroy the object on the heap in the classes destructor..
    >
    > I\’ve put up a much more detailed post about this on
    >
    > http://www.livejournal.com/~vishnuvyas
    > waiting for your views on this..
    >
    > also i\’ve already done a simple Thread Class in C++ to encapsulate
    > over the pthreads api.. and working on an abstract function class
    > based on the above idea..
    >
    “the past 2 days, and whatever i know of it before.. I could be wrong
    > so i am open to ideas regarding python etc..

    Ok, the looking into python for the past 2 days was in relevance to the framework, I’ve been looking and hacking around python for atleast 1.5 years now.

    duh you should stop asking inexperienced students to reccomend
    software platforms?
    ********************
    Comment 2:- (In response to the following mail send by you)
    > Respected Madam,
    >
    > I was initially very much excited about python, but digging deeper I
    > already found two problems with python, but what still excited me was
    > that python was garbage collected so I din’t really have to bother
    > with memory management at all.. And it had a whole bunch of
    > libraries.. but the thing is I still consider C++ way better to
    > python, even after garbage collection because of this Nice little C++
    > trick that I found out..
    >
    > The most common reason for a memory leak (apart from sloppy
    > porgramming is nesting of functions)
    >
    > If a function returns primitive data types it is fine to call them
    > directly because there is no need for memory management, however if
    > they return objects on the heap which will become a problem when there
    > is a nested function call then we can define a class with the
    > function’s name and make the default constructor have the same
    > function parameters, and overload the casting operator to the return
    > type, also destroy the object on the heap in the classes destructor..
    >
    > I’ve put up a much more detailed post about this on
    >
    > http://www.livejournal.com/~vishnuvyas
    > waiting for your views on this..
    >
    > also i’ve already done a simple Thread Class in C++ to encapsulate
    > over the pthreads api.. and working on an abstract function class
    > based on the above idea..
    >
    D([“mb”,”> But I think we may still need python for gluing a User Interface onto
    this.
    >
    > yours sincerely
    > Vishnu Vyas
    >

    This guy seems to have some kind of c++ fixation .
    If he likes c++ , good for him , but ask him not to criticise a chair
    for not being a table!

    His hacks on c++ are amusing.
    But on what level does this have anything to do with the suitability
    or otherwise of Python/SciPy for scientific computing ?

    here is a prediction for you . If you ask this person to write
    scientific software (and you shouldn\’t) prepeare to hear more of "my
    code doesn\’t work/isn\’t fast enough etc etc because we are using
    Python .If only I were using c++ … ".In the Industry this is known
    as the "Java is broken" argument for poor performance !Seriously this
    is a *known* sign of poor programmers.

    n short, asking inexperienced people to judge between software
    platforms is inmy *humble* opinion a big waste of time .To judge
    between any two software platforms you need people with immense
    experience on *both* platforms!

    *********************
    Comment 3:-
    To get a second opinion (just in case i was being too harsh – i have a
    very low tolerance for fools ),
    i asked ???? to take a look at Vishnu\’s C++ code on his blog .

    after reading your students\’blog with his c++ "trick" , ???? said
    on yahoo messenger ..

    ????: who is this?
    ????: he is talking heap/stack and crap without having clue about it

    to sum up , let me repeat . SciPy is good for ALL your needs for the
    next 5 years .Unless you have GOD level programmers in plenty , do not
    use C++ . You wil spend YEARS debugging.
    “,1] ); //But I think we may still need python for gluing a User Interface onto
    this.
    >
    > yours sincerely
    > Vishnu Vyas
    >

    This guy seems to have some kind of c++ fixation .

    No I don’t have a C++ fixiation, and I would anyday trade in LISP/Smalltalk for C++, yeah, thats when I am not bothered about efficiency and all that. But, when I need efficient solutions I don’t mind jumping to assembler if the need arises.

    If he likes c++ , good for him , but ask him not to criticise a chair
    for not being a table!

    Yeah,It is wrong to critcise a chair for being a table, the same way its inapropriate to use a chair to serve dinner for 4 .

    His hacks on c++ are amusing.
    But on what level does this have anything to do with the suitability
    or otherwise of Python/SciPy for scientific computing ?

    1. It takes the headache of memory management (to a certain extent), so I can use C++ to access the C/C++ core of SciPy or any other scientific library. And you seem to forgetting the fact the the Framework has little to do with SciPy as such. It just provides a pluggable interface to SciPy rather, and whats wrong in developing the framework in C++.

    2. It gives me higher order functions, which is a nice thing to have since now your exceptions can throw these higher order functions which can do a lot of setup required for the error handler.

    here is a prediction for you . If you ask this person to write
    scientific software (and you shouldn’t) prepeare to hear more of “my
    code doesn’t work/isn’t fast enough etc etc because we are using
    Python .If only I were using c++ … “.

    No, If I do end up using python I would *know* that my code would be fast enough with C++, but I ‘have’ to use it nevertheless. I choose a programming language for a reason, not because I can program in them.

    Btw, a framework is more of a typical SE problem than a problem in Scientific Computing.

    In the Industry this is known
    as the “Java is broken” argument for poor performance !Seriously this
    is a *known* sign of poor programmers.

    Ok, NEWSFLASH – Java IS broken. Java is a nice language and all that, it might be suitable for writing fancy applets that lets you play chess on yahoo, but atleast SWING/AWT is definitely broken. Eclipse an extensible-Ide for java , They had to write their own windowing toolkit because Java’s wasn’t good enough. Well, I don’t usually like making microsoft look good, but look at any of the programs written in the .net languages and compare it to those wrtiten in java. Not only are they significantly faster and more responsive, they are pretty good too.

    But this is not about java anyway. so I will let that pass.

    n short, asking inexperienced people to judge between software
    platforms is inmy *humble* opinion a big waste of time .To judge
    between any two software platforms you need people with immense
    experience on *both* platforms!

    Not necessary, anyone with even slightest sense can discern between whats apt and whats not, when they have enough idea about the domain of their problem.

    Also, in my *humble* opinion, asking experienced people about what *you* need is a big waste of time, because they will always tell you what they thought they were comfortable with.

    *********************
    Comment 3:-
    To get a second opinion (just in case i was being too harsh – i have a
    very low tolerance for fools ),
    i asked ???? to take a look at Vishnu’s C++ code on his blog .

    this is the C++ trick he refers to.

    after reading your students’blog with his c++ “trick” , ???? said
    on yahoo messenger ..

    ????: who is this?
    ????: he is talking heap/stack and crap without having clue about it

    Mr unknown yahoo person,

    I completely know what I am talking about, btw, there is no confusion about stack/heap there. and btw, if you actually go through it, you will find out that it is meant for functions which returns pointers to objects which are allocated using the C++’s new operator inside the function. It is just that it is in a more concise style.

    to sum up , let me repeat . SciPy is good for ALL your needs for the next 5 years .

    which does not involve writing a Framework, because a framework involves very little with the algorithms themselves, and is concerned with an environment to test those algorithms. (the algorithms might need SciPy, which is a totally different story).

    Unless you have GOD level programmers in plenty , do not
    use C++ . You wil spend YEARS debugging.

    Assuming you write extremely sloppy C++ code, btw, have you heard of garbage-collectors (for C++), profiling tools, lint, etc?

    And you don’t need to be GOD level programmer when you need to write C++ code, you just need to be careful not to shoot yourself in the foot. btw, some-one who shoots himself in the foot should not be left to handle guns in the first place.

    The reasons for suggesting C++ as the core language of the framework, from my point of view

    1. One of the primary motives of the framwork is to support concurrent agents, so good (as in efficient, not easy to code in) thread support is a must.
    2. This is a framework which will probably be plugged in with other code which may be executed concurrently, so it needs to have fast data structures.
    3. C++ flexibility, since most languages have bingings to C/C++ I can write my algorithms in any language provided the framework provides a decent binding api.

    But this doesn’t necessarily preclude python from the development, but it can only be used as glue, leaving
    the core to C/C++.

    I could be entirely wrong in what I’ve said before, and I am open to people who prove me wrong, but not about people, who rant because of their concieted notions of what they think is right.
    –>
    Signing off,
    Vishnu Vyas.

    Advertisements

    Written by vishnuvyas

    August 4, 2005 at 1:27 pm

    Posted in Geeky Stuff

    One Response

    Subscribe to comments with RSS.

    1. This post has been removed due on request. Even those who have read this post , please refrain from commenting on it anymore.

      Vishnu Vyas

      August 5, 2005 at 11:14 am


    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

    %d bloggers like this: