CakePHP: Interview with Larry E. Masters

Interesting interview with one of the core members of CakePHP community – Larry E. Masters.

Throughout the interview Larry covers CakePHP Framework history, as well as covering major milestones of CakePHP 3.x version. If you’re still into 2.x – it’s time to upgrade, as it brings some nice perks, more flexible code, and massive performance boost.

 

WP-CLI moves to make.wordpress.org

Great news to the WordPress community and those who spend most of their time in the console. WP-CLI after reaching 1.x stable moves to make.wordpress.org. No more weird sftpd/vsftpd installations, wp-cli gets officially recognized as a community tool for upgrades that might come handy with composer bundle as we do it in Qobo for WordPress project templates.

PHP: Array vs ArrayObject benchmarking

Some measurements on Arrays vs ArrayObjects found among gist users. Just going to bring it here, in case gist dissappears.

# php -v
PHP 5.3.6 (cli) (built: Mar 17 2011 20:58:15)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

# echo '<?php $s = array(); for($x=0;$x<1000;$x++){ $s[] = array("name"=>"Adam","age"=>35); }; echo memory_get_peak_usage(); ' | php
655040

# echo '<?php $s = array(); for($x=0;$x<1000;$x++){ $o = new ArrayObject; $o->name = "Adam";  $o->age = 35;  $s[] = $o;} echo memory_get_peak_usage(); ' | php
887984

# time echo '<?php $s = array(); for($x=0;$x<100000;$x++){ $o = new ArrayObject; $o->name = "Adam";  $o->age = 35;  $s[] = $o;} echo memory_get_peak_usage(); ' | php
61010784
real    0m1.448s
user    0m1.208s
sys     0m0.231s

# time echo '<?php $s = array(); for($x=0;$x<100000;$x++){ $s[] = array("name"=>"Adam","age"=>35); }; echo memory_get_peak_usage(); ' | php
33647944
real    0m0.525s
user    0m0.429s
sys     0m0.092s

We can conclude the following at least in PHP 5.6:

  • Winner for Speed: Arrays are faster than objects (with undefined or defined properties)
  • Winner for Memory: Objects with defined properties use less memory, 50%+ less than objects with undefined properties, only slightly less than Arrays

Ordered Fastest to Slowest in Speed for 100,000 items:

  • 0.107s – Arrays
  • 0.163s – Objects with undefined properties
  • 1.190s – Objects with defined properties

Ordered Least to Most Memory Usage for 1,000 items:

  • ~583kb – Objects with defined properties
  • ~807kb – Arrays
  • ~1.1mb – Objects with undefined properties

PHP functionphobs and doccomment fans

So in PHP functions are basically used in two cases: If the programmer doesn’t yet use OOP or if the script isn’t worth using OOP for. The notion of “helper function” or something like that does not seem to exist…(Reminder: Using classes does not mean your code is object-oriented!)

So true! But what really got me on this article, was this part:

Another tangentially related “standard” practice I feel badly about is the excessive use of doccomments. In most cases phpdoc comments just comment the obvious – at the same increasing the code size by a factor of two or three. I have no problem with doccomments where necessary, but in most cases (at least with well designed code) the behavior should be obvious from the method and parameter names.

Coming from a Perl camp and being a fan of Ruby for few years (still using them here and there), I start catching myself thinking that the world’s been taken over by crazyCamelCaseJavaProgrammers. I do understand that complex projects with huge (no, “huuuuuuuuge!” would be more appropriate here) codebase need concrete descriptive variables, but what happened with readable code? The less readable it becomes the more comments it generates. Sometimes the only expression you get after reading a doc file on the class is “Thanks, Captain Obvious!”. Commenting return statement with “return” comment, or “note: division by zero” and here it comes – division by zero.

I guess that I’m too picky on this one, but by the end of the day remember what this oldie:

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. Code for readability.

Future of PHP and HHVM buzz

  • Input Processing and sanitize (GET/POST/COOKIE)
  • Session Management
  • Database Access without surprises
  • Syntactic sugar for callbacks
  • Template processing
  • XML, HTML, JSON processing

These are stuff that PHP should already have in some kind of fast internal c code, but it simply fails to deliver. Frameworks fill the gap. If HHVM provides substantial better alternatives and people use HHVM then Frameworks will use these extensions.
Framework code is already filled with edge case handling for different PHP Versions, adding a case for HHVM isn’t a problem.

(c) source