July 30th, 2013 | Tags: , | Category: CodeProject, Software

The rules of minimalist programming

zen-rock-gardenLess is often better. In mathematics, physics, and arts, simplifying and shedding every bit of complexity and redundancy have produced remarkable results. It leads to abstraction, elevates expressiveness, and reveals patterns that are otherwise buried in details.

Programming is no different. For a developer that looks for correctness (does my program behave as expected?), efficiency (does my program use CPU and memory resources appropriately?), and robustness (can I reuse my program or extend it easily for future applications?), minimalism is a sure guideline. The beauty of simplicity translates into better programming.

  1. The less code, the less bugs. Reduce the size of your code with factorization, dead code removal, and the use of standard libraries.
  2. Keep function size small. If it doesn’t fit on your screen, it is probably too complex.
  3. Keep the depth of control structure small. Too many imbricated conditional and loop statements are hard to understand.
  4. Minimize accessibility. Make your variables and functions private or protected whenever possible.
  5. Minimize the lifetime of variables. Use persistent data as the last resort.
  6. Minimize the scope of variables. This makes reading the code simpler. And it helps the compiler to better optimize the code.
  7. Make the API as simple as possible. It helps eliminating redundancy and strengthening semantics.
  8. Use meaningful, standardized names for classes, functions, and variables. Just reading the name of a function should be enough to understand what it does.
  9. Clearly differentiate which data is mutable and which is not in the scope of a function. Use const declaration whenever possible.

Now go and rake your Zen garden.

3 comments to The rules of minimalist programming

  • Maurizio Vitale

    I wish I could rake my zen garden. Unfortunately somebody has grown a mangrove forest of bad code on top of it…

  • Hi Maurizio,

    You can try defoliant or napalm, but that is usually frown upon. Maybe clearing a small area first, where you can lay some gravel on, and build from there. We both know it will be a long journey…

  • Mohamed

    Hi Olivier,

    Very nice rules and philisophy !!

    In my guess, you can practice this only if you are very good artist/programmer … this is a kind of “simplexity” : things may look simple just because complexity was broken but it still needs a deep understanding and ingenius solving to make it simple.

    Thanks for this post ! I will ry to adopt :)

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>