Be A Pragmatic Programmer

Be A Pragmatic Programmer

We’ve all heard of the KISS concept, “Keep It Simple, Stupid”, but how exactly does this apply to development? Is it possible to write and maintain a large, complex codebase without losing sight of simplicity? Programming JavaScript Applications author Eric Elliott believes so.

Image: Nat Welch / Flickr, licensed under Creative Commons 2.0

In a post on JavaScript Scene, Elliott explains how he put the call out over Twitter, asking developers the following question:

He received from good responses, though this was the one he agreed with the most:

Elliott then goes on to look deeper at the concept of “simple code”, which isn’t as straightforward as it appears. Anyone can write a single-purpose function or separate concerns between classes, but as your project increases in size and scale, it can be tempting to take shortcuts or bend a few rules that keep complexity in check:

What is Simple Code?
Simple, from the latin simplus, originally referred to a medicine made from one constituent, especially from one plant. The meaning I refer to here is “not complex or compound; single.” Simple vs complex can be summed up concisely: one thing vs many things.

The author then goes through functions, classes and other programming concepts and provides point-form rules to apply to their implementation. For example, when it comes to functions:

Functions which have no side-effects and exhibit referential transparency are called pure functions. A pure function:

  • Given the same input, will always return the same output.
  • Produces no side effects.
  • Relies on no external state.

While Elliott’s post features JavaScript-specific examples and content, the principles he talks about can be applied to any language.

The Single Biggest Mistake Programmers Make Every Day [JavaScript Scene]