Common Refactors: Introduction.

The first programming language I ever learnt was Common Lisp.

Historically, Lisps provided a level of expressiveness not found in most programming languages used in production in the 20th century[0]:

(DEFUN VOWELS-IN-WORD (WORD)
    	(LOOP FOR CHAR ACROSS WORD
            COUNTING (FIND CHAR "AEIYOU")))  
(VOWELS-IN-WORD "HELLO WORLD!")
> 3

Problem was, Lisp(s) don’t look like most languages. When I landed my first professional project, it consisted of maintaining and extending a legacy codebase written in C# and jQuery.

Having barely touched an ALGOL-like language before, combined with a fire to write first and think later, I wrote a lot of horrible code. Luckily we had strong pipelines and code reviews, where most of my crap got stopped by more able developers before it could do any real damage. This forced me to rewrite, clean up and simplify my code. It also made me realize how much collective effort goes into maintaining a codebase, and how important it is to help and share knowledge with coworkers.

A few years later and the table has turned; now I’m the one looking at code with a scrutenizing eye, asking juniors to rewrite, clean up and simplify. Eventually, one can’t help but to notice that while the pappardelle and fettucine might appear different, but they’re both in fact spaghetti[1].

This series of posts is to draw out the similarities between these type of messes (using real examples), and hopefully clean them up a bit.

Next >

[0] Except Erlang, Smalltalk and a few others.
[1] They’re in fact both pasta. My joke doesn’t work if I call them pasta though.