Sean Middleditch » 2006 » August

So I’ve been thinking about my ideal programming language. C++ is a great language, but is still a little too low-level in places. Being _able_ to write low-level code is a necessity, but being _forced_ to do it even for trivial and routine things is not good. C#/Java are pure-OO languages, not to mention they aren’t all that low-level, and they both bring huge runtime requirements with them.

I want something that let’s me get low-level, but also has enough language/syntactic support available to make high-level abstractions of common routines easy to develop and use.

While I’m tempted to design this as an extension or modification of C++, there are enough things which I feel C++ gets “wrong” to want to do that. I’d instead base it off of C99.

Here’s the list of incompatbile changes to the C language I’d make:
* Clearly defined sizes for all types. int is 32-bit, long is 64-bit, short is 16-bit, byte is 8-bit. I’m not sure if I’d want char to be 8-bit or be a “wide” character by default; I’m leaning towards the latter, for the moment.
* Provide a far more powerful macro language (explained below).
* Instead of all symbols being public by default and using “static” to make them private, I’d instead make all symbols private by default and require “public” to make them public outside that translation unit.

Note that I’d still like to have, like C++, a way to do an extern “C” {} block to include C headers to make it dead simple to link to and use C libraries. That means we have to keep the C preprocessor support, among other things.

Just making the few changes above would barely be the worth the effort. There’s a lot more I’d like to do.

First, I do want classes and objects. Unlike Java/C#, however, I don’t want to force them down the programmer’s throat. Instead, it’ll be more like C++, where you can use them if you want and do things procedurally (or maybe even functionally) as the need arises.

My ideal class system would not be like C++’s, however. First, no multi inheritance. There’d be single inheritance, interfaces, and mixins. Mixins are something which I feel most statically typed languages miss out on. A mixin is basically just a special type of class which cannot inherit from any class or interface and which cannot create new virtual functions. It may provide implementations of virtual functions, however, or declare itself as a mixin for a particular interface. It can also define new non-virtual functions or member variables or operators.

Essentially, it’s just another form of inheritance that makes sure you can’t create the sort of ugly situations that multi inheritance in C++ often spawns.

Another thing I would do differently is that classes and structures would not be the same. Structures cannot have methods and cannot inherit or be inherited from. Every object of a class also always has a vtable pointer and a virtual destructor.

The class vtable would also include some additional information about a class, such as the class’s name (in normal programmer-friendly style, not mangled) and some other (very light) data which could be used for introspection. For example, a simple array of member names, type information, and offets. Or a list of methods, including vtable offset for virtual methods, return value, and argument list.

I want the typeof() operator, as well as the ‘var’ keyword which declares a variable and deduces its type from the value assigned to it.

A foreach loop construct, which requires some concept of iterators at a low level, would be really useful.

Anonymous functions (lambdas) are something no language should be without.

Multiple return values for a function would be incredibly great, too.

I want each case inside a switch to require either a break or continue statement at the end. That is, break will do what it does in C, but there’ll be no automatic fall-through; instead, you’d need to use the continue statement.

Speaking of which, break and continue should take an optional operand which tells it which loop to break/continue in. For example, break; would be an implicit break 1;, meaning to break out of the first loop containing the statement. A break 2; would mean to break out of both the first and second containing loop. A label name could also be provided, for labels attached to loops.

So, the macro language thing. I’d like to see a macro language that integrates deeper into the compilation process. The C preprocessor was originally designed as a completely separate step from compilation. Many old compilers (and even a good number of modern ones) use a separate process to preprocess the C code and then feed that into the actual compiler.

I’d like the macro language to be able to make use of information which would only be gleaned at compile time. Sort of like what you can do with a combination of the C preprocessor and C++ tempaltes, only far less of a pain in the ass.

To start with, a lot of what you currently need C++ templates for could be fixed by just having some better introspection facilities in the language. A statement like if(typeof(myvar)==typeof(char*)) would solve a lot of problems. However, the shortcoming of this is that such statements can only be inserted where an if statement is normally allowed.

A macro language can integrate further up the compilation process. Macros are a tool to modify the parse tree, not the intermediate bytecode or machine code.

I’ve started a barebones projects to work on this ideal language, mostly just to see where I can take it, not as a truly serious effort. I’m making a tool which spits out C code (much like early implementations of C++ did). If I like where it goes, and I get a stable language spec out and some community interest, maybe someday in the future I’ll work on a proper GCC frontend.

Alright, I’m getting sick of being asked this, and I’m sick of people’s misconceptions of it, and I’m sick of having to re-explain it to everyone, and I’m sick of her being insulted unjustly.

What happened between Laura and I mostly sums up to “Sean screwed up.” It was not in any large part her fault. I’m not going to put up with people attacking her personal character just because she dated me and now we’re not together. Any venom you might feel entitled to spewing at her on my behalf is uncalled for; the only one deserving any venom for all of this is me, not her. Clear? Good.

My roommate, his cousin, and I did some nice carpentry work yesterday. $50 worth of lumber, rope, and hardware later, we now have a “pel.” Basically, it’s a post with rope wrapped around it. We had to make on a base because, at the apartment, we can’t cement in a post like we’d have wanted. We also had to make it out of a 4×4 instead of a round post because Home Depot didn’t have any round posts of the necessary girth and height.

Anyways, it’s all together, and looks mighty good. I now just need to head out to Lowe’s and buy some steel pipes and have them cut down to 3′ and 4′ lengths for muscle training.

I also finally made a sword out of the rattan I bought off of Grace. I definitely like the weight it has. I’m quite pleased.

Life update:

I moved out of my parents’ house. I’m now living in an apartment with my friend Shawn Pearce.

I quit my job at the Township. I now do freelance work for considerably more money at considerably fewer hours.

Laura and I broke up.

I’m in therapy for severe depression, which I’ve been suffering from for the last four years or so.

Suffice to say, my life looks almost nothing like it did a few short months, or even weeks, ago.

Anyway, this blog is back. I’ve had quite a few people, both those I know personally and even many I’ve never met, tell me they actually read it, which implies to me that there is some value in continuing to write it, so I will do so.