logoalt Hacker News

hasley • today at 7:09 AM • 1 reply • view on HN

"I mean, which pointer should I use? How should I iterate? I'm sure there's an answer to this, but I just found it easier to go back to python and hit up rust when I needed it."

You can of course use Python. But we are talking about languages with different applications. You want fast development hand have no expectations on speed? Use Python! You want to control your computer to get maximum performance with a safe type system? Use C++!

Since you are already talking about pointers: In Python you are not even given the chance to do all the stuff you can do in C++. You have to rely on garbage collection (and "del"). That is an entirely different thing than C++ where you exactly control how long your objects should live.

For the pointers (order I would suggest): 1) No pointers, use references whenever possible 2) Use std::unique_ptr 3) Use std::shared_ptr

You can also try to use shared_ptr all the time if it makes your transition from Python more easy. It is not optimal, but it may get you started.

And do not start wrapping your head around rvalue references right from the beginning. This is a very special topic, which you can ignore as a beginner.


Replies

pjmlp • today at 7:20 AM

> You can of course use Python.

Which also has plenty of way to do the same thing.

People often mistake the easiness to write Hello World, with the real expressiveness that is available in any given language.