tags:

views:

935

answers:

8

I'm a long time C++/Java developer trying to get into Python and am looking for the stereotypical "Python for C++ Developers" article, but coming up blank. I've seen these sort of things for C#, Java, etc, and they're incredibly useful for getting up to speed on language features and noteworthy differences. Anyone have any references?

As a secondary bonus question, what open source Python program would you suggest looking at for clean design, commenting, and use of the language as a point of reference for study?

Thanks in advance.

+14  A: 

I never really understood the "Language X for Language Y developers" approach. When I go looking to learn Language X I want to learn how to program in it the way that Language X programmers do, not the way Language Y programmers do. I want to learn the features, idioms, etc. that are unique to the language that I am learning. I want to be able to take advantage of the things that make the language special and use that knowledge to expand my ways of thinking and solving problems. I don't think I would get the same sort of insights from a tutorial that was framed in the context of another language. If you can learn your first language without a tutorial geared towards something you already know you should be able to pick up a second language the same way (and in my experience, the more languages you know the easier it is to learn new ones).

With that said, I would recommend The Python Tutorial as a good, quick, and easy way to get going with Python and Dive Into Python as a more complete introduction, also available for free here. I would also agree with what others have said regarding looking at the code for the standard libraries as a source of good examples and design practices, the standard python libraries are pretty clean and easy to read.

Robert Gamble
I would agree, the idioms and features are important. But I'm not new to programming, so a lot of tutorials bore me with drilling through "this is a for loop" before they reveal "oh yes, it can iterate over list structures".
Stefan Mai
At least you aren't trying to do the reverse! C++ has an issue in that its use is very inconsistent, usually based largely on the background of the coder.
coppro
Also, Diving Into Python is for experienced coders. I just may use that link myself; thanks!
coppro
I think it can be good to point out anti-pythonisms a C++ programmer is likely to commit and point them out though.
Draemon
@Stefan, that is a different issue and I completely sympathize with you there. In that case both resources I cited bring you up to speed pretty quickly.
Robert Gamble
+1 for the tutorial. Any C++ programmer will have no problem in comprehending it. DIP is good to learn more advanced stuff. Also don't forget to look at the library documentation when you work on something.
Cristian Ciupitu
A: 

For the best examples of code of a language, the language's standard library is often a good place to look. Pick a recent piece, though - old parts are probably written for older versions and also sometimes were written before the library became big enough to warrant big standards - like PHP and Erlang's libraries, which have internal inconsistency.

For Python in particular, Python 3000 is cleaning up the library a lot, and so is probably a great source of good Python code (though it is written for a future Python version).

coppro
+2  A: 

I learned a lot about Python by reading the source of the standard library that ships with Python. I seem to remember having a few "a-ha!" moments when reading urllib2.py in particular.

Matt Campbell
+1  A: 

Python is sufficiently different from C++ so that specific knowledge can't normally be transferred. There are a few language comparisons available. What you can carry over is knowledge of specific APIs, e.g. of the POSIX or socket APIs.

As an example for a typical Python (GUI) application, look at IDLE (as shipped for Python).

Martin v. Löwis
+6  A: 

Dive Into Python is a Python book for experienced programmers.

gimel
+1  A: 

C# and Java are seen as cleaner replacements for C++ in many application areas so there is often a "migration" from one to the other - which is why there are books available.

Python and C++ are very different beasts, and although they are both considered general purpose programming languages they are targetted towards different ends of the programming spectrum.

Don't try to write C++ in Python; in fact, try to forget C++ when writing Python. I found it far better to learn the common Python paradigms and techniques and apply them to my C++ programs than the other way around.

Dipstick
+1  A: 

To learn the language the free and online python tutorial is really all that you need to pick up the language and start writing apps. If you want a book, I've found Beginning Python from Apress to be an excellent reference and tutorial. Of course the best way to learn a language is to write code, thus I would recommend that you check out Boost.Python. If you have a C++ that needs to be a bit more flexible, Boost.Python can give you a good excuse to learn Python and get paid for it.

+1  A: 

Dive Into Python is great, but don't forget PJE's Python Is Not Java.

orip