Veteran C++ Developer Says Python Is Best Starter Language
New programmers who are looking for a first language and anyone wanting to add another language to their toolkit should start with Python. So says Phil Nash, one of the original authors of the C++ test framework, Catch2, and a developer advocate for SonarSource.
“It’s a boring choice, but for exciting reasons,” Nash told The New Stack. “It’s very simple to start with, but it scales with you right up to being a really industrial-strength, very popular language. I don’t think there’s any other language that comes close to covering all of those bases.”
Python, on the other hand, covers both bases — it is beginner friendly and useful, said Nash.
“It really reads more like pseudocode that you might just write on paper, when you’re sketching out an ideal, that translates into real working code in a production code base,” he said. “You can’t really get more beginner friendly than that, and it’s also widely used in industry.”
Python as Second Language: Should You Bother?
Consider this: With the release of Anaconda’s open source PyScript last year, Python is now making its way to the frontend.
“You can also use it as a great web technology on the backend, which I do a lot,” he said. “And it’s starting to show some promise of being a frontend language as well, although it’s very early days. It’s too early to really tell if that’s going to take off, but the fact that it exists, if you already have Python skills, you can now call yourself (or consider yourself) a frontend developer, at least if you dabbled with it. So it is possible, at least, which you can’t say for various other languages.”
“Python is great as a scripting language,” he said. “It’s full feature for that as well, because it scales to the problem.”
“Python is a dynamic language, which means you can make mistakes in the code that only get picked up at runtime, whereas a statically typed language will pick it up at compile time,” he said. “Many people, myself included, generally prefer statically typed languages, particularly for larger more complex code bases. Python does now have optional type annotations, which gives you a lot of the benefits of it, but only if you use an additional static analysis tool.”
Sonar offers a static analysis tool that will pick up mismatches in types of use, even in Python, he added.
Python can be used as a friendly frontend to more complex code bases, such as C++.
“You can wrap it in a Python interface, and then it’s very easy to write Python code against that. So that’s what most ML libraries do, for example, they’re actually written mostly in C++, the underlying heavy lifting, and then the nice, relatively easy Python frontend,” he said. “It’s really great as a second language. Most developers, if they’re going to learn another language, they should have Python in their toolkit.”
Python is best known for its use in machine learning, but it’s also a popular language in finance, in part because of NumPy and quant computing, which applies mathematical and statistical methods to financial and risk management problems.
“Quant developers, traditionally have worked pretty much exclusively in C++, and maybe with MATLAB for sketching things out, and then they’ll convert their code into C++ for performance,” he said. “But with Python and NumPy, they find they actually get everything in one package. Their code looks like what they would have written it in MATLAB, but it performs like C ++ under the hood.”
What Developers Need to Know about Python
“Django is more of a traditional web framework, where you had to do everything the Django way. And it’s all in, you’re basically a Django developer now,” he said. “Flask takes a lot of cues from Django but is much less opinionated. And you can actually just drop in exactly the level you want, bring in other dependencies, do things the way you want to do, which is my preference when I’m coding.”
There are also millions of tutorials and resources online for learning these frameworks or anything with Python, he said. Python is also already bundled on machines with a Unix-based OS, such as MacOS or Linux. Windows machines can add it with a simple install. From there, it can be accessed on the command line by typing Python. It then goes into an interactive shell, where developers can start typing code immediately. It can also be accessed through IDEs such as PyCharm, which is an IDE for Python, or through a plugin with VS Code. It’s not, for instance, a high-performance language, like C++ or Java — although Python can play a role in those coding projects as well.
”Where performance doesn’t matter, it’s usually an ideal choice,” he said. “Or you can use it in conjunction with a high-performance language; you can interface into C++ very easily and get the best of both worlds.”