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

Paul F. Kunz Paul_Kunz at SLAC.Stanford.EDU
Sun Dec 8 01:38:22 CET 2002


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

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

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





More information about the Cplusplus-sig mailing list