MNMLSM: Simplify, simplify some more, then start simplifying
Minimalism is an interesting thing – far from meaning as stark as possible, minimalism is the idea of removing anything unnecessary for base level functionality. Imagine a human face. Now remove all of the details you can until it still resembles a human face. If, for example, you took the eyes out and it looks wrong, stick them back in. Once you’ve finished you have minimalism. Buildings, paintings, web design can all implement (and benefit from) minimalism. So can code.
When I started coding for a living I had no idea about loops. The last year of solidly building WordPress sites has taught me a lot. I still start my code the same way I used to code though. I write everything out longhand, then work out the commonalities and parse them as variables, arrays, and loops. Then I start cutting out the duplicated code. Once I have this, I can start working out what I can cut from where to make my code as small and as simple as possible.
Who wants a DRY KISS*?
Every single developer! The reuse of code improves performance, makes updating easier – especially if the project gets passed to someone else when you’re inevitably hit by that bus that everyone goes on about, and benefits consistency across the design.
“Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.”
Everyone knows that deadlines get in the way of perfection and sometimes it’s necessary to chuck something in that works rather than delay everything to produce code that will make other developers moist. This is where Technical Debt comes in. Set aside some time after deployment to tidy up your code. Think of it like throwing all of the stuff from your floor into a wardrobe when your mum visits. Your flat will pass muster for the duration of her visit but, if you don’t go and sort that wardrobe out once she’s gone, you’ll be in for a world of pain later on!
It’s like CSS classes; you wouldn’t apply identical styles to two elements when you could assign the same class to them and only write one bit of CSS, so why do it with your PHP or JavaScript? I start by breaking a build down into independent functions. Then breaking those independent functions down into independent pieces of functionality. This allows me to reuse a function again and again. For example, on one site I built recently, we needed a Netflix-style ‘bookshelf’ that scrolled sideways. This had to start on click of a button or swipe on a touch-screen. It also had to work on several ‘shelves’ independently of each other. By separating the function that made the shelf slide, I could call that one function on each shelf for each method of initiation. This made this one function simple to adjust, easy to replace if a better solution presented itself, and extensible for use on infinite shelves.
Andy Hunt and Dave Thomas originally intended their principle for use in software engineering but it is sound practice for almost all aspects of development. Keeping your code clean, reusable, and – above all – simple, makes for better code and, by extension, better websites.
* Don’t Repeat Yourself and Keep It Simple Stupid