This post is part of a running series of posts. Click below to catch up!
I'm making a programming language. What's it look like?
TheOneAndOnly ・ Jan 27 ・ 3 min read
It's finally time to start making posts about actual implementation. Actually, this post is more about what to do right before you start implementing something.
So, let's start things right. At least, let's start it right for you, fellow developer. I was not so lucky.
When I began implementing this project I went through many languages and many wastes of time, and I want to go into every reason I chose the language I did because it impacts just about everything implementation-wise, from your code architecture to your code flow. I know that everyone can't just pull a language out of a hat and start a project in it (I might make a post about honing your skills to be able to do that one day), so this post will be more about project organization and knowing what you're doing before you do it.
What do I want out of Cure?
So I've been toying around with the idea of bootstrapping Cure. This affects my choice because Cure is meant to be transpiled to C and compiled, which means that if it's bootstrapped it really doesn't matter how fast the first implementation language is-- it just has to work and be fast enough to iterate a new compiler in Cure (which hopefully runs fast itself).
I did not know this starting out.
For my first (out of many) tries at making Cure I started with C. I promptly had an existential crisis and quit.
Alright, second try, can't be too bad. Maybe I needed a higher level language, C++ let's goooooo--
Okay, third time's the charm. Maybe it was the SEGFAULT's that were tripping me up, let's try Rust. It actually went pretty good, relatively. But slowly the reality came up to me.
I was too dumb for Rust Rust was not my preferred language to work in. I was making slow, trodding progress and my codebase only got more hectic as I tried in vain to please the ever-hungry borrow checker.
It was that last one that got me to re-think what I was doing, because that was pretty much 3 months of my time spent trying to work on Cure down the drain. I needed to evaluate exactly my goals out of Cure and pick the right workflow.
From my first draft of the compiler I want (in order of importance):
- A clean codebase
- Easy portability and readability
- Ability to run C Code
Whatever I code in, it needs to be able to do all these things. Now, I mention portability because I might redo the compiler in Cure once I finish this one. Since it's compiled to C the speed of the bottom one wouldn't really matter. Above all, though, I want a codebase I can smile at coming back to.
I chose Go. This was not a rash decision but it was a reluctant one. I have never used Go before, only taken a look at its syntax a while ago and steered away because of PascalCase and lack of generics. HOWEVER, when I took a second look at it for Cure, what'd'ya know? Generics are in, and things were looking more hopeful. I'd tried a little out in V and I liked it (actually wish V was more stable so I could reasonably put together a project in it) so I decided Go could probably work. It's fast, no-nonsense, data-oriented, and quite robust. I'm pretty sure there's even C linkage support (which is good in order to statically link standard library functions in C easier). In fact, I used ideas from Go's syntax in Cure's. Besides, Cure is like an amalgamation of Rust and Go.
How's it been?
It's been about 5 months of working on this and it's really good! Go is a great language and while there's some style things I don't agree with and project organization is kinda trash to me the language itself is very nice and it makes my code easy to come back to everytime. Right now, I'm maybe halfway to having an MVP, although development has slowed a bit with these posts.
So, in conclusion, make sure to lay out your big projects beforehand-- it will save you lots of time and effort in the long run. Also, I recommend learning Go, just because!
This has been TheOneAndOnly, wishing you amazing readers a wonderful time programming. If you have any questions, concerns, comments, or protests to make leave them in the comments. Expect more implementation-oriented posts about Cure in the future!
And as with every post, happy developing!
Top comments (0)