[C++-sig] Why Python for C++ programmers

David Abrahams dave at boost-consulting.com
Sun Dec 8 16:23:49 CET 2002


"Paul F. Kunz" <Paul_Kunz at SLAC.Stanford.EDU> writes:

>    I didn't see my response for this show up in the archives, so I'll
> repeat it.   Sorry if it is indeed a duplication...
>>>>>> On Thu, 05 Dec 2002 15:36:34 -0500, David Abrahams <dave at boost-consulting.com> said:
>
>> Hi All,
>
>> In broad strokes, they're complimentary because:
>
>> * C++ is hard. Python is easy
>
>    If you are talking to a C++ audience, it doesn't seem like a way to
> make friends :-)

No, and I don't like the way the tone was coming out here.
However, even as a C++ jock, I have to admit it's true.

>> Other thoughts?
>
>    Your view of "complimentary" seems to focus on language.   My view
> is how Python and C++ can work together rather than trying to force
> everything into one language or the other.

Very nice, this is what I want to talk about.

>    Some examples...
>
> - Many C++ applications needs some set of parameters to intialize the
>   application before executing some simulation or analysis.   So some
>   initialization file with a particular syntax is invented.   This
>   file has to be parsed with C++.  But Python is much better at
>   parsing,

I think Joel de Guzman of the Spirit parser framework might argue with
you about that... but I take your point.

>  so if you expose the appropriate `setXXX' methods in the
>   C++ code to Python, one can use Python to parse the file.


> - One expand upon the above one better.  Eliminate the initialization
>   file and just tell people to write Python code.  This has the
>   advantage that one can use Python as a programing language to set
>   parameters.  For example, if a simulation has 100 layers of
>   something, set at certain distances, a Python for loop can be use.
>   If one only had a static initialization file, one would have to type
>   in the number corresponding to each layer.

Yes, I agree. Python literals are extremely powerful and expressive.

>
> - If the above has been done, then one gets for free the ability to
>   change the parameters of the program interactively.   Also read back
>   results and do something useful with them, instead of writing to a
>   file and having to run another program to parse that file.
>
> - If one has two C++ programs, written independently, perhaps by
>   different organization, it is often quite difficult to take the
>   output of one and feed it to the next.   But if both have the the
>   appropriate parts exposed to Python, then python can be the glue
>   between them.
>
>    Hope you might find this useful.

very much, thanks.

-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list