Wednesday 29 December 2010 5:35:16 am
Hi !
I was thinking about how boolean function/method arguments are currently handled in eZ Publish. Calls to methods with boolean arguments will look like this:
method( $stringArgument, true, false ) When reading this call, without using code tools like code insight, you don't know what true & false are for. Within PHP itself, these days, we see a lot of mask arguments:
$iterator = new FilesystemIterator( $path,
FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO );
While it requires writing more code, I feel like it strongly improves code readability, and actually improves the API itself by allowing more than one value for one option. With the proper API in the framework itself, it would be easy to use these in our code. Any comment ?
Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier
|