Friday, August 26, 2011 

Detecting php duplicate and unused code.

One of the project that I had to work on recently was huge and written over by developers who were working intermittently on it with very short deadlines. Hence the code had duplicate code, dead functions which were never used. It needed re-factoring badly. 

I found the below tool which helped us a lot in identifying duplicate and dead code. 

phpcpd - for identifying and detecting duplicate code. (php copy paste detector)
phpdcd for identifying and detecting dead code. (php dead code detector)

Wednesday, August 17, 2011 

javascript functions.

Every function in javascript has:
- this (the current object on which it is using  - if no object is used and the function is just called like that it uses window object as this)
- scope (all the variables that are defined with in the scope of this function and its parents are accessible via this scope).
- Functions have lexical scope, ie scope is defined when the function is defined. As soon as the function is called, this scope is used to assign the latest values to the variables used in the function. This is how closures work.