My Mistakes on DIO Projects

Submitted by swarut on Thu, 06/21/2012 - 17:04

I've done many mistakes on DIO project which team's seniors have to refactor them. As a reference for learning, and to improve my coding, it would be good if I wrote the mistakes all in one place.

11 - 15 May 2012

-- to be written

14 - 18 May 2012

-- to be written

21 - 25 May 2012

-- to be written

28 May - 1 June 2012

-- to be written

4 - 8 June 2012

-- to be written

11 - 15 June 2012

-- to be written

18 - 22 June 2012

  • Write a spec which is hard to read. Spec should be easy for other to understand. (http://www.swarut.com/node/384)
  • Write the test in the wrong place. For example, testing the model in request spec.
  • Setting default value for the first parameter in method signature while there are two or more paramaters in total. This makes the default value of the first paramater not necessary as if we were forced to pass the second parameter, the value of the first parameter must be explicitly defined.
  • Did not write a comment on top of method implementation. I think it's a good practice to do, but I always forget. Even an easy method should have the comment as other people may not understand the intent of the writer. The comment should consist of the description (describing the method intention), parameter list (name, type and description) and reference (if any).
  • Put method in a wrong place.
  • Not carefully include the helper. The helper methods are, by default, public to be called from every controllers. However, if there were some private methods in the helper and there were needed to be used outside, make sure to put them in the right place.

 

25 - 29 June 2012

  • Remove commented codes.  To fix or update the code, I often uncomment it instead of deletion in order to keep it as reference. However, I often forget to remove it. 
  • Update corresponding code thoroughly. When there is an update, make sure to update all its corresponding code: spec (controller/model/helper/request) and blueprint.
  • DRY js selector. If the selector is going to be refered again, assign it to the variable.
  • Try minimizing the length of if's condition. For example, if you wanted to check for string matching with 2 patterns, instead of creating two matching statement, try combining them into one (using regex). Instead of if(event.location.downcase.match("500hq") || event.location.downcase.match("444 castro st, suite 1200")) This is better if event.location.try(:downcase) =~ /500hq|444 castro/

2 - 6 July 2012

  • Space after hash and braces. Must use it collectly. hash = { key1: value1, key2: value2 }