Why you should reinvent the wheel, but shouldn’t use it

Why you should reinvent the wheel, but shouldn’t use it

I am a passionate developer. I didn’t choose this path because I wanted to make big money, or create the next Unicorn. I became a developer because I love code.

I started coding early, at about twelve. This was a time were the Internet was barely emerging. the access to information was scarce, but yet there. You had to know the right words to find what you needed. Thus, at the beginning, I was “reinveting the wheel”. A lot of times. And as a developer we are often told “Don’t reinvent the wheel”.

I strongly disagree with that. I really believe that every wheel I reinvented made me a better developer. What I believe is that you should reinvent the wheel, but you shouldn’t use it in the real world.

Let me illustrate this with a skill I got when I was in college : regular expressions.
I had this project that required to parse a human-readable file to a 3D scene. This was a pet project, I wanted to build everything by myself. So I decided to write my first parser (I didn’t know that was a parser at that time). And I got stuck on a problem : how do you parse the string lexeme ? This is not a keyword, this has arbitrary length, and sometimes you use the backslash to add special chars. So I invented my own syntax and an algorithm to parse lexemes. It took me about a week to make it work properly. It was very basic, but fitted my needs.

Then a friend told me “Do you know about regular expressions ?”. Of course I didn’t. So I started my 56k modem and typed “regular expressions” on Google. What I read got deeply written in my brain. That was exactly what I was trying to do. So I obviously started using them and dropped my home brewed syntax.

The fact that I got stuck on this for a week made me understand the challenges that regular expressions were solving, and the power of its syntax and simplicity. Now, I am pretty good at writing them. I often have a colleague coming to me when he is stuck on a tricky one.

But the most important thing this experience made me understand is : to become an expert in something, you have to dig into it, to try to solve it by yourself. The outcome won’t be very valuable or even usable, but you will learn at lot of things along the way.
And when you did that, you should drop it. Because others have already solved this problem, probably better than you did. But now you can see why this is better.

You really should reinvent the wheel as many times as you can. But don’t use it on a real world project.