# Why I prefer static typed language

Yes. It is been a long time.

I am now working on a project which consists of a team from different technical background. Some works on PHP for their whole careers, others, like me, comes from a Java background. Yes I know both of them are boring, bad ... etc. But this is what we get. But basically we can be split into two camp, Static typed camp and dynamic typed camp, or Camp Java and Camp PHP to be simple.

As we are collaborating using CodeIgniter, I notice many, subtle or not, differences in our code while reading codes from different camp. The most prominent difference is the parameter of functions. Here are examples of function declaration from both camp.

Camp Java

public function get_a_list_of_sth($param_a,$param_b, $param_c) { ... } Camp PHP function get_a_list_of_sth($option_array_param) { ... }

So essentially Camp PHP tends to group all the parameter into one array and Camp Java loves to split all parameters to different names. I am more inclined to Camp Java for the most obvious reason - readability.

The camp PHP is of course easier to develop, but the caller will not be able to determine whether what to put as arguments into the function without digging in to the code.

The caller cannot safely call and expect the functions to run as described. Without reading the implementation, caller of the functions have no way to make a successful call of the function without referring to the documentation, if there is any. This brings us to another issue of testing and maintenance. When using PHP or any other dynamic typed language, everyone should check the type of the arguments in the run-time. Take an example of a trivial add function. In a static typed world:

public int add (int x, int y) { ... }

I can heard PHP guys already asking, ‘what about numbers with decimal places?! This is too rigid! We, in one function, can handle both! we will write like this:

function add($x,$y) { ... }

But the world is a cruel world, callers of your functions will come out with strange idea to use your functions. For example,