Language Design

Posted by Rusky on Feb. 21, 2011, 7:09 p.m.

So, before I begin, how can I update my submissions? Do I just resubmit them or is that not implemented (yet) in v3?

C is a relatively nice high-level assembly language. C++ is the kitchen sink sitting on top of that, so you can do lots of things with it but it can be painful. I'm sure this will be disputed, so I'll get to it in a minute. Java is a simplification of C++, but in some places it oversimplified like with "a.setFoo(a.getFoo() + 3)." Scala and C# move back toward C++, but they're both still on VMs and designed for high level applications.

That leaves us with few options for low-level and/or performance-sensitive projects like game engines, operating system kernels, embedded applications and almost anything else fun. Contemporary, well-supported, easily-accessible and well-enough designed languages include C, C++ and… well, anything else fails to meet our requirements.

It's obviously possible to write large projects in C (e.g. the Linux kernel) but it's not the best-designed of languages. All the little things like type conversions, declaration syntax, scope and namespaces and verbosity make C more painful than it could be. Then larger-scale issues like polymorphism (ad-hoc/inclusion and parametric), higher-level functions and type safety go out the window.

C++ almost had to be based on C to become popular, so it inherits a lot of its problems. In addition, it's just a big kitchen sink bolted on top, so it lacks the elegance of languages like Smalltalk that a lot of its ideas come from. Larger projects have to enforce restrictions on different allowed subsets of features (Google eliminates exceptions, RTTI and multiple inheritance in the interest of compatibility, less fragile code and consistency).

I would like to design a systems-level programming language that can be as efficient as C but can also be much more expressive and easy to use than C++. Rather than designing by committee to build a checklist of features, it would need to have a unifying idea, like Lisp, Smalltalk, Haskell or Go. The systems-level programming world needs something like that.

Rather than starting from C or C++, I'll start from scratch. The goal will be to use a small, easily-learned feature set that will allow a large range of simple, concise designs. Things like Lisp macros, Haskell type classes, Smalltalk/Objective-C message passing, etc. Haskell comes closer to this than Smalltalk, in that its type system is much stronger than C's (although it would need some tweaking to allow the required control over memory layout, etc.), but still allows all the uses of C++ virtual function calls, CLOS multimethods and OOP-style namespaces.

Anyone have any stories of things they'd have liked to be able to express in their favorite programming language but couldn't without resorting to verbosity, repetition or some ugly hack or other?

Comments

ludamad 13 years, 10 months ago

C++ will always appeal to me. I realize it's flaws, but there is something appealing to me amongst the mishmash. I find that I can safely wade through the mess of features, and it can be used a 'better C'. I recently wrote a scripting language in C++ and I can safely say it was a very good fit. The object system of my scripting language was written in C-like code, but with the convenience of C++ features at hand. D would be just as capable of these low-level features, and my choice of C++ over D was of course for knowing C++ better, but I found it to be a painless project. Like you mentioned I did restrict myself to a subset of C++. However it is when you find you need those other features you are glad they are there.

Anyway, I am of course willing to admit that C++ is flawed in many ways and is just a bit ridiculously complex in areas. Now I'd like to talk about that dynamic scripting language I've been working on recently.

In my object system, every object is allocated and has a reference count (note, C++ made this low level management of reference count very automated with constructors/destructors for a special reference class, which for the curious would be inlined into the assembly).

The syntax I partially borrowed from python - it struck me as clean and simple, so I don't mind admitting to heavy borrowing.

The main difference from python is that every object has copy-on-write functionality (change directly if ref count == 1, otherwise create new object). As a result the list class is both fundamentally safe and fast to change. The dictionary class has similar functionality.

The scripting language is fully functionality and implemented using ASTs, I will further compile to byte code for saving soon. Anyway heres example syntax:

d = {"1" => "Hello ", "2" => "World"}
s = ""
for i in d:
      s ~= d[i]
println(s)

Undeadragons 13 years, 10 months ago

Wow luda, that is a neat little scripting language you have there, may I enquire for what it is being made?

I'm also using C++ for a project at the moment, basically implementing a whole bunch of GM's features in C++ and it has been relatively painless, but as I've mentioned, there have been a few times where I have had to resort to things like overloading operators for primitive types (to allow me to do things like "Score: " + string(var_score)), but all in all it has been relatively good.

Rusky 13 years, 10 months ago

I agree that C++ has a certain appeal; that's why I bring it up so much here. However, I may have been spoiled by languages like Haskell- writing a scripting language in C++ now seems like it contains an awful lot of boilerplate and unnecessary decisions about memory management.

That sounds like a fun project- what kind of features do you have/plan on language-wise?