Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vanilla PHP

Vanilla PHP

How not to let the ready-made solution trees hide the wood of possibilities behind them.

Tomasz Kowalczyk

March 16, 2015
Tweet

More Decks by Tomasz Kowalczyk

Other Decks in Programming

Transcript

  1. Vanilla PHP
    how not to let the solution trees hide the wood of possibilities behind them
    https://www.flickr.com/photos/ted_major/6600956129/
    Tomasz Kowalczyk

    View full-size slide

  2. thunderer@THUNDER$ whoami
    PHP ~2007
    Lead Engineer @ HASH.FM
    GitHub /thunderer
    Twitter @tmmx
    http://mientefuego.deviantart.com/art/Carbon-Glider-129268523

    View full-size slide

  3. Brand new, shiny, greenfield project...
    $ composer create-project symfony/framework-standard-edition NAME
    $ composer create-project zendframework/skeleton-application NAME
    $ composer create-project yiisoft/yii2-app-basic NAME
    $ composer create-project cakephp/app NAME
    // ...
    $ composer create-project laravel/laravel NAME

    View full-size slide

  4. Next steps?
    → scaffolding
    → bundles
    → controllers
    → modules
    → repositories
    → entities
    → views
    → templates
    → configuration
    → services
    → libraries
    → dependencies
    → tests
    → environment
    → forms
    → ...

    View full-size slide

  5. how about some change?

    View full-size slide

  6. NOPE*!
    “one bad programmer can easily create
    two new jobs a year”
    * irony

    View full-size slide

  7. “ if it ain’t broke, don’t fix it ”
    - industry

    View full-size slide

  8. FDD: FRAMEWORK-DRIVEN DESIGN
    → hinders ability to change
    → vendor lock-in
    → domain coupled to framework
    → locks away job opportunities
    → “Rails programmer”-like titles
    → artificial walls between people
    → forced structure
    https://www.flickr.com/photos/binaryape/3625043250

    View full-size slide

  9. how can I change this?

    View full-size slide

  10. look mOm, no framework!
    → Open Source projects “design pattern”
    → semantic versioning
    → modular, elastic and independent code
    → framework as an implementation detail
    → rewrite basic Symfony2 in less than 100 LOC
    → shorter and easier code means less bugs
    → use framework to build only “application” layer
    → code independent from changes in other projects

    View full-size slide

  11. Example project structure:
    ...............
    ................
    .................
    .................
    .................
    ...............
    .................
    .............
    .................
    .................
    .................
    .................
    .................
    .................
    ...............
    .............
    .................
    ...............
    .................
    ..............
    ...........
    ........
    .....
    /project
    /apps
    /web
    /etc
    /src
    /views
    /web
    /console
    /bin
    /cli
    /src
    /etc
    /lib
    /src
    /tests
    /uploads
    /var
    /cache
    /log
    /vendor
    .gitignore
    .travis.yml
    composer.json
    composer.lock
    phpunit.xml.dist
    project directory
    applications directory
    web application
    configuration
    web application source code
    web application views
    front controller
    console application
    application executable
    application executable source code
    console application source code
    project configuration
    domain code
    applications shared code
    unit tests
    user data (images, etc.)
    dynamic application data
    cache directory
    log directory
    dependencies
    dotfiles
    Composer files
    PHPUnit configuration

    View full-size slide

  12. How to rewrite Symfony2:
    $twig = new \Twig_Environment(new \Twig_Loader_Filesystem(array($templatesDir)), array('cache' => $cacheDir));
    $twig->addExtension(new TranslationExtension($this->getTranslator()));
    $twig->addExtension(new FormExtension(new TwigRenderer(new TwigRendererEngine(array('form_div_layout.html.twig')))));
    $assetFactory = new AssetFactory($assetsDir);
    $assetFactory->setAssetManager(new AssetManager());
    $twig->addExtension(new AsseticExtension($assetFactory));
    $loader = new YamlFileLoader(new FileLocator(array($routingDir)));
    $router = new Router($loader, $routingFile, array(), null);
    $session = new Session(new NativeSessionStorage());
    $formFactory = Forms::createFormFactoryBuilder()->addExtension(new CoreExtension())
    ->addExtension(new HttpFoundationExtension())
    ->addExtension(new ValidatorExtension(Validation::createValidator()))
    ->getFormFactory();
    $transport = \Swift_SmtpTransport::newInstance($this->host, $this->port, $this->security)
    ->setUsername($this->user)
    ->setPassword($this->password);
    $mailer = \Swift_Mailer::newInstance($transport);

    View full-size slide

  13. → on your skills
    → on your experience
    → on your approach
    → on your requirements
    → on your company
    → on your process
    → (...)
    of course “it all depends”
    but maybe those are only
    minor excuses?

    View full-size slide

  14. → strong experience or experienced leader required
    → you need to care about structure and quality yourself
    → no ready-made solutions
    → manual implementation of all new ideas
    → you cannot rely on your knowledge of given framework
    → you cannot hire based on some framework knowledge
    of course there are disadvantages

    View full-size slide

  15. askQuestions() or die();

    View full-size slide

  16. good code is not going to write itself...
    so...
    WE’RE HIRING! (YAY!)
    wait for it...

    View full-size slide

  17. Thanks!
    (thanks for all your input!)

    View full-size slide