Let's Design a Language: C♭ - Part 1
I’ve got this huge project that I work on every once in a while. I want to port Objective-C to the Common Language Runtime. I’ve been working on it for two years, restarted it three times, and have really not come any closer to finishing it because of the normal excuses: family, work, other projects, weariness, lack of falafel, the moon in the wrong phase. You know what I mean.
I love languages
But, I really love languages and language design. I believe that if you really study how a language works, you can sense the thoughts of the designer. They wanted to solve a problem and decided that a new language would help to do that. Very rarely do you get the actual words from the creator of a language; Boo‘s creator, Rodrigo Barreta de Oliveira, published a manifesto defending his decision to create Boo. It opens with the following.
boo was born almost a year ago out of my frustation with existing programming language systems and my growing love for the Common Language Infrastructure and the architectural beauty of the entire .net framework.
I was frustrated mainly because I could not use the language I wanted to use (python at the time) to build the kind of systems I needed to within the technological framework my company has settled on. I had two options: I could either use a different framework (such as the python standard libraries and runtime environment) or a different programming language (C# was the logical choice for such a long time C++ programmer like myself).
I tried both and was completely satisfied by none.
I still think that Boo for all its immaturity remains the best CLR language available. C# has adopted a lot of the features that you can find in Boo; however, the C# compiler guys usually did it in an inferior way.
Esoteric programming languages
An esoteric programming language (sometimes shortened to esolang) is a programming language designed as a test of the boundaries of computer programming language design, as a proof of concept, or as a joke.
from Wikipedia’s entry on esoteric programming languages.
Examples of esoteric programming languages:
- LOLCODE - A language based on the language of LOLCATS
- brainfuck - An Eight-Instruction Turing-Complete Programming Language
- C- - This language was named for the grade received by its creator when he submitted it as a class project in a graduate programming class. C- is best described as a “Low-Level” programming language. In fact, the language generally requires more C- statements than machine-code statements to execute a given task. In this respect, it is very similar to COBOL.
- Whitespace - A language in which any non-whitespace characters are ignored; only spaces, tabs, and newlines are considered syntax.
Funny.
A new language based on the usage patterns of C#
When Bjarne Stroustrup created a new object-oriented language based on C; he
called it C++. Looking at it just now, I get what it means: the next version
of C. Because, in the C language, ++
is the postfix increment operator.
That’s clever! Man, I’m dense for never noticing that.
Let’s be clever, too!
In our case, we have a popular language named C#. However, after working with other programmers using C# for nine years, I’ve noticed some usage patterns of my co-workers. So, why not just make a language that supports those usage patterns in a natural way?
I’ve decided to call the language C♭ becuase it will consist of a subset of the features found in C#. (It’s a musical reference. And, yes, I know there’s no such thing as C♭. There’s really not a language, yet, too.) Since my peers don’t use some the language features, let’s just get rid of them altogether! For the features they use regularly, let’s make those required!
Features of C♭
So, how do “real” programmers use C#?
All public methods for classes are static or property getters/setters.
: It turns out that a lot of C# programmers love those two features of
classes. So, why not just make it that way all the time? This means we can
get rid of annoying things like the static
keyword.
Methods only take one parameter and it’s a lambda/Func/Action. : It’s the “modern” way of programming C#. Who needs to worry about value types and PONOs when you can supply an anonymous method? For an example of this, look at Topshelf’s Creating a Service.
The compiler fails to compile a file that contains less than 300 lines. : C# developers love them some big classes. While the innovative programmer will figure out how to get around this by having 200 ‘\n’ characters at the end of the file, they probably won’t use this language.
The compiler fails to compile a file with any XML documentation. : Frickin documentation. Who needs that?
All property getters and setters are virtual.
: Just like in Java. They got it right. So, we don’t need the virtual
or
override
keywords anymore.
Declarations MUST use the var
keyword.
: Let the compiler figure it out.
Global variables are allowed. : That Singleton pattern is hard to write! And, since C# programmers like to do it so often, let’s just get rid of it and make true global variables. It’s time to ditch that stupid abstraction.
Every class is IDisposable
.
: Screw that stupid argument over the correctness of how IDisposable
works.
We’ll just make every class implement the interface. And, we’ll use the
compiler to create fancy finalizers and what not so we don’t have to like
the way we get empty constructors on classes that don’t define one! Speaking
of which…
All constructors must have at least one Boolean value. : Because that’s how we tell the class to act one way or the other!
The compiler will automatically generate an interface for each class. : Why rely on Resharper to “Extract Interface…” for us when we can have the compiler do it? Therefore, a class “Nachos” will automatically implement a compiler-generated class “INachos” that we can use everywhere in our program.
In C♭, the ubiquitous Hello World will look like this:
1 | using System; |
If you have noticed any specific way that programmers have used C# and I have not listed them here, please leave them in the comments section. Let’s make this a group effort!