How to learn new things using side-projects

06 May 2014 — By Marc — In about

Having side-projects is one of the best thing you can do to become a better programmer. But mostly, it can help you enjoy coding even more while learning new things.

My side-projects have helped me get a job, travel the world and meet amazing people. They are part of how I express myself. I see them as a form of art and as my most valuable assets.

Here’s the story of how I learned how programming languages work trough my side-projects.

However, my goal was never to learn how programming languages work. My goal was to create one, so I had to learn. I think this is very important. Learning for the sake of learning never worked for me, but learning because I wanted to do something with that knowledge did.

The Dream: creating my own (very fast) programming language

I remember browsing programming forums, Reddit and Hacker News and reading answers from people who knew about programming languages, virtual machines and such. I was in awe! How could they know so much? Surely they were some kind of mage or very old programmers who invented silicon chips. I felt I could never be as smart as they were.

During that time, new Ruby implementations where being released on a monthly basis. All the cool people were working on one. It was considered the ultimate accomplishment for a programmer to create one.

As a result, my dream was to create the fastest and smallest Ruby implementation EVER! No less.

July 2008: The Inspiration

I first discovered TinyPy, a Python implementation in 64 Kb of code. I was blown away that you could implement a language with so little code. Creating one was starting to look a little more accessible to me. It was just few lines of code to study and understand… right? …

That’s where I got the crazy idea to create a Ruby equivalent of TinyPy. Of course, I called it TinyRb.

I knew a little bit of C and a little bit about Python. But zero about parsers, VM & languages. I tried understanding the source of TinyPy but it was too much for me. There were a lot of one character variables and bizarre tricks I’d never seen before.

I almost gave up, but then I found HotRuby. HotRuby is a Ruby virtual machine implemented in JavaScript. Bingo! I knew a lot about Ruby and JavaScript and learned a great deal from that source code.

I was very inspired and started coding on TinyRb, porting some parts of HotRuby and some parts of TinyPy I understood. Here is the first commit.

However, I gave up after a few days. But I did learn a lot.

September 2008: My first language… well, kind of

That was about the time that the Chrome web browser was released along with its V8 JavaScript interpreter. V8 was one of the fastest JavaScript interpreter at the time. This gave me an idea.

Lets plug HotRuby into V8. HotRuby could execute Ruby and V8 could run HotRuby (since it’s written in JavaScript). I ended up creating the first Ruby implementation running on V8.

But that was a big giant hack. I didn’t create a language, I was simply plugging two things together. Still, that was a start. I could feed a program to it and it would execute.

December 2008: My first real language

I kept trying to learn about parsing and compilers. But most libraries were too complex for me to use and understand. I finally discovered Treetop, which was a simpler and well documented parser and LLVM (a generic compiler/VM), which had nice Ruby bindings, tutorials and code samples in Ruby.

I plugged the two together and ended up with a very very simple language called Orange. The first one I ever built from the ground up.

February 2009: The real deal

The pieces were starting to make sense and I knew enough to start reading books and research papers about virtual machines and programming languages. Lua had some very good ones, but as a neophyte, it often took me a full week to understand just a few pages. But it was fascinating!

Even to this day, I consider the Lua virtual machine to be one of the greatest code I’ve ever seen. Call me crazy, but to me it’s a piece of art. I am fascinated by the Lua bytecode even to this day. So I had an urge to learn all I could because I wanted to create code like this. I wanted to create something that was art to me. It was no longer just about creating a fast Ruby implementation to impress my friends.

I stumbled on another cool and small language called Potion and got even more inspired.

All of this together was the spark that I needed to complete my grand project. I don’t remember feeling so motivated about a project. So I quickly got down to business and re-wrote TinyRb. After 10 days, I released the first version.

September 2009: No books?

You might have noticed I didn’t read any books to get started. I tried, but they were all long, boring and too advanced. There was nothing targeted at beginners. So … I wrote one :)

Four lessons from my experience

Here are a few key things I learned from that experience about completing a project and learning new things.

1. Never start with nothing

Copy or inspire yourself from the code of others to get started. Never start from a blank project. Steal, borrow, mimic, translate, port, whatever you call it.

The first programming language I wrote was a port of another language. That means I simply translated from one language to another.

Then, each time I created a new language a started on the foundations of the previous one.

2. Inspiration is perishable

For each one of my projects I’m extremely motivated at first. But that usually doesn’t last long. If you’re inspired by something, don’t wait for the perfect time to do it. It will be too late, because you will no longer be inspired.

Inspiration is your most important asset! It is the fuel of your project. Don’t let it go to waste!

3. There is no such thing as a failed project

Some of the early languages I created were horrible and pointless, but each time I learned something new. Each time it became easier and I was more inspired by the possibilities.

Don’t let the fact that you’re building something “useless” stop you. You’re always building something useful if you think of it as a learning opportunity.

4. Lower your expectations

My goal was to create one of the fastest and smallest Ruby implementation ever. When I tried implementing that from the get go it didn’t work. I had to create many small languages before that. Starting with some blatant hacks and incomplete projects. But, always doing a little bit better each time.

You want to work on interesting projects too?

This is what the club is all about! We’re a group of passionate programmers who work on cool new projects each month.

Some members have created games, others languages or frameworks.

I hope to see you in the club!

- Marc