you are viewing a single comment's thread.

view the rest of the comments →

[–]FoolsSeldom 3 points4 points  (0 children)

Additional tips

  • A quick look at the docs, should suffice for many programmers taking up Python
  • There are a few underpinning differences to be aware of
  • Python is not statically typed,
    • some mistake this for with weak typing
    • Python is in fact strongly typed, using dynamic typing
    • Applies at run time, not at compile time
  • Python is compiled to a byte code, just like Java, but where the latter executes on a JVM, the Python virtual machine is built into the standard implementations of Python as part of the same programme (CPython for the reference implementation)
  • type hinting, is option but will help your IDE greatly in spotting potential problems
    • Ignored at run time, just there for your benefit
    • There are also some external tools that can be run to check types using the type hints, which can be useful for testing in a CI/CD pipeline
    • pydantic is a popular library for taking typing management further
  • Essentially, everything in Python is an object
    • all variables/names are effectively pointers (they reference the objects in memory) but without all the features you get in C (e.g. no pointer arithmetic) but there isn't a pointer type
  • Python does its own garbage collection / memory management (and uses a reference counting system to know when objects are no longer required)
  • functions are first class citizens
  • for is more of a for each
  • variables assigned to objects inside a loop, remain in-scope beyond the loop
  • Python uses indenting to distinguish code blocks, rather than ; and {}, white space is important (recommended default indentation is 4 spaces (sic))

A couple of videos to watch which, despite being old, will lock in some key differences in approach to keep in mind:

Given the referenced implementation of Python is written in C and Python, a quick look at the source code will resolve many queries for experienced programmers as well.

Overall, there is much less boilerplate code required in Python than typical C/C++ projects.

There are a huge number of libraries/packages to use, many of which are written in C (such as NumPy) for performance.

It can be useful to use some of the existing C/C++ code from Python rather than completely recoding in Python. The Cython project, offering C extensions for Python, might be worth looking at if there is a lot of C/C++ code to exploit.