Talks

Viewing Ruby Blossom

EuRuKo 2016

00:00:04.640 so our next speaker comes from Moscow
00:00:08.250 he's an indie developer
00:00:09.680 and hanami and sidekick contributor so
00:00:13.710 welcome onstage Anton davydov
00:00:21.829 announcement it's my first English talk
00:00:23.880 in my life and that's why I'm really
00:00:26.309 nervous about it
00:00:28.340 anyway hello Erika
00:00:31.070 it's my first year occur and I'm first
00:00:33.570 time in Sofia and I'm happy to be here
00:00:36.840 with you I meet so many amazing people
00:00:39.930 and you are so awesome thank you my name
00:00:43.980 is Anton I love stickers and open-source
00:00:48.200 sidekick and Konami committer also my
00:00:51.390 commits you can find in some projects
00:00:53.550 like Ruby rails crystal and etc and also
00:00:56.880 I have a social activity I am an
00:01:01.620 organizer of
00:01:03.019 Moscow Ruby user group and also I have a
00:01:07.170 Twitter account for russian-speaking
00:01:09.479 developers it's through be understood
00:01:11.130 it's Twitter account about Ruby and it
00:01:14.610 looks like
00:01:16.460 looks like ask me anything on the read
00:01:19.590 on the reddit so in japanese language
00:01:23.970 you can find really interesting called
00:01:25.860 it's called hanami and its mean watching
00:01:29.250 the flora Blom of course the most
00:01:32.940 popular flower is Sakura but other
00:01:36.090 flowers such as tuples are watch it as
00:01:39.960 well I found this illustration about
00:01:43.409 this process and of course today we will
00:01:46.380 talk about rubia and not about flowers
00:01:50.119 today we will talk about
00:01:53.330 today we will talk about saruba velak
00:01:55.710 work which called hanami this framework
00:01:58.740 was created by developer from Italy his
00:02:03.000 name is Luca
00:02:04.340 the first commit was created three years
00:02:07.140 ago and as you can see it's a very young
00:02:09.810 framework
00:02:11.090 code team can consist of two people
00:02:15.069 Luca and I think we need to start
00:02:18.159 talking about general idea of this
00:02:20.230 framework so let's talk about it first
00:02:23.140 ideas module Eretria it's enabled to
00:02:25.930 switch any parts of your view framework
00:02:28.989 for example if you want to use active
00:02:31.599 record or maybe Rome instead of Konami
00:02:33.609 model you can do it without any problems
00:02:36.480 and you can drop some parts of framework
00:02:40.150 and it's so easily to the next idea is
00:02:43.750 simplicity I think simple to provide
00:02:48.400 provide
00:02:50.010 the faster way to create production
00:02:52.900 applications and
00:02:54.480 framework it's just a tool and don't
00:02:57.040 make a coat of it
00:02:58.709 few conventions if you're using if you
00:03:02.409 if you are going to use Konami or you
00:03:05.079 again more freedom and you don't need to
00:03:09.010 think where or how you can mix your
00:03:12.239 business conventionals and framework
00:03:14.859 conventionals together
00:03:17.159 poor objects pull objects yes I think
00:03:20.680 it's clear for everyone there zero
00:03:24.940 monkey-patching why it's so important
00:03:27.669 for this framework
00:03:30.030 if you want to understand this this try
00:03:33.639 to pass the squeeze it squeeze about
00:03:36.180 where some methods was defined in Ruby
00:03:39.519 or in a rails for example you can see
00:03:42.090 duplicate method and you need to try to
00:03:46.180 understand whereas this mattress was
00:03:47.709 defined so in the last idea it's a
00:03:50.799 thread safe we all concurrency program
00:03:53.109 or we are web servers and this why so
00:03:55.900 important I
00:03:57.389 have really important not please notice
00:04:01.569 this hanami is Naturals hanami is
00:04:04.689 natural skiller
00:04:06.269 it's a different framework which used
00:04:09.790 the MVC pattern and
00:04:12.150 compassion of these frameworks it's a
00:04:14.620 really stupid idea but of course we will
00:04:16.930 compare it later so
00:04:21.870 any web application consists of two
00:04:25.510 different parts of logic first part it's
00:04:28.810 business logic it's your module database
00:04:31.419 and maybe some calculation or something
00:04:34.330 else and second parts it's data flow on
00:04:37.330 data flow term I mean any logic about
00:04:41.289 getting requests parts exists call some
00:04:45.099 business logic and responses request to
00:04:47.770 user
00:04:49.409 so let's talk about data flow
00:04:53.909 so I forgot Konami
00:04:58.110 splitted the logic by different paths
00:05:01.379 and let's talk about that the flow
00:05:06.210 refreshing your memory of what great
00:05:08.229 people are recommended as a recommended
00:05:10.889 monolith first strategy and Konami has a
00:05:14.800 really nice and very simple HEVC have a
00:05:17.800 simple way to create manolito manolito
00:05:19.979 applications it's called application of
00:05:23.740 heat actually and it looked like this
00:05:26.520 when you generate new Konami application
00:05:29.560 it will have application folder and this
00:05:32.349 folder contains some files all these
00:05:34.479 files you can split on three different
00:05:36.310 groups first group which configuration
00:05:38.469 file it's only one configuration file a
00:05:40.990 second group it's routing and
00:05:43.479 controllers and the last part it's about
00:05:47.279 view paths I mean it's view object and
00:05:50.440 plates and assets so of course we are
00:05:54.460 all modern guys we use solid principles
00:05:56.889 in our works and we want to put we want
00:06:01.810 to split our log into separate
00:06:04.210 applications for example we can put
00:06:07.150 admin logic to different place instead
00:06:10.960 of web or maybe just on logic and
00:06:14.250 Konami have Konami has a simple solution
00:06:18.279 for this to the solution colored are
00:06:20.969 continuous actually and it's look like
00:06:23.139 back with X where each X is the
00:06:26.409 application and it's look like this as
00:06:28.750 you can see can utter
00:06:30.500 after generation the application Konami
00:06:32.720 creates two folders first folder it's
00:06:35.990 admin folder and this folder includes
00:06:38.690 all parts from our application
00:06:41.150 architecture and second folder in my
00:06:43.550 example is to a part
00:06:45.640 so let's talk about business logic
00:06:48.280 Konami use a library folder for all your
00:06:51.350 business logic and this fault it's this
00:06:54.560 folder consists of two different parts
00:06:56.900 to first parts its configuration and
00:06:59.630 mappings
00:07:01.360 second part its model Konami realized
00:07:06.160 repository pattern and that's why we
00:07:08.600 have repository folder and entity folder
00:07:11.110 and second part it's library in my
00:07:14.960 example I use library for the mailer but
00:07:17.690 you can use you can put any stuff on
00:07:20.810 this vault here so I told the Konami
00:07:25.190 it's model of a framework and
00:07:27.880 let's look to all parts of Konami
00:07:32.020 so if you open github github repository
00:07:36.919 with Konami organization you'll see ten
00:07:39.440 different games first five games it's
00:07:41.930 Konami it's a place again which
00:07:45.490 generates some file and provide common
00:07:47.990 line interface it's a router this game
00:07:50.840 needs only for mapping hue path and
00:07:53.690 controllers it's controller you choose
00:07:56.330 it's like active support in rails and
00:07:59.900 model and second five it's a validation
00:08:02.180 helper view assassin mailer
00:08:04.570 so let's talk about difference I know
00:08:08.450 that this all look strange for you but
00:08:13.100 after this part of my speech you'll
00:08:15.260 understand that Konami it's nice
00:08:17.140 framework so one person says that talk
00:08:23.120 is cheap and I have a short about
00:08:26.450 obviously squad
00:08:28.510 so and this why on the next my slides
00:08:32.180 I'll show file display only code samples
00:08:34.400 our first code sample it's typical great
00:08:37.520 application as this application so it's
00:08:40.820 a simple class with only one
00:08:43.580 public method it's a call method and
00:08:46.010 this method returns array of three
00:08:48.470 elements
00:08:50.200 so Konami can use
00:08:53.830 class read class and MA and maps this
00:08:58.430 class to some pros you can see that I
00:09:02.060 create a simple instance of Konami
00:09:04.430 router and after that I am mapping this
00:09:06.950 road on get request on the root folder
00:09:10.899 so next example is Sinatra application
00:09:13.640 it's clear to I think and hanami I have
00:09:18.350 block notation you can write like
00:09:22.579 Sinatra like applications to so it's a
00:09:26.810 logical to compare rail section and
00:09:28.940 Konami action and I have a good example
00:09:31.250 of typical race action
00:09:34.070 relax I'm kidding I told I told about it
00:09:39.920 real estate Konami it's a really
00:09:42.050 different frameworks as they realized
00:09:44.959 MVC pattern but the principles and ideas
00:09:48.860 is different and that's why I think it
00:09:51.380 will be good to take each part of MVC
00:09:54.320 pattern and
00:09:55.540 display how Konami and rails realized it
00:09:58.899 so first part its controller
00:10:02.170 in typical rest control controller looks
00:10:05.600 like this it's class with some methods
00:10:09.520 method method can be can have any names
00:10:13.730 and I think it's clear
00:10:16.600 controllers in DHH cell it's a class to
00:10:19.550 but but you can put only rest actions
00:10:25.700 into this class into this controller I
00:10:28.490 mean so our Konami have a different way
00:10:31.310 you can see that it nons its life you
00:10:34.520 can see a typical Konami action this
00:10:37.699 action is a simple class with only one
00:10:40.730 our public method is method call it
00:10:43.279 looked like a typical application but
00:10:46.100 it's not a typical direct application so
00:10:50.410 and it's look like a typical service
00:10:52.880 object for example the next part its
00:10:55.339 model
00:10:56.330 so in or else if you remember we have
00:10:59.870 active record an active record realized
00:11:03.020 put all validation database data logic
00:11:06.140 data and a cessation logic into the
00:11:09.050 model and of course you can put some
00:11:11.030 authorization logic some search logic
00:11:13.130 and etcetera etcetera etcetera of course
00:11:15.890 we can use roam
00:11:17.320 but sometimes Rome is so complicated for
00:11:21.470 for us because we need to realize
00:11:24.500 adapters common mappers and other stuff
00:11:27.140 myself
00:11:28.990 Konami is a cross between rels and Rome
00:11:32.120 I told that Konami realized repository
00:11:36.260 pattern and
00:11:38.110 on this slide you can see entity it's
00:11:41.540 like that object like we've dos or maybe
00:11:44.780 dry types and this class works only with
00:11:48.980 data if you want to work with your
00:11:51.680 database you need to use a repository
00:11:53.960 object typically passes the objects
00:11:57.320 works with database and if you need to
00:12:00.050 create update maybe select some data you
00:12:02.810 need to use this class so
00:12:07.630 support support functionality I have
00:12:10.880 only one slide
00:12:12.160 you can see a simple ice method and how
00:12:16.610 this method
00:12:17.680 realized in rails and Konami you can see
00:12:21.200 that or else use monkey-patching and in
00:12:25.160 konami we creates different class only a
00:12:28.580 different string class and use only this
00:12:31.160 class for our
00:12:32.710 helper methods so let's talk about view
00:12:37.630 in also have template view in in this
00:12:42.320 folder we have partials and also we have
00:12:45.650 our else helper it's a model and in this
00:12:49.160 model you can call your view logic also
00:12:51.980 we initialize instance variables in our
00:12:56.030 controllers and causes variables into
00:12:59.960 some place
00:13:01.930 in hanami
00:13:04.000 in hanami we have
00:13:06.830 you object it's a poor Ruby class I
00:13:09.290 which provide a simple way to use view
00:13:12.260 or view logic and also we have templates
00:13:14.930 if you want to
00:13:17.260 use some data from your action you can
00:13:20.180 create a simple gutter in this action
00:13:22.820 and use this Gator instead of instance
00:13:25.910 variable so last operation is ourselves
00:13:30.760 unfortunately I don't like this part and
00:13:33.530 that's why I'll leave it as it lets you
00:13:36.530 for independent review sorry
00:13:40.460 so let's talk about proxy and cons the
00:13:44.210 first Brooks of Konami it's no magic
00:13:46.460 really let's look on this code sample
00:13:50.990 it's a real quote from my application
00:13:53.150 it's a test of action and on this sample
00:13:56.720 you can see that I initialize simple
00:13:59.930 Ruby object without anything and after
00:14:03.260 that I call this object and get simple
00:14:06.260 array of data and as you can see we
00:14:10.100 don't use some strange and magical
00:14:12.650 method like both get and etc
00:14:16.540 another example of magic it's questions
00:14:20.480 like this on this stack overflow
00:14:23.570 question some person tried to use week's
00:14:26.720 method in simple Sinatra application and
00:14:30.020 you don't understand what's happened and
00:14:32.090 why this method not work and that's why
00:14:35.510 I think that we need to see the
00:14:38.210 difference between language and
00:14:39.730 framework so other procs it's best
00:14:44.870 practice I hope that great tool doesn't
00:14:48.080 not just work correctly great to teach
00:14:50.720 developers a good practice and Konami is
00:14:54.440 great too because
00:14:55.990 Konami teach you some practice like
00:14:59.210 modularity
00:15:00.700 logic separation and TDD so this
00:15:05.300 framework used for test first princip's
00:15:07.790 and Konami applications have a really
00:15:10.310 nice tasting high pay
00:15:13.060 so
00:15:15.330 but of course I'm sorry I forgot that to
00:15:18.000 deduce that
00:15:19.070 so let's talk about cones first course
00:15:22.890 is to do it's a note economic problem
00:15:25.110 it's usually it's a problem of TDD maybe
00:15:28.020 but sometimes you write too many
00:15:30.810 unnecessary tests in your application
00:15:33.330 for example you can try to write tests
00:15:36.420 for your viewed object and in this view
00:15:38.610 object you generate HTML of your form
00:15:42.750 and you try to test it and sometimes
00:15:45.300 it's located
00:15:46.910 so next con is same type of code
00:15:51.800 so sometimes this framework is verbose
00:15:54.570 really for example try to create simple
00:15:57.810 admin application only with screwed
00:16:00.290 actions and try to do it for maybe 5
00:16:04.560 modules and after that you understand
00:16:07.020 what I mean
00:16:07.970 and
00:16:09.560 other course is not stable version now
00:16:12.900 canonical version 0.8
00:16:15.680 and I remember finding time when linked
00:16:21.240 to helper doesn't for correctly in some
00:16:23.250 cases of course now it's a fixed but
00:16:27.020 anyway and also maybe you remember that
00:16:30.960 this game was this framework was renamed
00:16:33.210 from Lotus to Konami
00:16:35.720 so it's a problem of all new frameworks
00:16:41.190 we haven't
00:16:42.920 some useful games for
00:16:46.940 working for example for working with
00:16:49.410 some
00:16:50.480 cases and just I think rails is 10 years
00:16:54.870 old framework Sinatra is 8 year old and
00:16:58.970 that's why that's why I think it's one
00:17:02.940 of the reason why some useful games are
00:17:05.580 missing
00:17:06.410 and the last cons it's if you are a
00:17:10.380 modern boy you want and want to work
00:17:12.930 with all of this stuff like WebSockets
00:17:15.870 or react I have a bad news for you
00:17:18.990 Konami doesn't support all of this and
00:17:21.110 but of course you can try to realize all
00:17:24.240 this stuff but I think it should look
00:17:26.940 like this
00:17:30.080 so
00:17:32.270 we all love benchmarks also I know that
00:17:35.430 benchmarks is falsification and
00:17:38.570 I think everybody likes charts and each
00:17:42.420 mark that's why let's show on some
00:17:44.820 charts for benchmarks I used Puma I used
00:17:49.230 Puma server with 4 threads and
00:17:52.490 thought for for testing kyu's where
00:17:56.700 carve is this case and also you can find
00:17:59.100 it's a github repository link you can
00:18:02.130 open this or show all examples and try
00:18:05.340 it on your machine
00:18:07.010 so my first benchmark was about rack and
00:18:11.610 Konami of course record - of course rec
00:18:15.240 is faster than hanami because us because
00:18:18.180 hanami it's a wrapper on red and for
00:18:21.780 this benchmark I use at Konami shelters
00:18:23.730 I'm sorry honey routing only
00:18:27.200 so negative mark it's about Sinatra
00:18:30.750 grape and Konami I create a simple JSON
00:18:33.870 application which returns only one
00:18:36.920 simple JSON and this application has
00:18:40.440 only one action
00:18:42.020 for this example I use it Konami roads
00:18:45.570 with Konami controller and you can see
00:18:49.050 results here and the next it's more
00:18:51.690 interesting example it's real solution
00:18:56.090 42.6 and Konami version
00:18:59.150 0.8 I
00:19:01.520 absolutely empty two different
00:19:03.990 application one for hanami one for rails
00:19:06.600 after that I put I
00:19:10.730 made two actions for each application
00:19:13.740 one action a returns template and second
00:19:17.340 returns JSON and after that I use work
00:19:20.910 out for my benchmark and you can see
00:19:23.340 results here
00:19:25.010 so last part of my talk it's about
00:19:29.420 James I told the Konami it's very young
00:19:32.990 framework that's why sometimes we're
00:19:35.390 missing something for example but in
00:19:37.190 other way we have a really interesting
00:19:39.860 solution for other problems for example
00:19:42.650 I try to
00:19:44.260 integrate rod I with game this Konami
00:19:47.210 and it looks a little nice
00:19:49.480 you can use this awesome side and it's
00:19:54.530 awesome side for hanami on this side you
00:19:57.530 can find some interesting games
00:19:59.650 interesting and good posts and if you
00:20:03.710 want you can contribute to this side too
00:20:05.570 so it's a contact it's main site it's a
00:20:09.770 chat where you can ask anything and this
00:20:12.710 is a forum last link it's a forum on
00:20:15.140 this forum you can find really
00:20:17.000 interesting threads
00:20:18.490 so this is the end so thank you so much
00:20:22.000 if you have any questions you can or you
00:20:25.160 can catch me after my talk
00:20:42.600 you