Each Answer to this Q is separated by one/two green lines.
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.
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.
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.
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.
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).
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.
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).