So Much of C++ Coding is Making a New Language

Building Great Code

I'm working on my latest new project - a simple lisp-like language in C++ that is intended to be fast to execute and very memory efficient. In the past, I've built something like this, but it was more of an interpreter, and this time I'm heading for a more JIT-style system where I'm going to be creating in-memory data structures and then running them over and over as the values come in. This matches up more with what the use case is: data stream processing.

What I'm realizing that as I build the code in LKit, I'm really building a new language based on C++ and the objects and operators that I define in C++ for this problem domain. Think about it: C++ has only the basic data types of C, but it ships with the ability to deal with complex data - yeah, a + bi complex data.

You can create these as if they were simple data values, add, subtract, multiply them… even stream them out. For all intents and purposes, the shipping compiler really supports complex data types. But it's really all just built on top of what's there, and that's the real power of C++ to me - the ability to really augment the language to be able to add in data types and operations that make perfect sense in the domain, but aren't in the initial cut of the compiler.

I've create a value. This value can be a bool, an int, a double, or a time stamp. I can add these, compare them to one another, and to the data types they represent. They look, act, and process exactly like they were part of the language. That's really quite incredible. But it comes at a cost: you have to code it all up.

You have to code up the operations. You have to code up every little thing about how to handle these new data types, and if you don't, then it's not there. It's a lot of code to throw down, and I can see why a lot of people shy away from it, but it's got a lot of power, and there's reason to be careful with what you are doing.

But in defining this language, I really have a tremendous power. I get to define how all this works, and what it all does. I can make my resulting C++ code look incredibly simple and clean by making sure all the operators and functions are there to support what one would naturally want to do with these data types.

This makes the language almost domain-specific. And that's one of the things that makes coding in C++ so amazing to me. Great tools.