Code Smells

Comments == Code Smells ?

In this post, I am doing something different. Above is a link to a great article on ‘Can Comments become Code Smells ?’ by Neal Ford. I would like to know your opinion on it and have a good discussion on the that. To start off, here are my views on the topic.

Continue reading

Advertisements
Link
Code Smell of the Week, Design Patterns

Code Smell of the Week : Broken Encapsulation

Lets take a scenario of a customer placing an order on an ecommerce website. The order may comprise of several products. This order once placed cannot be changed but it will need to be displayed to the customer

public class Order
{
 private List<Product> products;
 //other variables, methods and constructors

 public List getProducts()
 {
  return products;
 }

 public void setProducts(
    List<Products> products)
 {
  this.products=products;
 }
}
//sample usage of Order
displayOrders(orders.getProducts());

However comparing the requirement to the code it is evident that something is wrong.

Continue reading

Standard
Code Smell of the Week, Design Patterns

Code Smell of the Week : Magic Numbers

if(order.getStatus() != 1)
{
 ordersList.add(order);
}
displayOrders(ordersList);

First look at this code tells you that an order with a particular status is not displayed. But what is that particular status ? When is it changed ? Who the hell wrote this ? These are the frustrating questions that pop-up in the programmers head. What follows is a quest to find the creator of the code by navigating the Maze (a.k.a. The Code Repository). The creator may also have ‘moved on’ which leads to further pain.

Continue reading

Standard