php hooligans
Embracing the PHP philosophy
A fractal of bad design?
There is no design
no single dictator or design committee
PHP assimilates
and nothing gets thrown away
what some call quirks
- needle haystack or haystack needle -
- to under_score or not -
others may call 'backwards compatibility'
learn to use code completion
P.S.
array function? -> needle haystack
string function? -> haystack needle
design patterns
MVC,factory,singleton,observer,
listener,strategy,decorator,active
record,gateway,proxy,adapter
cute, so you're a hotshot programmer
now what does this
AbstractSingletonProxyFactoryBean
actually do?
keep it simple
don't use design patterns just because you can
don't name your functions after generic design patterns
design patterns are a code smell
we're not programming java here
these are not the types you are looking for
php isn't fuzzy about types
avoid type hints and embrace duck typing
everything is a string
object oriented
it's not what you think
Avoid objects
e.g.
$info = $treeNode->info; $treeNode->cd('..'); $info2 = $treeNode->info;
$info2 = \mylib\tree::cd($treeNode, '..')->info;
AVOID INHERITANCE
embrace composition and encapsulation
use 'final' and 'private'
(some hooligans disagree)
call it dependency injection and you are cool too
large class hierarchies are a code smell
keep it small
when in doubt, leave it out
don't overthink, build what you need now
The best code is no code
keep the php spirit
conform to the language
work with standard types if at all possible
emulate them if not
( toString(), ArrayObject, etc.)
keep the learning curve low
finally: steal
there is a lot of useful code out there
even if you don't like the quality, chances are they fixed problems you haven't found yet
http://phptrends.com/
http://packagist.org/
do check the license though
php hooligans
By Auke van Slooten
php hooligans
- 2,313