Search This Blog

Loading...

Saturday, March 28, 2009

I hate dynamic language

OK, this is a rant. No flame intentioned. But dynamic language rubs me in the wrong way and I have to complain about it.

Tell me what's wrong with the following code:

$client = new SoapClient($wsdl); 
$dwer= $client->login(array('userid'=>$usrname, 'password'=>$pass)); 
$param = array('sessionId'=>$sessionId, 'caseId'=>$caseId, 'delIndex'=>$delIndex);
$result = $client->derivateCase($params);

I spent an hour trying to debug this code. It turned out that I misspelled $params-- it should be $param ( with no s at the back).

I wouldn't get this if I were using a static type language.

5 comments:

Anonymous said...

In PHP years ago (is this PHP? I'm not even 100% sure) I could stay sane by enabling output of all errors, including read access to unused variables (E_ALL I think). That helps a lot. So this is probably more a configuration problem than one of dynamic languages imo.

JeffWaltzer said...

Do you have unit tests for your code? Static typing isn't very important if you have good unit tests.

Soon Hui said...

Hi Jeff, I am struggling with unit testing in PHP ( ironic considering that I am a fierce proponent of unit testing in this very blog).

And yes, I have already set the error_reporting flag to E_ALL in my PHP.ini file.

Alexey Zakhlestin said...

In this exact case, PHP allows you to add type-hint, which wouldsolve your issue.

Just define method as following:

public function derivateCase(array $params)

j4kp07 said...

sometimes 'error_reporting(E_ALL);' comes in handy. it would have reported that '$params' did not exist.