Thursday, September 30, 2010

I hate $this and array(...) ! [PHP rant]

$this->


I have no reason to hate the explicit reference to 'self' or 'this' object.

But it shouldn't be repeated everywhere all around the codebase, every single time!

Ruby:

@name = @first_name + ' ' + @last_name

Java:

name = firstName + " " + lastName

PHP:

$this->name = $this->first_name . ' ' . $this->last_name

Unnecessary typing, unnecessary duplication. I should create a shortcut just for typing "$this->"

array(...)


array(2, 3, 5) doesn't look so bad.

But when you're dealing with nested associative arrays (and it's quite common), it doesn't look very good.

$this->_voucher->setOptions(array(         'storeId' => 'voucherStore',         'storeType' => 'dojo.data.ItemFileReadStore',         'storeParams' => array(                 'url' => $router->assemble(array('controller' => 'index',                         'action' => 'vouchers-for-number', 'mobile_number_id' => 1)),                 'clearOnClose' => true),         'dijitParams' => array('searchAttr' => 'title') ));
Ruby and JavaScript nails the sweet spot here. As with Scala (on JVM).

Java (the language) is at least as guilty as PHP on this front and much worse hehehe.

No comments:

Post a Comment