A Streamlined Introduction to C
2019-01-28 | By Maker.io Staff
Python has been the main language of focus for its simplicity and ease-of-use with the Raspberry Pi. In this blog, we will be introduced to C++ and discuss its benefits and disadvantages.
C++
C++ is an object-oriented programming language that was first developed in the late 1980’s intended to bring objects to the C programming language. It is one of the world’s more popular computer languages and is responsible for most operating systems, games, and applications. The coding style of C++ is near identical to C, which makes moving between C and C++ easier than transitioning between other languages like Python and Java. So, what are the advantages and disadvantages of C++? And should you use it for your next project?
C++ Advantages
C++, unlike Python, is a compiled language, meaning that a C++ program needs to go through a compilation process before it can be executed. During this process, every single line of code is turned into machine language that the CPU understands. It is this conversion of code lines to machine instructions that make C++ programs considerably faster than Python programs. Python programs get parsed line-by-line and then interpreted by a Python interpreter, which next performs the desired action and makes them slower.
C++ is an object-oriented language allowing the use of objects and classes. While this is an advantage, it is not an entirely relevant advantage, as most languages have been modernized and often include object orientation. Other languages that include object orientation include Java, Python, Visual Basic, and C#. C++ is also a “middle language,” meaning it sits between low-level (close to hardware) and high-level (pure abstraction). This is very convenient because it allows the user access to the hardware, while also providing many useful functions and classes to help make programming easier and more accessible.
C++ Disadvantages
While the C++ language itself is cross-platform to a degree, the compiled program is not. This is because the compiled program is entirely made up of CPU instructions, which can only be understood by a specific processor.
For example, Windows machines run CPUs that understand the x86/x64 architecture. Programs compiled for the Windows OS use the Window API calls. This is why a Windows program cannot run on a Mac OS or Linux without the use of a virtual machine.
C++ can also consume more “code-per-mile,” meaning it takes more code to get the same task done when compared to other languages. This means that following a C++ code can be harder to follow or understand if clear comments aren’t made, and more code is required to do even the simplest of tasks. C++ is more complex than Python when creating applications that involve networking, graphics, GUI, and hardware. This is why it should only be used if speed is absolutely necessary.
Conclusion
Choosing to write a program in C++ should not be taken lightly, and other languages should be considered first. For example, if you want to get a program made quickly with little effort, a language like Python might be the better choice. If, however, you require fast access to IO, want the most out of your machine, or building a large program, then C++ is definitely the way to go!
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum