Ruby, say hello

1
2
3
4
int main() {
   puts("A shiny red gem.");
   puts("We call it Ruby.");
}

Rather strangely I decided to code in the Ruby language. As the only project I am working on is my little “compiler” project it means I am currently messing around with writing a compiler using Ruby.

So why strange. Well I am a huge proponent of static typing as a way to build robust fast software. It has not always been that way and I slightly brought into the hype a decade or so ago that dynamically typed languages allowed the removal of syntactic noise along with things like garbage collection meant you could really think about the problem rather than the hardware.

Outside of certain domains I consider that statement to be false. Statically typed languages gradually removed the noise and other advantages by adopting many of the features common in dynamically typed languages while keeping their static typing.

In return some dynamic languages added gradual typing so the battle continues.

So what do I mean by certain domains. Well there is basic scripting that is automating things you would do on the command line. Experimental/Exploratory work where you are writing short programs to understand an area. Prototyping where you don’t plan to harden off the code or maintain it for long. I guess driving calculations such as what we see in python in AI being used to load and set up large C++/GPU libraries

While statically typed languages are attacking these areas, you still find dynamically typed languages filling these roles in a productive way.

I guess I like static typing as it limits the number of combinations of entities/object in your program that result in the program being ill formed. As these forms are eliminated by the compiler it is something that you get for little cost. With dynamically typed languages you would have to write more unit tests and even then that is not the equivalent as have the compiler prove program is well formed in terms of the types being checked.

It can lead to slightly more code but that, in my mind, is a fair trade off, Recent C++ version and Rust both do a good job reducing this increase in typing.

To bring this back on track. Why Ruby? Well I was messing around in C working on a simple type systems and I looked at my code and notice I am dealing with linked lists and refactoring to reduce the memory usage. This felt like a long way from where I wanted to be at the moment in development.

I wanted to be in the exploration/experiment stage of development not fine tuning code. Optimization should not currently be on the table of things to worry about. Instead I wanted to be spending my time thinking about compiler algorithms and language design. Eventually if I keep at this project I would want to code the compiler in the language I am creating so the code I wrote will not be in use in the future.

Now I could have switched to using C++ or Rust. Past experience has taught me I will still end up thinking too much about optimized memory allocations so I figured it would be fun to try doing it in Ruby.

I am confident that when I hit 5000 lines of code in Ruby I will no longer feel like I am in the sweet spot of exploration of the topic and will be ready to rewrite in a typed language.

I actually started with Python but after a couple of evenings I was thinking about adding the optional types. That’s another distraction to the goal of exploration. Having wanted to try Ruby on and off in the past I figured this is a good project to try it out with.

I know from personal experience writing more than a thousand lines in a dynamically typed language requires either many unit tests or a real focus on simplicity. I admit the idea of simplifying on these vectors appeals to me at the moment. Particularly with the knowledge that I will eventually do a rewrite. It is perfectly possible the whole exercise will lead me down some interesting avenues of simplification.


707 Words

2020-04-22 23:00 +0000