Core S2 Software Solutions

Minimalistic Programming

Older article from Lost in Dev; originally written by Jeremy Bridon.

After reading through Code Complete and Advanced Programming in the UNIX Environment, I started learning how to greatly improve my own coding style. Both of these books never mention “minimalistic programming” by word, but clearly use this style and concept throughout all of their examples. You can try and look online or in books, but you probably won’t be able to find a clear definition of what minimalistic programming is. I offer my own definition:

Minimalistic Programming: A method or approach to generating clear and concise code in the least amount of instructions possible which naturally leads to optimized and readable code.

Well… Isn’t that what we are supposed to do? Our specialization as computer scientists is to write clear, concise and flexible code, yet myself and others rarely will ever have a formal course on the topic in a university. It is unsaid, but such skills are expected to be picked up via experience with class projects, but the problem is those kind of projects are usually far from “production” quality code. I know this is true since I have done over a year and a half of tutoring in several CSE courses and see the quality of other’s code. The reason behind this issue is that our coding style is rarely graded, and usually incorrectly.

From now on, I will be attempting to write minimalistic code in all my projects, and I will go as far as say so should you! The benefits are obvious from the definition, yet the issue is we still haven’t defined how to write such code. Honestly, you can’t! I don’t think you can ever formalize the concept, since it depends so much on the situation, language, libraries, etc. The best method of learning the technique is to read the books mentioned above and try to follow their programming styles.

These are a few points that I have picked up, yet they do not even scratch the surface of what there needs to be learned to be truly proficient in minimalistic programming:

  • Your default case, (such as returning 1 when a user calls a power function with the exponents as 0) should not be a conditional return but the default value for the function-critical variables.
  • Do not have mutliple return points, keep the count as low as possible.
  • Check for possible errors before calling a function, not after. Don’t see if what the sqrt() function returned, check if the given value is within the domain of the function first before calling it.
  • If you can’t read the code after not seeing it for a month, it is probably poorly written.
  • Don’t abuse arrays. Arrays are good for quick memory manipulation or structure representation, but the lack of flexibility may be limiting.
  • Your first attempt should always be your best and closest to the final production code. Save yourself time, do it right the first time.
  • Never have code that is nested too deeply or is tabbed too far. Call a function or use other methods; split code up as reasonably as possible.

A great source of examples of minimalistic code is usually found in UNIX functions such as “ls” or “chmod”. You can find a lot of beauty in their simplicity and eventually catch onto the technique. Write a common function, such as a power or memset function, and see what you can do to make it both efficient and reasonable to understand.

This entry was posted in News & Updates. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

Sites map