473,385 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Back to the future - python to C++ advice wanted

During the last 18 months or so I have indulged in the joy of learning
and using python for almost everything, but I may have to go back to
C/C++ at work. Suddenly I found myself transliterating (or translating
at least) common python idioms and patterns, looking for libraries to
replace python's "included batteries" or writing my own from scratch,
(over)using templates in an attempt to mimic duck typing, and so on.
Still, I am not sure if this is a good idea in general since every
language has its own idiosyncrasies, and this is obvious when one sees
python code looking like C or Java. OTOH, bringing python's higher
level of expressiveness to C/C++ might actually be a good thing,
leading to cleaner, safer code.

So, I wonder what have others who have gone the same path done and
learned in similar situations. How one can avoid the frustration of
having to work with a low level language once he has seen the Light ?

George

Jul 19 '05 #1
7 1311
George Sakkis wrote:
During the last 18 months or so I have indulged in the joy of learning
and using python for almost everything, but I may have to go back to
C/C++ at work. (snip) So, I wonder what have others who have gone the same path done and
learned in similar situations. How one can avoid the frustration of
having to work with a low level language once he has seen the Light ?

Well, I'm lucky enough to not to have to use C++ again, so I can't
answer directly. But I think this might interest you:
http://www.boost.org/
(NB : never tried it myself, but seems to be a nice job)

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jul 19 '05 #2
In article <42**********************@news.free.fr>,
bruno modulix <on***@xiludom.gro> wrote:
George Sakkis wrote:

Jul 19 '05 #3
On 2005-06-17, George Sakkis <gs*****@rutgers.edu> wrote:
So, I wonder what have others who have gone the same path done and
learned in similar situations. How one can avoid the frustration of
having to work with a low level language once he has seen the Light ?


This project:

http://astrolabe.sourceforge.net/

....is implemented in both Python and C++. I do the Python version first and
then translate to C++ as directly as possible, using namespaces, exception
handling, the standard string type and STL library.

Let me second the recommendation of the Scott Meyers books. And another which
I no longer have -- something like "The C++ Memory Model" -- was very
instructive.

-Bill
--
Sattre Press In the Quarter
http://sattre-press.com/ by Robert W. Chambers
in**@sattre-press.com http://sattre-press.com/itq.html
Jul 19 '05 #4
D H
George Sakkis wrote:
During the last 18 months or so I have indulged in the joy of learning
and using python for almost everything, but I may have to go back to
C/C++ at work. Suddenly I found myself transliterating (or translating
at least) common python idioms and patterns, looking for libraries to
replace python's "included batteries" or writing my own from scratch,
(over)using templates in an attempt to mimic duck typing, and so on.
Still, I am not sure if this is a good idea in general since every
language has its own idiosyncrasies, and this is obvious when one sees
python code looking like C or Java. OTOH, bringing python's higher
level of expressiveness to C/C++ might actually be a good thing,
leading to cleaner, safer code.

So, I wonder what have others who have gone the same path done and
learned in similar situations. How one can avoid the frustration of
having to work with a low level language once he has seen the Light ?


That's why so many people have switched to Java or C# (or Python and
other langugages of course). You might talk to them about using Python,
since Python and C/C++ fit together very nicely (with tools like BOOST,
SWIG, Pyrex,...). But me personally I like to avoid C++ altogether when
possible, and use Java or C# instead, both of which also can be combined
with python or python-like languages such as jython, groovy, or boo.
Jul 19 '05 #5
D H wrote:
That's why so many people have switched to Java or C# (or Python and
other langugages of course). You might talk to them about using Python,
since Python and C/C++ fit together very nicely (with tools like BOOST,
SWIG, Pyrex,...). But me personally I like to avoid C++ altogether when
possible, and use Java or C# instead, both of which also can be combined
with python or python-like languages such as jython, groovy, or boo.


But accessing Java packages from jython does not reduce effecively the
underlying pain. Personally I favour for programming in C++ over Java,
because I feel at least the mind of an evil genius ( C++ template
programming is Turing complete, operator overloading enables objects
having a builtin groove ) where Java is plain mediocrity. In spirit it
is a kind of Anti-Python.

I recommend studying C++ idioms carefully.

http://www1.bell-labs.com/user/cope/...uroPLoP98.html

If Georges starts on greenfields he may have a look at Qt and it's
object library which is not only concerned with widgets.

http://doc.trolltech.com/3.3/

BOOST is more high brow and I guess that it compiles slow because it
uses templates extensively. Template metaprogramming as a compile time
language was a funny discovery. Here is some prove of it's
capabilities:

http://osl.iu.edu/~tveldhui/papers/2003/turing.pdf

Regards,
Kay

Jul 19 '05 #6
"Kay Schluehr" wrote:
I recommend studying C++ idioms carefully.

http://www1.bell-labs.com/user/cope/...uroPLoP98.html
Thanks for the link; very useful indeed.
If Georges starts on greenfields he may have a look at Qt and it's
object library which is not only concerned with widgets.

http://doc.trolltech.com/3.3/

BOOST is more high brow and I guess that it compiles slow because it
uses templates extensively. Template metaprogramming as a compile time
language was a funny discovery. Here is some prove of it's
capabilities:

http://osl.iu.edu/~tveldhui/papers/2003/turing.pdf


Many thanks to Kay and Bruno for suggesting Boost; I browsed through
its numerous libraries and they're quite impressive ! They seem
indispensable, especially for python (or other very high level
language) programmers going back to C++. Some libraries that seem to be
very relevant to pythoneers are:

- any: brings dynamic typing in C++
- tuple; 'nuff said
- iterator: out-of-the-box equivalents of
itertools.{imap,ifilter,izip,count}, reversed(), and others not
existing or applicable in python
- tokenizer, string_algo and regex: similar functionality to str.* and
re.*
- bind, mem_fn, function, functional, lambda: first class callables,
currying, higher order (functional) programming
- assign: syntactic sugar through operator overloading for (relatively)
readable container initialization:
map<int,int> next = map_list_of(1,2)(2,3)(3,4)(4,5)(5,6);
is actually valid and equivalent to
next = dict([(1,2), (2,3), (3,4), (4,5), (5,6)])
- many, many more goodies, with or without respective standard python
equivalent (threads, graphs, math utils, serialization,
metaprogramming, etc).
- and last but not least, Boost.Python. I don't think it's just a
coincidence that among all languages they chose Python to make
interoperable with C++ :-)

Thanks again,
George

Jul 19 '05 #7
On 17 Jun 2005 06:26:50 -0700, George Sakkis <gs*****@rutgers.edu> wrote:
During the last 18 months or so I have indulged in the joy of learning
and using python for almost everything, but I may have to go back to
C/C++ at work. Suddenly I found myself transliterating (or translating
at least) common python idioms and patterns, looking for libraries to
replace python's "included batteries" or writing my own from scratch,
(over)using templates in an attempt to mimic duck typing, and so on.
Still, I am not sure if this is a good idea in general since every
language has its own idiosyncrasies, and this is obvious when one sees
python code looking like C or Java.

So, I wonder what have others who have gone the same path done and
learned in similar situations.
I feel exactly like you described, both when I move from C++ to Python, and
when I move from Python to C++. I think most multi-language programmers
feel like this, and I don't think there's anything wrong with it.

What I do? I try to keep calm and resist the temptation to write C++ code
in Python and the other way around. Why? Because I know how much I hate C++
code written as if it was Java, or C, or Smalltalk.

(rearranged from above) OTOH, bringing python's higher
level of expressiveness to C/C++ might actually be a good thing,
leading to cleaner, safer code.
Maybe. On the other hand, you risk messing up the things that make idiomatic
C++ clean and safe: static typing, const correctness, conservative use of
inheritance and polymorphism, ... And in the end: will other C++ programmers
hate your code? Will they modify it without butchering your original
design?
How one can avoid the frustration of
having to work with a low level language once he has seen the Light ?


I wouldn't call the modern C++ you (since you don't seem to be afraid of
templated) use a "low level language". It does different choices compared to
Python when it comes to run-time efficiency versus usability, and so on.

But yes, programming in C++ is usually more tedious and frustrating -- and
less fun.

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
5
by: John Ladasky | last post by:
Hi, folks, At the beginning of 2003, I was a frustrated computer user, and lapsed programmer, with problems to solve that screamed for programming. Thanks to the Python language and community, I...
75
by: Xah Lee | last post by:
http://python.org/doc/2.4.1/lib/module-re.html http://python.org/doc/2.4.1/lib/node114.html --------- QUOTE The module defines several functions, constants, and an exception. Some of the...
1
by: Ron Davis | last post by:
I have recently discovered Python and like it quite a bit. I would like to use it on a new project I am starting. The project will gather data from several web services and present the collected...
69
by: notbob | last post by:
I'm not posting this just to initiate some religious flame war, though it's the perfect subject to do so. No, I actaully want some serious advice about these two languages and since I think usenet...
75
by: kwikius | last post by:
My hunch is my posts to clc++ are disappearing down a hole, so I post here instead. Future of C++ thread on clc++ "Abhishek" <nospam_abhishekpandey@yahoo.comwrote in message...
8
by: Derek Martin | last post by:
I'd like to know if it's possible to code something in Python which would be equivalent to the following C: ---- debug.c ---- #include <stdio.h> bool DEBUG;
20
by: timotoole | last post by:
Hi all, On a (sun) webserver that I use, there is python 2.5.1 installed. I'd like to use sqlite3 with this, however sqlite3 is not installed on the webserver. If I were able to compile sqlite...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.