Developing CX

From Smart Contracts to Machine Learning and Video Games…the Sky’s the Limit.

CX is Skycoin’s feature-rich programming language. It is designed to address the growing needs of Skycoin’s ambitious ecosystem of projects that can’t be satisfied with any other available languages.

Unlike other domain-specific languages such as Solidity, CX is a general purpose programming language. This means that the next wave of blockchain developers will be able to do just about anything with CX: smart contracts, decentralized apps, machine learning, video games, even CX itself will be developed with CX.

In order to provide a rich user experience for millions of people around the world, we needed a robust language that is highly optimized yet easy for existing developers to learn. Coding in CX uses best practices and paradigms that developers already prefer. In essence, CX is a deterministic, statically typed, interpreted and compiled language, yet you don’t need to be a techie to understand the journey and decisions made in its development. Work on this next-generation language began in November 2017 and it started with consideration for quickly onboarding developers.

The Syntax

Programmers have strong preferences for the languages they like to work in, and one of the main factors influencing that preference is syntax. Syntax is the set of rules for writing in a programming language, with some being more complex and hard to read and write than others. We started with LISP in mind, but ultimately decided to use the more modern Go. Golang, or Go, is an open source language designed by Google engineers. It has been made concise and easier to read for programmers without sacrificing features or performance.

Prototyping and Basic Functions

Moving forward with Go, we developed the first prototype for CX with basic functions. As a strictly typed language, a variable or piece of information cannot be changed from one type to another after it’s declared. For example, a number variable cannot be changed into a string of text or vice versa. This prevents a lot of bugs that can be made when a program grows in complexity. While it may be a little more work early on, it prevents a lot of common errors in the long run. Because CX is deterministic, the same inputs will produce the same outputs regardless of the environment or machine that is running CX.

Another common choice among languages is between interpreted or compiled. Compiled languages can provide faster performance and more optimization, with the added step of compiling a program before its run. Interpreted languages work without the compilation stage and are considered easier to implement. With CX we decided that we could do both, giving developers the flexibility of an interpreted language as well as the performance of a compiled language.

We then introduced input/output functions and an openGL library for rendering graphics. OpenGL is used in a wide variety of applications including virtual reality and smartphones. If you’re a gamer you’ve probably played a major game made with OpenGL. We’ve prototyped some games made with CX and look forward to seeing what the next wave of CX developers build.

“Crappy Ball CX”, a Flappy Bird clone coded in CX

How CX Improves Security

One of the major innovations added to CX is the affordances paradigm. We looked at major blockchain scandals and the hacks behind them, and built features into CX to prevent these types of hacks from occurring. In object-oriented programming an object is defined along with its properties, inputs that it takes, and functions that it can perform. To programmatically create a “car” object, for example, you would set properties such as its color or the number of wheels, and add some methods to it like “turn on” or “move forward.” This is a decades-old paradigm used in most of the applications we interact with daily. Affordances add an extra layer of security by allowing the programmer to set user permissions for objects. In the affordances system a user can query the language at runtime to get a list of what can be done with a CX object. To use our car example, imagine a thief steals your key and tries to start your car, only to have permission denied!

Your CX Programs Can Get Smarter

CX contains machine learning tools built in, opening the possibility for CX applications to solve problems it doesn’t currently know the answer to. Using genetic programming, CX can take a problem and attempt to solve it, adjusting its approach over time and come up with powerful predictions.

CX Can Clean Up After Itself

Using a powerful garbage collector, CX can optimize itself by reclaiming resources that aren’t being used, freeing up memory. This gives it advantages over languages that leave it up to the programmer to manually find these unused resources.

Your Eye in the Sky

A production-ready application can contain thousands of lines of code spread out across dozens or hundreds of different files written over the course of several months. Understandably, an object might get left behind in code because nobody remembers why it’s there and modifying or removing it could have unpredictable consequences. CX’s object explorer gives developers a birds-eye view of all objects and their memory allocation.

Putting It All Together Step-By-Step

CX’s stepping feature lets you stop a running program, troubleshoot, add some steps, then continue running. At this point you can do many things, for example, get a rundown of the current state with the object explorer or use genetic programming to improve your debugging. CX’s serialization feature means that every object can be serialized, so you can save your state and send it across the blockchain.

Challenges Ahead

This is a forward-thinking programming language that will run applications that haven’t yet been dreamed up. In order for CX to be up to the task we’re working hard on performance and optimization fixes. We’re seeing continuous improvements through the use of shortcuts and assembly language. Even the garbage collector itself is constantly being optimized.

CX development timeline

Golang Must Go

Currently, performance is our main challenge and CX relies heavily on Golang. We’re moving CX’s stack, code segment, and data segment from Golang to byte array. Eventually, CX will be completely made with CX.

Ready to Try CX for the First Time?

If you’re a programmer or student and want to learn more about CX, you can get your hands on our newly released book series. The first book introduces the basics of the language and future books will teach you how to program with CX for video games and smart contracts.

v0.5 of our very own CX programming language textbook.