What You Need to Know about Carbon, Python and Hylo
There are hundreds of programming languages out there today spanning all sorts of categories — frontend and backend, high level and low level, interpreted and compiled. For developers, it can be easy to fixate only on the handful of languages that you use on a day-to-day basis. However, it’s important to consider how other languages, both emerging and old, can provide value in new ways.
Here are some things you should know about three important programming languages: One is a new language, one is still under active development, and one is a longtime mainstay.
Carbon Is a Successor, Not a Replacement for C++
Last year, Google introduced the new Carbon programming language. Despite popular belief, Carbon is not a strict replacement for C++. Instead, it is designed as a successor. While that may sound like the same thing, the important distinction is that it is intended to be used alongside C++. The interop story is the most important part. You can mix C++ and Carbon in the same project — calling between each other seamlessly.
Carbon does address several significant issues in C++. These problems in C++ are the result of decades of technical debt in the language that, because of the priorities of C++ evolution, cannot be addressed within C++ itself.
One issue is that C++ is notoriously hard to parse — even for tools — and often requires many extra keywords to get the behavior you would like by default. Its original take on generics evolved into a fully-fledged meta-programming language, yet it had been unable to fulfill some of its early goals.
Carbon also aims to address C++’s governance model. It favors benevolent dictators (emphasis on the plural) model with an open evolution process on modern tools, rather than an international standard (ISO) that is optimized for representation by nations and corporations.
Ultimately, the Carbon project is absolutely necessary as C++ has hit a brick wall in several important areas of evolution that it cannot address without changing its priorities in a way that cuts off many (perhaps the majority) of its users. Attempts have been made to introduce versioning systems into the language to work around this, but they have failed, defeated by the very complexities of the language that they have aimed to address. C++ will continue to live and evolve for a long time and remain an important language, but its limitations are real and inescapable.
For C++ to succeed, it needs to be succeeded. Carbon was designed to do just that.
Hylo Shows Power of Mutable Value Semantics
Hylo, previously know as Val, is an experimental language designed for high-level systems programming that is centered around a concept called mutable value semantics. It prioritizes simplicity and ease of use without sacrificing performance. Hylo hasn’t gotten much attention yet as it is still under development, but once version 1.0 is released, there could be good adoption. However, the first version will likely not be ready for a while, maybe years.
Value semantics is a model of objects where data is represented as distinct and independent values — as opposed to reference semantics, where the memory location of the underlying object is exposed and may be shared. When data with value semantics is assigned to another variable or passed to a function, the original and new values are isolated from each other. Modifications to one won’t affect the other, making the code easier to reason about. This is often achieved by copying the objects that represent the values. Where values are immutable, it is often possible to share the actual objects behind the scenes to minimize the overhead of copying.
With mutable value semantics, such sharing is typically banned, but with sufficient cues from the language, which Hylo provides, the compiler can employ techniques such as reference borrowing (à la Rust) or copy-on-write to still avoid or minimize these copies. As a result, you get the programming simplicity of pure values, with mutability and sharing safely managed for you by the compiler.
Python and C++ — a Match Made for Coding
Python has demonstrated its value with tons of applications over the decades. It’s probably the most straightforward language to learn, being simple to use. A very versatile language, Python can cover many use cases from small tasks such as quickly analyzing some data in a spreadsheet, to automatically scraping the web for today’s news headlines, to bigger things like building web applications or doing some serious data science work.
While it’s a popular language for being easy to call on and for its readability, Python is not highly performant on its own. That’s why Python and C++ together make such a good pair — you get the ease of Python with the high performance of C++.
The benefit of leveraging these two languages together is not uncommon knowledge, but using the two together is still not largely done outside of data science, numerics and machine learning. By using both Python and C++, developers can get the simplicity that Python provides without having to give up on the power that C++ offers. This is especially beneficial with the rise of machine learning and AI in the past few years, as the strengths of both languages can be well executed in numerical computing and machine learning cases where high performance is needed.
Python has some excellent wrappers around C++ libraries, and it’s very easy to call on C++ from Python or to use several widely used interoperability libraries like NumPy, Boost Python and PyBind11. In that way, all the heavy lifting is done in C++, and you can just import your Python project.
Both Carbon and Hylo show a lot of promise, but they’re probably a few years out before they can truly be used. However, you can use Python with C++ right now and get many of the benefits that the two together provide.
Keep Learning about Languages
For software developers to keep growing, they have to keep learning. That means not only getting to know new programming languages, but also thinking about new applications for familiar languages. It’s easy to stay up to speed: There are lots of great software engineering blogs, developer publications and coding events to look out for. And of course, be sure to check out Sonar’s blog and follow our posts here on The New Stack.