Python vs. C++11

S

sturlamolden

There are bigsimilarities between Python and the new C++ standard. Now
we can actually use our experience as Python programmers to write
fantastic C++ :)

Here is a small list of similarities to consider:


Iterate over any container, like Python's for loop:

for (type& item: container)


Pointer type with reference counting:
std::shared_ptr


Python-like datatypes:

tuple std::tuple

list std::vector
std::list
std::stack

dict std::unordered_map
set std::unordered_set

complex std::complex

deque std::deque

lambda [name](params){body}

heapq std::heap

weakref weak_ptr

str std::string -- unicode, raw strings, etc work as Python


Other things of interest:

std::regex, std::cmatch
std::thread thread api versy similar to Python's
std::atomic datatype for atomic operations
std::mt19937 same prng as Python
 
S

sturlamolden

There are bigsimilarities between Python and the new C++ standard. Now
we can actually use our experience as Python programmers to write
fantastic C++ :)

And of course the keyword 'auto', which means automatic type
interence.
 
H

Henrik Faber

This is more true than you might think. For quite a few years now, I've
been able to do an almost line-for-line translation of my Python programs
to C++ programs. (Microsoft has had a "for each" extension for a while
that made this easier.)

I disagree. Unicode support comes for free with Python3+ while C++ it
still is a piece of crap (or something that you'll have to pass to
external libraries). The C++ standard library is nowhere nearly as
densely packed with features than Python's. For every little thing you
need some external dependencies. Language semantics aren't enough to
translate one language into another.

Best regards,
Henrik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top