TNS
VOXPOP
What news from AWS re:Invent last week will have the most impact on you?
Amazon Q, an AI chatbot for explaining how AWS works.
0%
Super-fast S3 Express storage.
0%
New Graviton 4 processor instances.
0%
Emily Freeman leaving AWS.
0%
I don't use AWS, so none of this will affect me.
0%
Frontend Development / Python / Software Development

Veteran C++ Developer Says Python Is Best Starter Language

C++ developer Phil Nash contends Python is the best starter language, or a great second language for frontend and web developers.
Mar 13th, 2023 10:58am by
Featued image for: 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 or JavaScript for a First Language?

But what’s wrong with JavaScript as a first language? Well, JavaScript is a good choice, but it was never really designed as a beginner-friendly language, Nash said. This led to a little morality tale about BASIC, a popular 80s programming language that stood for Beginners All-purpose Symbolic Instruction Code. It was pretty, in that it was simple. The problem was, it wasn’t a very good language — so people didn’t use it for serious applications, until Microsoft rolled out Visual Basic in the 1990s, he said.

The popular Python is different because it’s simple to use, but as developers become more experienced, they can delve into more sophisticated uses and eventually write real-world applications, he said. JavaScript is also fairly simple, but more by accident than design, Nash contended.

“[JavaScript] got designed as part of something else and accidentally became the most popular language in the world, just because it came bundled with the web basically,” he said. “So it’s a great language to learn for that reason. It’s just not as beginner friendly.”

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.”

He moves between Python and JavaScript a lot; and the biggest point of confusion that creates is knowing whether to put a semicolon at the end of lines or not.

“That’s one of the problems with JavaScript, a lot of things are optional. So semicolons are actually optional, except in some cases where they’re not,” he said. “Python has as part of its mantra that there should be one proper way to do things. It’s not always true, but by and large, they try to design things so there’s an obvious way, the Pythonic way, to do things. Everything looks fairly uniform. JavaScript is almost the opposite of that.”

Python as Second Language: Should You Bother?

“But it’s irrelevant,” you may say. JavaScript is the king when it comes to the web and you’re a frontend/web developer.

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.”

But let’s say it’s too late for you — you’ve already learned JavaScript or some other language. Python is also an ideal supplementary language, Nash contended.

“Python is great as a scripting language,” he said. “It’s full feature for that as well, because it scales to the problem.”

Another differentiator for Python is that it’s known as a dynamic language; so, for example, when you declare a variable you don’t have to say what type of variable it is (number, string, boolean). The language infers it from how you use it — much as JavaScript does. That’s not true for Java or C++, which are statically typed languages. Dynamic languages are generally easier for beginners, he added.

“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

On the backend for web development, there are two primary Python frameworks: Django and Flask. Nash uses Flask for his web development.

“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.”

Group Created with Sketch.
TNS owner Insight Partners is an investor in: The New Stack, SonarSource.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.