In this post, we will discuss a question that I periodically search just to feel out the general opinion of the Internet. There are so many blogs that discuss the same question, which you’ve likely seen if you’re reading this one as well. I hope having another set of conflicting recommendations is more helpful than harmful to you.
I’m not going to clickbait you by making you read the whole post to see my top languages. So here they are: C++, Python, and MATLAB/Simulink.
C++ : Software Development and Embedded Systems
Technically, this title should read C and C++ because of embedded systems.
To be as brief as possible: C++ is “just” C with object-oriented programming, which has minimal negative impact on performance but also makes things so. much. more. convenient. with tools like data structures (vectors, stacks, queues, etc.), memory management (new/delete, smart pointers, etc.), and so on. I recommend this GeeksForGeeks page if you want to know more.
C++ can be challenging to learn for beginners because it is
- Object-oriented — which has its own learning curve to master.
- Strongly-typed — you have to declare the data type of every variable before using it.
- Compiled — meaning you can’t just write a script and run it, as is the case with interpreted languages like Python or MATLAB. Every time you write or modify a piece of code, you have to go through a compilation process to generate executables, libraries, etc.
I believe the effort to learn and write C++ is worth it because compared to interpreted languages, implementations in C++ are fast and efficient. As a result, you will find that most production-quality robotics software is written in C++.
Again, don’t think that I am trying to intimidate you with C++. There are several high-level libraries for robotics built on C++. Some examples include
- ROS and ROS 2 for robotics prototyping, software node management and communication
- Eigen for math and matrix operations
- OpenCV and Point Cloud Library (PCL) for computer vision
- MoveIt! and Open Motion Planning Library (OMPL) for motion planning
… and many more. I found this cool list if you want a more complete picture of the robotics software ecosystem. It’s also worth noting that other languages provide APIs that are glorified wrappers of said C++ implementation. Python and MATLAB are very much guilty of this, and for good reason!
C and C++ are also popular languages for programming embedded systems. C still dominates this space, but many modern boards today will accept C++ as well, or variations such as the Arduino programming language. If you’re all the way down at the bare-metal firmware or operating system levels, you will likely still be writing plain C, though.
Python : High-Level Programming and Machine Learning
Python is a good interpreted programming language that extends far beyond robotics and you will likely find some use for it regardless of where you end up … as long as it’s a technical field.
Python is the top programming language worldwide. It is so widely used that you will find code and answers for virtually anything you want. This YouTube video shows the meteoric rise of Python way better than I could.
Specifically for robotics, Python has a few main reasons for being popular:
- On average, it’s faster to develop and test a piece of software in interpreted languages like Python vs. compiled languages like C++. So if you’re doing research, a class project, or something high-level enough that is not performance-critical, then Python is more than enough.
- Python is the standard language for several machine learning libraries, most notably TensorFlow, PyTorch, and scikit-learn (remember, folks, not everything needs deep learning!).
- As I said in the previous section, many of the robotics packages available in C++ also have equivalent Python APIs. The Python APIs for ROS/ROS 2 and OpenCV are quite ubiquitous.
If you’re getting into production-level software development, or have code that just isn’t running as fast as you need, the “jack of all trades, master of none” nature of Python comes out. At this point, you may want to consider moving at least your critical components to C++.
MATLAB and Simulink : Engineering and Controls
In many posts like this one, people will often get into the good old “MATLAB vs. Python” debate.
First off, let’s discard what I consider silly non-issues like ArRaYs StArT aT ZeR0 and get to the bottom line: If you’re talking about purely scripting and data analysis, I agree with most of the community in that MATLAB and Python are almost indistinguishable in their capabilities, both having their own quirks, except Python is free and open-source — so why ever choose MATLAB? You’re not wrong if you’re asking yourself this question.
This is why I specifically point out MATLAB and Simulink. Getting outside the “core” MATLAB, there is a whole host of toolboxes where the MathWorks software ecosystem brings something unique. The two main areas in my opinion are control systems and physical simulation. While Simulink is not a language but a graphical programming tool, MathWorks’ philosophy for engineering design is heavily skewed toward Simulink, so I believe you’ll need to learn this to get the most out of the software unless you’re dealing with simple linear systems for your introduction to engineering courses.
For control systems, MATLAB and Simulink are undisputed winners. If you’re doing control design, you should 100% learn MATLAB and Simulink along with all the controls add-ons. If you didn’t know about the MATLAB Tech Talks on controls, now you do.
For physical simulation, there is the Simscape product family which lets you do handy things for robotics like importing CAD and URDF models, linking them to multiphysics components such as mechatronic and fluid power systems, and — the key — working these simulations in with the controls tools in Simulink.
… you just have to hope that your school / lab / company is willing to pay for your license 🙂
NOTE: The simulation tools I discuss in this section are strictly useful for engineering and control design, but if you need more of a “physics engine” environment that handles collisions and perception sensors (camera/lidar/etc.), then you are better off with other tools like Gazebo, Unity, and so on… for which I recommend you head back to C++/Python land since that’s where the APIs for these tools reside.
Summary
If you’re interested in dipping your toes in all the activities above, not all hope is lost! Several communication frameworks such as ROS allow you to build hybrid systems that take advantage of all the above languages for the things they are respectively good at. I mentioned the C++ and Python ROS APIs, but I’d be remiss not to bring up that MATLAB/Simulink also has a ROS Toolbox (full disclosure: I say this because I worked on supporting its release).
Needless to say, the set of programming languages useful for robotics does not stop with this list. There are fairly popular languages that sit somewhere between C++ and Python, such as Java and C#. Also, let’s not downplay the importance of Web programming to make user interfaces, visualization tools, and so on.
So which language should you learn first?
- Learn C++ if you want to be a robotics software developer and/or you want a strong programming foundation that will enable you to pick up other languages relatively easily.
- Learn Python if you are pursuing a future in machine learning, or you’re generally interested in programming and want a solid general-purpose language for whatever you choose to do later in life.
- Learn MATLAB and Simulink if you are not so much into programming, but you want to use modeling and simulation to design robots and their controllers. Although to implement these control algorithms on a real robot, you may at least want to know a bit of C as well.
My personal recommendation is C++. Once you’ve learned this well, then picking up other languages is much easier than going the opposite way. For example, MATLAB and Python are object-oriented, but depending on what you’re doing you may never even be exposed to classes and objects (granted, this is not true for robotics). However, if you know how to handle object-oriented programming well it can make you much more effective in any of the languages in this list.
I know people that spent most their time using MATLAB or Python in college or their early professional career, and are now too afraid to jump into C++. I’m a bit like that too, so I’ve taken a bunch of online classes during my time as a professional to try catch back up. Learn from my experiences and consider picking up C++ early if you seriously want to be a robotics software developer.
If this was useful to you, or you have different opinions, it would be great to see your comments. Until next time!
been reading your blogposts for a while and just wanted to drop by to thank you for sharing your past experiences and research! I especially love your yearly reviews, your background is fascinating – keep up the amazing work in helping others (like myself!) figure out how to navigate through the world of robotics (: