Look at your Old Code.

The internet is filled with questions regarding how to become a better coder. And the answers are pretty much the same: read books, do peer reviews, participate in open-source projects, etc. All those are excellent answers, but one issue that remains unanswered is how to measure your improvements as a coder throughout time.

One thing that I always encourage peer coders to do is to archive all the personal code that they write, no matter the language or subject. Put it somewhere safe (ie. git/svn) and keep it as long as you can. Then once a couple of years have passed, take some time to look at it. There is nothing more gratifying than looking at some old code and thinking: “OMG my code was so stinking awful!!”, nothing more satisfying than executing old handmade programs and games.

For example this past week-end I was looking through my archives from 7 years ago and found an old fizzbuzz.rb file laying around with some other ruby source files! I was pretty excited to look at it since I’ve never been a huge fan of it:

# I am part of the chosen 1/200th!!!! :)
# http://blog.codinghorror.com/fizzbuzz-the-programmers-stairwa
y-to-heaven/
(1..100).each{|i|
    if i % 3 == 0 && i % 5 == 0
        print 'FizzBuzz'
    elsif i % 3 == 0
        print 'Fizz'
    elsif i % 5 == 0
        print 'Buzz'
    else
        print i
    end
}

It still executes fine:

$ ruby fizzbuzz.rb

12Fizz4BuzzFizz78FizzBuzz11Fizz1314FizzBuzz1617Fizz19BuzzFizz22
23FizzBuzz26Fizz2829FizzBuzz3132Fizz34BuzzFizz3738FizzBuzz41Fiz
z4344FizzBuzz4647Fizz49BuzzFizz5253FizzBuzz56Fizz5859FizzBuzz61
62Fizz64BuzzFizz6768FizzBuzz71Fizz7374FizzBuzz7677Fizz79BuzzFiz
z8283FizzBuzz86Fizz8889FizzBuzz9192Fizz94BuzzFizz9798FizzBuzz

No major WTF moment. I looked at my code and actually had a couple of positive thoughts:

– I’m glad I put a small comment in there, it helped me remember that I wrote this code after having read Jeff Atwood’s article back in February 2007. This was the first time I had read about it and my reflex was to put it to the test.
– The code gives out correct results.
– The code is pretty readable.

And now I was also glad that 7 years later, a couple of things jumped out at me:

– The if conditionals can be rewritten so they are more readable
– The modulo math operations are performed twice
– The code has a bunch of magical numbers 1, 100, 3, and 5, preventing any easy change in the problem text.
– Nothing is tested

In a couple of minutes, I knew which parts of the code I could improve. Some of the stuff that I didn’t know about 7 years ago had now become reflexes. I then proceeded to write my new perfected version of FizzBuzz and hope to look at it in 7 years.

You never realize how much improvement you’ve made as a coder until you’ve looked at yourself as a coder a few years back. It lets you become the user of your own creations, and it usually brings back some fond memories. A month ago I fell upon this game I created back in college 10 years ago and had a blast finishing it even though it has many bugs (don’t try to skip the intro!!):


You can try it here: ICWars Java Web Start
(self-signed, might trigger some security warnings)

(In game: arrows to move, space to shoot. In starport: arrows to move, enter to select)

Your old code shows your creativity, your weaknesses, your strengths, your evolution and your improvements. It helps you stay humble and patient towards others coders. It’s your history in the byte world. It is precious. I urge you to keep it safe.

 

Creating Better Wheels

Back in february 2013, I was at a clumsy hotel in the business heart of Paris, La Defense, for a week while visiting Qualys’ French headquarters. The golden rule of supply and demand over there drives the prices crazy and I felt robbed as I entered the tiny, smelly and loud room that my company was paying 250$ / night for. A beautiful view on the hotel 20 feet away next door, freshly stained carpet, and exquisite torn tapestries. The final blow came when powering up my laptop and realizing that the wifi signal was like a distant whisper, too weak to be used though it had been paid for… After being disconnected numerous times within the first minutes of usage, I gave up.

I had been working on a side project for the past couple of months and had run accross the simple need to have a multiple selection combo box in tune with Bootstrap. I had spent a couple of hours trying to find or play with the closest solutions to my needs (chosen, select2, textextjs, etc) but I was not satisfied with the lack of configuration options. At the time they would all come short of the features I needed: some didn’t allow you to create free entries/tags, all had static layouts, the quality of the docs matched the one of my hotel room (they have all improved on this since), and it was a pain to achieve a pixel-perfect visual with Bootstrap. I had always been told not to reinvent the wheel but as I attempted to work with the existing tools I realized it might take me less time to actually rewrite a plugin from scratch.

A clumsy place with no internet and a poor TV programming for 4 nights was just the perfect moment to create my combobox. I designed it from scratch, with the inspiration of what had been done for the other plugins. It took me about 8 hours to get something that I was satisfied about, and because I had some time left, I took another 4 hours to build the documentation and prepare it to become open source.

While I had made several contributions in the past to other open source projects I was using, this was my first attempt at releasing an open-source project as a creator. I pushed it during the week-end and created a thread on /r/programming to expose it and tract a bit of attention. I was hoping for some good feedback. All i got the first 24 hours was a single comment saying:

http://ivaynberg.github.com/select2/

http://textextjs.com/

I have to say, I felt pretty bad and quickly concluded that my project was useless. I received a bit more neutral feedback afterwards with people who pointed out a few bugs and I spent some time fixing them for the next couple of days. I then exposed the plugin at two other places but always received the same answer: “why are you reinventing the wheel? It’s already been done before a thousand times.”

If you have ever created anything, you have probably been in that case as well. I think it’s pretty safe to say that in the software business, all the needs have been covered one way or another. Whatever you do out there, you will be reinventing the wheel. This is so disturbing it can even prevent you from starting anything. When John Carmack started game development, he felt like he was late to the party and that everything had already been done a couple of years before him. So why even bother?

Well, surprisingly, a year later, my tiny and simple open-source jQuery plugin MagicSuggest has almost reached 900 stars on github. It even was at the top of github’s trending list for a few consecutive days. Small achievement, yet big realization: I started as a plagiarist. I became an innovator.

Take a look at all the software/websites you are currently using and you will realize that almost if not all of them have replaced an existing product / website that was irreplacable at the time. Back in 97 everyone was using AltaVista to search the web. You would have been foolish to create another search engine back then. In 2005, all development teams were using SVN. And there were tens of other VCS available should the standard not fit. Why on earth would you want to recreate another one? Back in 2007 everyone was using emacs / vim / textmate / notepad++ to code. There were thousands of editors out there and you would have been foolish to create another one. The list goes on and on, with similar patterns. similar initial end-users criticisms, similar end-product success.

There’s a quote wrongly attributed to Picasso that is often quoted today: “Good artists copy, great artists steal” that Steve Jobs would often refer to. I prefer the W. H. Davenport Adams version:

“Great poets imitate and improve, whereas small ones steal and spoil.”

The great truth about software is that there is no perfect round-shaped wheel out there. We should be very careful when criticizing those who imitate: the ones who attempt to recreate something are the only ones who can seize the opportunity to make it better. And if you want to contribute to the future, start looking for people who have the guts and skills to question the standards of today.

In our little world of code, innovation is not achieved through creation. It is done through improvement.

The illusion of phone security

My phone has become my everyday tool. I use it to check my mail, write blog posts, check my bank accounts, play games, perform transactions. I use it so much I often forget that it holds so much sensible data. If you were to get your phone stolen by someone, what passwords or accounts would he have access to? My phone checks my mail automatically on all my accounts. Very convenient. But I realized today that this convenience is an expensive asset. You think your paypal account is safe? Anyone can ask for your password to be reseted. If that someone has access to your automatically-checked mailboxes, he has access to your bank account, your facebook profile, and pretty much your entire digital life.

All of that digital life in the palm of my hands or in my backpocket is a danger I tend to overlook.

Some of you may have some locking mechanism such as a 4-digit phone pin… But really, when was the last time you made sure noone was looking as you entered your pin #… (even worse: most people choose the same pin # on their phone as their credit card pin #) I personnally think it’s better not to have any locking mechanism on your phone and behave like it has absolutely no security rather than believe in the illusion of its security.

I need to find another way to authenticate myself to my mail servers on my phone.