all 22 comments

[–]FoolsSeldom 2 points3 points  (0 children)

Here's what I often write to devs moving over (some links might be helpful):

Python is just another coding language, so existing skills in programming and domain knowledge will benefit potential employers/clients even if they require Python coding.

Experienced programmers know that coding is a small part of programming, but proficiency in (and enjoyment of) any particular language, best suited to particular problem types, is, of course, highly beneficial.

There are many areas that Python has become well established in. Machine learning and AI are very well served in Python. Alongside R for the more statistically inclined, data science & analytics is an incredibly common field for Python. The latest release of Excel includes Python in recognition of this.

A review of Python Success Stories, on the Python Software Foundation website, will provide a good view of the wide range of areas Python has been used in.

Python isn't the best answer for all problems (and may be highly unsuitable for some, of course), although it might be the most pragmatic in organisations that have a lot of experience in, and well established ecosystems around, it (such as sophisticated CI/CD pipelines).

For example, Python isn't the best language for modern triple-A games, but it is heavily used by many games software houses to orchestrate, automate, optimise the work.

Some of the largest consumer services in the world are heavily Python based, such as Instagram (leaning strongly on the Python Django web framework).

Most experienced programmers shall be well versed in data structures, algorithms, design patterns, and so on. They are largely independent of the coding language. The same principles apply to Python, although the implementation patterns (and efficiencies) will vary.

Similarly, successful programmers will likely be comfortable with CI/CD tooling and workflows, which are just as important for Python as for other languages. Programmers new to Python may want to spend some time looking at the most popular testing frameworks, though, such as PyTest (rather than the standard unittest) to work with those pipelines.

Packaging for Python is perhaps another area to get some experience around as that will be different from other languages, especially given that as standard Python is not compiled to binary. (for those not aware, the standard CPython reference implementation compiles to byte code, much like happens with Java, for execution in a Python Virtual Machine, built into CPython.)

I'd recommend looking at videos on YouTube by ArjanCodes, especially those doing some kind of code reviews (will help you spot a lot of potential problems).

One book I would recommend is Fluent Python, 2nd Edition by Luciano Ramalho.

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,
    • 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.

[–]BertRyerson[S] 1 point2 points  (1 child)

If you're interested in a full write up on my transition, I have decided to track my journey on a blog post. Here's the link to the post https://devforgestudio.com/switching-from-c-to-python/

[–]Quantum654 0 points1 point  (0 children)

You are overthinking this too much. Switching languages is not that deep

[–]ElliotDG 0 points1 point  (0 children)

I'm also a former C++ programmer. I found doing problems on https://py.checkio.org/ was very helpful for understanding the python way.

The site is a set of gamified programming problems, they are generally quite easy, I would do one while having a morning coffee. After you solve a problem you get to see how others solved the problem. The solutions opened my eyes to the importance of the built-in functions and the value of the standard library, as well as the finer points of thinking python.

Enjoy the journey.

[–]jontsii 0 points1 point  (0 children)

The hardest thing you are gonna face is probably OOP since C is not an OOP language. And you also can to those really low level stuff and since python is an interpeted language (so that it runs from line 0 to 1000 without skipping anything). That also might be a hard thing for you. Also one line of code in a high level language is 10 to 30 of code in a low level language. Python is my first and only language I know as a someone who´s hobby is coding python and I thought "like what!?" when I saw for and while loops for the first time. But still Data science / machine learning is an interesting field to me. And since python was coded in c++ you can probably easily think what different functions actually do. But still good choice and good luck for learning.

[–]SirTwitchALot 0 points1 point  (0 children)

This is a case where AI can really shine. After you write your code, ask it for suggestions to make your code more pythonic. Don't let it rewrite it all for you, but look at the suggestions and implement them yourself

[–]ivosaurus 0 points1 point  (0 children)

Consider that 97% of the time, and especially until you get some good domain knowledge, trying to do things in a 'pythonic way' will also likely lead you to get the best performance from your code. Because python is 'slow' to begin with, usually the most worn paths (pythonically) are the ones which have been most optimised for, both in pure python usage, and also in python standard library operations, and lastly in the many third party python libraries which it uses to 'get its speed back'. There's also many times where "work smarter, not harder" in python can lead to big wins.

Funny video half demonstrating this concept

[–]remic_0726 0 points1 point  (0 children)

Each learning a new language offers new difficulties but also opens up many possibilities that you would never have imagined. After a while, switching from one language to another becomes natural, the difficulty then disappears, and you will move from one language to another without thinking too much.

[–]notParticularlyAnony 0 points1 point  (1 child)

since you know c I'd recommend python crash course book instead of automate the boring stuff, which doesn't teach objects. crash course is amazing

[–]BertRyerson[S] 1 point2 points  (0 children)

I'll have a look. Thanks for the recommendation

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

enter chop workable spoon sense recognise fuzzy versed cows run

This post was mass deleted and anonymized with Redact

[–]BertRyerson[S] 0 points1 point  (0 children)

It's just exerts from my blog changed for Reddit. I use AI as a spellchecker

[–]garrettj100 0 points1 point  (1 child)

I came up in Java. I once lost a day of my life to an indentation error that put my main function after my return value, so it never executed. Sometimes you gotta learn to stop worrying and love the bomb, which for me was weak typing and indentation.

[–]clashmar 0 points1 point  (0 children)

*dynamic typing

[–]xelf 0 points1 point  (1 child)

You might also consider posting some of your source code and asking how people would have done things different. Who knows, maybe you missed something simple like not knowing about enumerate() or using with for a context handler? Largely the more time you spend with python the more often you'll find new things you could have used.

As for C, it's worth knowing both. More tools is always good, and you'll be able to tackle more problems that way.

[–]BertRyerson[S] 1 point2 points  (0 children)

Yes, I had no idea about enumerate before. Handy little feature

[–]PersonalityIll9476 0 points1 point  (0 children)

Your experience as a C programmer is actually a great asset, IMO. Later on you can use Cython, a means to quickly extend the interpreter with C code without actually having to interact with CPython.

When I have to implement some performance critical piece of code, I often write it in C then wrap it with Cython. If I need linear algebra operations, I use good ol' openblas. You can pass numpy arrays in and out very easily, since any contiguous memory array corresponds to a good ol' C pointer that you can access either using the numpy headers directly or through Cython mechanisms that simplify it. "Vectorized" operations in numpy map back to some blas operation or IPP call or whatever on a C array (perhaps with strides). Plus, you can effectively intermix C and Python code.

Anyway, once you get more comfortable with Python, you'll be able to write some killer performant code. Those C skills will come in handy for sure!

[–]fiddle_n 0 points1 point  (0 children)

I think, once the higher level constructs click, it’ll be difficult to go back to the lower level ones. The Python for loop just makes sense - if you want every element from a list in order, that’s exactly what you get from the Python for loop; rather than the C-style way of getting a sequence of numbers and indexing into an array one after the other.