Slide 1

Slide 1 text

Framework×10-6. WTF? Роман Лапин, Evercode Lab @memphys, [email protected]

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Unix philosophy Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface. Doug McIlroy

Slide 4

Slide 4 text

Микро? WTF? • Не full-stack • Нет четкой структуры для проектов • Т.е. делает мало, но достаточно • Single page (обычно) • Less overhead • Extensible

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Микро? WTF? “Micro” does not mean that your whole web application has to fit into a single Python file, although it certainly can. Nor does it mean that Flask is lacking in functionality. The “micro” in microframework means Flask aims to keep the core simple but extensible. http://flask.pocoo.org/docs/foreword/#what-does-micro-mean

Slide 10

Slide 10 text

Микро? WTF? • Routing • Controllers (HTTP Request/Response) • Template Engine (?) • HTTP Caching (?) • Extensibility

Slide 11

Slide 11 text

Микро? WTF? • Routing • Controllers (HTTP Request/Response) • Template Engine (?) • HTTP Caching (?) • Extensibility

Slide 12

Slide 12 text

Микро? WTF? • Какие есть точки входа? • Что надо сделать в каждом действии?

Slide 13

Slide 13 text

Who’s the boss?

Slide 14

Slide 14 text

Для чего? • Прототипы • Почти статичные сайты • API • Адаптация legacy кода

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

$app->match('/admin', function (Request $request) use ($app) { if ('POST' == $request->getMethod()) { return $app->redirect('admin'); } return $app['twig']->render('admin.html.twig', array()); }) ->bind('admin'); Слайд с кодом

Slide 17

Slide 17 text

Подходы • Процедурный стиль • DSL • OOP

Slide 18

Slide 18 text

Передача параметров • Параметры = Аргументы • One $params to rule them all • Контейнер $app

Slide 19

Slide 19 text

Routes • HTTP Methods • Валидация параметров • Названия для роутов

Slide 20

Slide 20 text

$app->match() $app->get() $app->post() ->assert('id', '\d+'); ->bind('route_name'); Слайд с кодом

Slide 21

Slide 21 text

Helpers • Редиректы • Генерация URL • Flash Messages • Log • View (templates)

Slide 22

Slide 22 text

10-6. Good parts • Мозг не лопается • Наглядность • Просто начать • Это весело

Slide 23

Slide 23 text

10-6. Bad parts • Большинство решений на усмотрение • Нет единой структуры (как правило) • Code reuse? • Как вовремя понять, что проект слишком вырос? • Когда выбрасывать прототип?

Slide 24

Slide 24 text

Right tool for the job?

Slide 25

Slide 25 text

Framework×10-6. Ruby • Sinatra (http://www.sinatrarb.com/) • Camping (http://camping.io/) • Cuba (http://cuba.is/)

Slide 26

Slide 26 text

Framework×10-6. Python • Bottle (http://bottlepy.org/) • Flask (http://flask.pocoo.org/) • web.py (http://webpy.org/) • CherryPy (http://www.cherrypy.org/)

Slide 27

Slide 27 text

Framework×10-6. PHP • Silex (http://silex.sensiolabs.org/) • Slim (http://www.slimframework.com/) • FatFree (https://github.com/bcosca/fatfree) • The MicroPHP Manifesto (http:// microphp.org/)

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Happy New Year! Roma Lapin [email protected] @memphys @evercodelab