DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Using Python Libraries in Java
  • Start Coding With Google Cloud Workstations
  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  • Why I Started Using Dependency Injection in Python

Trending

  • AI's Dilemma: When to Retrain and When to Unlearn?
  • Article Moderation: Your Questions, Answered
  • Secure by Design: Modernizing Authentication With Centralized Access and Adaptive Signals
  • Event-Driven Architectures: Designing Scalable and Resilient Cloud Solutions
  1. DZone
  2. Coding
  3. Languages
  4. Python vs. C/C++ in Embedded Systems

Python vs. C/C++ in Embedded Systems

Python might be at its strongest when used as a communication middleman between the user and the embedded system they're working with.

By 
Tom Radcliffe user avatar
Tom Radcliffe
·
Sep. 05, 16 · Opinion
Likes (23)
Comment
Save
Tweet
Share
23.8K Views

Join the DZone community and get the full member experience.

Join For Free

The C/C++ programming languages dominate embedded systems programming, though they have a number of disadvantages. Python, on the other hand, has many strengths that make it a great language for embedded systems. Let's look at the pros and cons of each, and why you should consider Python for embedded programming.

C/C++ are compiled languages, while Python is an interpreted language. C/C++ have been around for ages; C was first developed in 1969, and C++ came along in 1983. Python is younger as it was created in 1989 by Guido van Rossum. Since then, it's become one of the most popular open source programming languages. All Python releases are open source and freely usable and distributable, even for commercial projects. (If you're looking for commercial- grade support and indemnification, distributions like ActivePython are available.)

The Case for Python

Python is the most popular introductory programming language at the top computer science (CS) departments in the United States. According to a study by the Barr Group, eight of the top ten CS departments currently use Python to teach coding. Debate the merits of it if you want, but the simple fact is that the most widely understood language in the hiring pool of recent graduates is Python. It's dramatically more likely that a recent graduate will understand how to code in Python than in C/C++.

Hobbyist developers are likely to have some experience with Python, and it's more likely that they'll be proficient in Python than in C/C++. Since only about 40% of computer software engineers and system analysts have computer science degrees, a lot of industry hires are coming from hobbyist backgrounds. But when it comes to embedded systems, the numbers flip pretty severely. The Barr Group study shows that over 95% of the code for embedded systems is written in C/C++. This legacy on embedded systems might be hard for Python to overcome, but its attributes and the sheer number of people coding in Python might help it overtake C/C++ in the future.

Python isn't only the most-popular language for introductory CS programs, it's also the fastest-growing language for embedded computing. Maybe that sounds silly when you scan the numbers again and realize it's the fastest-growing language of the remaining 5% of embedded systems code that aren't C/C+ +, but Python will start eating into C/C++'s monopoly even more over the next few years. Hobbyists migrating into the industry with experience programming drones, robots, or other projects frequently have an Arduino or Raspberry Pi background. They'll likely have dealt with Python on some level in that time, and it's also likely that they'll have bumped up against some embedded systems programming.

While C/C++ is slow to write, error-prone, and frequently unreadable, Python is known for its writability, error reduction, and readability. The importance of readability can't be overemphasized: when you're working in a team, readability is paramount to maintaining the code. It has to be easily decipherable unless you're willing to shell out more time and money on debugging and quality assurance. The design reuse of Python far outclasses C/C++, and in today's Agile environments design reuse can be the difference between staying ahead or falling behind the competition.

Embedded algorithms are getting increasingly complex. Simple control loops are being replaced by neural networks and other heavily-involved processes that have helped Python gain its foothold. There are Python libraries like Theano that will optimize Python code for these processes. While Theano is mostly written in C/C++, Python is used to interface with high-performance libraries in a human-friendly way. Python libraries are thriving—PyPI, the Python package index, has over 80,000 modules, and these massive compendiums dramatically increase the productivity of programmers by giving them the option to skip a few steps and use already-established functions in their own code.

The Case for C/C++

The case for C/C++ is pretty obvious: it creates more compact and faster runtime code, and it's already the language of choice for 95% of embedded system code, so it has a whole legacy that Python will have to overcome. When it comes to speed, however, runtime speed isn't the only aspect of development to consider—you also have to consider development speed. While Python may be less efficient than C/C++ at runtime, during development it's much more efficient. Interpreters read each line of code, parse it, do runtime checks and call routines in order to execute the operations in the code. This is a lot more activity than what you get from running C/C++ code, where the same line of code might be compiled into just a couple of instructions. This can lead to slower runtime speeds and higher energy consumption with Python.

Improving Python's Speed

So the main case against Python versus C/C++ is its runtime speed, but there are several ways to optimize the code so it runs more efficiently. Aside from libraries like Theano, there are optimizing extensions for Python like Cython, which is essentially Python with static typing and keywords to run math more quickly. Because Cython is statically typed, you can easily compile to C/C++ and run at C/C++ speeds.

Just-In-Time (JIT) compilers are another good way to improve Python's runtime speed. These compilers work in parallel with Python's interpreter to generate compiled machine instructions for code inside loops. This allows subsequent passes by the interpreter to execute faster. The PyPy JIT compiler is able to increase Python's execution speed by nearly a factor of two. JIT compilers should only be used if there's enough space, though, and embedded systems don't usually have a lot of that to spare. The best optimization is to use better data structures and algorithms, but this is the hardest task in software design and implementation, so it might be best to utilize one of the tools above, depending on your skill level.

Using Python to Communicate With Embedded Systems

Python might be at its strongest when used as a communication middleman between the user and the embedded system they're working with. Sending messages through Python to or from an embedded system allows the user to automate testing. Python scripts can put the system into different states, set configurations, and test all sorts of real-world use cases. Python can also be used to receive embedded system data that can be stored for analysis. Programmers can then use Python to develop parameters and other methods of analyzing that data.

Currently, the main debate about the merits of Python and C/C++ comes down to what's more important to your team: development speed or runtime speed. In the future, though, it might not be up to Python programmers to make their case for its use in embedded systems, but rather for embedded systems designers to figure out how to accommodate the relentlessly increasing popularity of Python.

Python (language)

Published at DZone with permission of Tom Radcliffe, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Using Python Libraries in Java
  • Start Coding With Google Cloud Workstations
  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  • Why I Started Using Dependency Injection in Python

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!