XOD 0.35.0: C++ Optimizations, API Improvements, Wider Compatibility

Victor Nakoryakov
Sep 8 · 3 min read

Hello, folks! Today I announce 0.35.0 release of the XOD visual programming language. This time XOD devs focused on improving quality rather than introducing sugar features.

C++ syntax simplification

Those who tried to make own C++ node know that the code looks weird a bit at the first look. Yes, it’s C++ but with some foreign quirks like {{ GENERATED_CODE }}, strange rules to #include other libraries, etc.

We wanted to remove all that non-standard stuff completely with this update. But the reality of many-many-many edge cases did not allow to do so. We have to keep a few deviations. Nevertheless, we are sure that the new API/syntax is much more intuitive, welcoming, and simple to start with.

You can find the complete list of differences in the new guide article Migrating C++ nodes to v0.35. And just to get an idea how it affects the code, here’s an example.

Before:

{{#global}}
#include <LiquidCrystal_I2C.h>
{{/global}}
struct State {
uint8_t mem[sizeof(LCD)];
LCD* lcd;
};
{{ GENERATED_CODE }}void evaluate(Context ctx) {
State* state = getState(ctx);
if (isSettingUp()) {
state->lcd =
new (state->mem) LCD(getValue<input_ADDR>(ctx));
}
state->lcd->printLine("Hello");
state->lcd->printLine("World");
}

After:

#include <LiquidCrystal_I2C.h>node {
LCD lcd = LCD(const_input_ADDR);
void evaluate(Context ctx) {
lcd.printLine("Hello");
lcd.printLine("World");
}
};

Don’t worry if you rely on some C++ code in the previous API. It still works as is.

Port type is read-only now

Oh, this was a hard part. A massive rework of the program transpiler allowed XOD to have constant types. The value of a constant is set once during the program creation and can never change then. For now, the only constant type is Port, the one used to define pins through which a module is connected to the board. “And what’s the point?” — you might ask — “How this is better than a regular type?”

First, the value of such type is known at compile time. That means that XOD can fail the compilation with a clear error message if you set an incorrect port for a module instead of failing to do anything at runtime.

Second, it opens the doors for program optimization because many upstream nodes no longer raise runtime errors (no need to consume memory for error management). There’s no need to keep duplicate port values across an external library and the program storage. Dead code elimination might be more efficient. Etc, etc.

Third, we haven’t done it yet, but there could be other constant types like “buffer size”. The constant values are accessible at the compile-time and so might be used, for example, to allocate memory for an array statically and safely without touching the new operator.

arduino-cli compatibility updated

As you possibly know, XOD uses the arduino-cli tool to manage hardware packages, perform uploads, and interact with the boards in other ways. The used version is updated to 0.12 (latest at the moment), which brings compatibility with many new Arduino-boards to XOD. For example, XOD is now compatible with Arduino Nano Every and ESP32 out of the box.

As usual, the release includes other small improvements and enhancements. Read the full list on GitHub.

Get the new version of XOD from the downloads page or try it directly in your browser. If you have XOD installed already, click the update message when IDE starts.

XODlang

XOD visual programming language use cases and projects

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store