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 Slide

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

    View Slide

  3. View Slide

  4. 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 Slide

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

    View Slide

  6. how about some change?

    View Slide

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

    View Slide

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

    View Slide

  9. 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 Slide

  10. how can I change this?

    View Slide

  11. components

    View Slide

  12. 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 Slide

  13. 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 Slide

  14. 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 Slide

  15. → 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 Slide

  16. → 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 Slide

  17. COOL STORY

    View Slide

  18. askQuestions() or die();

    View Slide

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

    View Slide

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

    View Slide