Nick Francisco Capstone

CS 462 – Blog Post 1

An article I read about clean code comes from [1]. This article provides several tips and best practices for writing clean code. One tip from the article that I want to work on more often is the efficiency of my code. I can create effective code but I often know that it can be more efficient. The article gives an example of inefficient and efficient code shown in figure 1 below. The efficient code only requires one iteration over the array and has fewer lines of code which helps with its simplicity. Improving my efficiency will not only help my code run faster but can help my code simplicity which will make it easy to understand and follow.

I also have some practices that I want to avoid while coding as an article on code smells from [2] points out. One of these practices that I want to avoid is having code bloat, specifically long functions. In previous coding assignments I would often place all code for one task in one main function instead of creating helper functions that can help reduce the main function. Doing this creates a long and bloated main function that is harder to understand and follow. Creating helper functions to reduce the main function will help me avoid code bloat and can help me improve code readability or simplicity.

// Inefficient Example
function sumArrayInefficient(array) {
let sum = 0;
for (let i = 0; i < array.length; i++) {
sum += array[i];
return sum;

// Efficient example
function sumArrayEfficient(array) {
return array.reduce((a, b) => a + b, 0);

Figure 1 – Inefficient vs Efficient code example


  1. How to Write Clean Code – Tips and Best Practices (Full Handbook). (2023, May 15).
  2. Code Smells. (n.d.). Code Smells.

Print Friendly, PDF & Email






Leave a Reply

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