Unobtrusive Programming - The Art of Clean Coding

Unobtrusive Programming - The Art of Clean Coding

Programming has been around for years and most of our software and mobile apps run huge lines of code needed to enable us do most of the things we enjoy doing such as chatting, blogging, sharing, liking and so much more.

One of the things I came across a while back as a young engineer was the concept of clean coding, which suggested a set of standards that enabled programmers effectively write & communicate code in a way that made it easier for other programmers to understand what the code was doing with or without the help of its author. For full measure, you might want to go through the book titled Clean Code by Robert Cecil Martin, it does a good job of explaining the basic tenets for good programming.

Simply put, if your code needs to be explained to other members of your team in your absence then its obtrusive and getting in the way of relevant team work and seamless delivery. Another definition to this would be, if your code doesn't quite scale well in terms of performance for a large data set, then its most likely going take a longer time to process and would require more CPU power and lead to system slow down and therefore by extension get in the way of other system functions or processes.

Good code should never be obtrusive, it should never hinder or hamper understanding of any kind. It should never bring an organization to its knees because some program or function needed more than is necessary to run effectively.

Here are some examples of what I mean:

Clear & Functional Naming

The following are two javascript functions designed to do the same thing:

function solution(A) {
  let total = 0;
  for(let i=0; i<A.length; i++) {
    total += A[i];
  }
  return total/A.length;
}

Second function (does exactly what the first function does)

function getAverage(integerArray) {
  let total = 0; let average = 0;
  for(let i=0; i<integerArray.length; i++) {
    total += integerArray[i];
  }
  average = total/integerArray.length;
  return average;
}

I'm sure I don't need to tell you which one looks clearly more readable and understandable at a glance. Even though this function is clearly very elementary, it shows how powerful the concept of appropriate naming conventions can be for variables, functions, arrays, classes, objects and so on.

In other words, programming constructs should be named according to their function within the program (very important) and not just ambiguous names like the case of the first function called "Solution". Obviously the first function (Solution) is getting in the way (its obtrusive).

要查看或添加评论,请登录

Chigozie Orunta的更多文章

  • Common Mistakes WP Engineers Make

    Common Mistakes WP Engineers Make

    WordPress is famous for being one of the most popular content management systems (CMS) worldwide, powering millions of…

  • Applying SOLID Principles to WordPress Development

    Applying SOLID Principles to WordPress Development

    SOLID Principles in modern software development refers to the design approach intended in making software code more…

    2 条评论
  • Speed Up Your WordPress Website

    Speed Up Your WordPress Website

    As a website owner, you probably already know how important it is for your site to load fast and efficiently so that…

    1 条评论
  • Creating A Custom Divi Module or Extension Plugin in WordPress

    Creating A Custom Divi Module or Extension Plugin in WordPress

    Divi is one of the most powerful WordPress page builders out there in the market. Its ease of use and WYSIWYG nature…

    4 条评论
  • Building A Custom Gutenberg Block In WordPress

    Building A Custom Gutenberg Block In WordPress

    Gutenberg Blocks in WordPress have been around for a while, ever since the builder was released on the WordPress…

  • Working With WordPress Hooks, How To Create & Use Them.

    Working With WordPress Hooks, How To Create & Use Them.

    WordPress Hooks are one of the most powerful features in theme and plugin development. They enable WP developers to add…

  • Setting Up A PHP CodeSniffer For WordPress using Composer

    Setting Up A PHP CodeSniffer For WordPress using Composer

    A PHP CodeSniffer is a program that helps developers keep code clean and uniform or in sync across teams. In PHP, you…

    2 条评论
  • Most Useful WordPress Plugins in 2022

    Most Useful WordPress Plugins in 2022

    Plugins are an invaluable tool for today’s WordPress websites. There are extremely few websites that exist today that…

    1 条评论
  • Safeguarding Your WordPress Site

    Safeguarding Your WordPress Site

    WordPress accounts for almost 30% of all websites on the Internet and is one of the most popular CMS (Content…

  • 4 Ways To Style Your React Components

    4 Ways To Style Your React Components

    So you’ve built your first React Component but don’t know how to style it. Well, here are 4 quick ways to style your…

    1 条评论

社区洞察

其他会员也浏览了