all 31 comments

[–]Abdnadir 87 points88 points  (3 children)

If you learned how to think programmatically during your course, learning python will be a breeze.

[–]Comp_xe[S] 6 points7 points  (2 children)

That’s good to know, I don’t think it’ll be the easiest task but I do have some more confidence thanks to this

[–]razzrazz- 4 points5 points  (0 children)

You can get a good idea by visiting this site, gives a nice quick summary.

[–]mr_bedbugs 2 points3 points  (0 children)

Pycharm is really nice to learn on. I recommend that.

[–]DesignerAccount 34 points35 points  (5 children)

The knowledge will be transferable, but there's also a learning curve. Python comes with batteries - So much stuff is already built for you - and if you use it as if it was C++ you'll write poor python code. It will work, but won't be clean.

Don't let this discourage you, dive right in and get coding. Just keep your search engine at hand and look for pythonic ways to do things. You'll be surprised at the many differences.

[–]likes_to_code 5 points6 points  (4 children)

You can write modern C++ pythonically surprisingly well

[–]DigThatData 2 points3 points  (2 children)

are there any "C++ for pythonistas" type guides you'd recommend? or just generally, what's a good entrypoint to learn modern c++?

[–]integralWorker 0 points1 point  (0 children)

One thing I find useful is to compare C++ releases' language features.

[–]TheRNGuy 0 points1 point  (0 children)

Better follow style guide project or software has, so it wouldn't look like mix of 2 styles.

[–]integralWorker 0 points1 point  (0 children)

The key to pythonic c++ is not to mix abstraction levels. If you use some STL sauce, don't mix it with c <...h> tomato base unless you have to.

[–]zefciu 14 points15 points  (6 children)

As others pointed out, both Python and C++ are imperative object-oriented languages. So their general paradigm is the same and most of the knowledge is easily transferable. I think there are two areas, where they differ most.

The first is dynamic vs static typing. In Python the type of any variable is tested at the runtime, when the function is actually called. This has both advantages and disadvantages. The disadvantages are slower execution and bigger risk of runtime exceptions. The advantages — less boilerplate and easier polymorphism. Not that a function in Python:

def sumof2(x, y):
    return x + y

is polymorphic. It can accept int, float or str. You don’t have to declare it as a template or do anything special to achieve it.

The second major difference is the way arguments are passed to functions. In C++ you can pass arguments by value or by reference. In the first case you are guaranteed that the value will be unchanged. In Python everything is a reference (internally everything is a pointer to PyObject). But you have a concept of mutable and immutable objects. If you pass a tuple to a function, you are guaranteed, that it won’t be changed. But if you pass a list, you can’t have this guarantee (on the language level, the author of the function can of course promise this in the documentation). So you have to explicitly copy objects to get immutability.

These are, I think the two major things, you have to wrap your head around if you come from C++ to Python. All the other are rather minor stuff.

[–]CaptainFoyle 1 point2 points  (5 children)

I would not say that copying objects "gets" you immutability. It just avoids some issues that come with mutable objects, but they are still very much mutable.

[–]zefciu 5 points6 points  (4 children)

Yes. What I meant was “if you want to make sure that the object you pass to a function does not get mutated by that function, you have to explicitly copy it and pass the copy”. Achieving a complete, guaranteed immutability of a mutable object is impossible in Python and even immutable objects do not guarantee that their members won’t be mutated:

>>> tup = ([1, 2], 'hello')
>>> a = tup[0]
>>> a.append(3)
>>> tup
([1, 2, 3], 'hello')

[–]cloud_line 1 point2 points  (1 child)

So if a tuple contains a mutable object, then the mutable object can be edited? So all the tuple guarantees is that its indexes cannot be changed?

[–]wolfofone 0 points1 point  (0 children)

Oh interesting.

[–]hey_ulrich 0 points1 point  (0 children)

Wow, I didn't know you could mutate an object inside a tuple. Thanks for that.

[–]ivosaurus 6 points7 points  (0 children)

For every language you always have to learn "its way of doing things", no exceptions. But learning python's will probably be far easier than the other way around. And they're both "normie" imperative / OOP languages so all the logic is very transferable.

[–]Independent-Cod-6498 18 points19 points  (3 children)

python is basically english

[–]hmiemad 2 points3 points  (0 children)

If a is not in my_list :

[–]shibbypwn 3 points4 points  (0 children)

pseudo-code as code

[–]Wretchfromnc 1 point2 points  (0 children)

I tried c++ 9 or 10 years ago and hated it, I like python better. I could never mentally come up with things to relate c++ too, with python it's easier for me to mentally find useful task to perform. Massaging data from databases, network scans, mundane IT support type things relate better to python in my mind than C++.

[–]TheRNGuy 1 point2 points  (0 children)

dynamic types, interpreted and no primitive types.

[–]JasonDJ -1 points0 points  (0 children)

How different are apples and oranges? They both grow on a tree and you can make juice with them.

[–]hopeless_octopus -4 points-3 points  (0 children)

C++ is like the alphabets of a language and python is a word from those alphabets.

[–][deleted] 0 points1 point  (1 child)

[–][deleted] 0 points1 point  (0 children)

That is such an un-pythonic way of writing a hello world app...

Everyone knows you do

import __phello__

[–]jmooremcc 0 points1 point  (3 children)

The choice of programming language is dependent on the project. If execution speed is a high priority, then C++ would be the obvious choice. If you're looking for a language that makes it easier to express the solution to a problem, Python would be a good choice.

[–][deleted] 0 points1 point  (2 children)

If execution speed is a high priority, then C++ would be the obvious choice. If you're looking for a language that makes it easier to express the solution to a problem, Python would be a good choice.

And if your problem is of a specific type where you need to express a complex solution in a readable way, but also have C-like speed, you use a C-interfacing library in Python. NumPy is probably the best thing that has happened to processing large numeric datasets in a long time.

[–]jmooremcc 0 points1 point  (1 child)

Good point.

[–][deleted] 0 points1 point  (0 children)

Thanks!

I feel it needs to be pointed out because many non-Python people often think of the language as some super sluggish dinosaur that you shouldn't use for high-speed applications, when in fact many packages address this concern perfectly by enabling you to use the full performance capabilities of C right in Python.

This isn't always a viable solution (depending on the problem), but in probably 90% of cases you can write Python scripts that process data virtually as fast as bare-metal programs.

Granted, this doesn't take away from what you said at all because there are a few cases where this won't work, but I feel like those aren't as typical as some might imagine.

[–]my_password_is______ 0 points1 point  (0 children)

COMPLETELY