00:00:05.420
so for our last talk he's the creator of trail brain brazier
00:00:13.340
that's correct Trailbreaker a
00:00:18.580
high-level weber she textured solution for ruby apps
00:00:25.660
you are not the only one that wants to sleep he also wrote a book about it on
00:00:31.519
lean PAP you might have noticed him yesterday
00:00:36.950
being the soul of the party he's the least German German I've ever known and
00:00:42.079
I've been living in Germany for two years now three years yeah Munich
00:00:47.559
so yeah it's Munich you know there's a lot of Bavarians there so please welcome
00:00:54.980
on stage mr. Nick Souta three years come on
00:01:09.220
better
00:01:15.009
it's always big pleasure - and a two-day conference
00:01:22.640
and to sit all day in a dark corner trying to cure your hangover because the
00:01:31.060
after-party is on the first night and not on the second night
00:01:36.430
actually I think this is a bad excuse from the organisers
00:01:41.780
so they told me everyone is leaving today who is leaving today
00:01:48.009
it's like five people okay I'm sorry I mean I'm happy so you
00:01:55.060
could actually party last night and I think you partied hard because you didn't have to give their closing
00:02:00.520
presentation on the second day and so on and so on and so on but I also hear rumors about and you know official after
00:02:08.860
party tonight so maybe you want to rebook your flight and stay for a couple
00:02:13.959
of more days hey Rafael take a seat okay to
00:02:20.100
make this to make this might be confusion my name is actually
00:02:26.680
not are my name is Nick I'm also not from
00:02:32.730
Bulgaria I'm from Germany this does not mean I cannot drink as much luck here as
00:02:39.580
you guys can drink so I'm it's a it's a bit said he this lovely guy actually I
00:02:45.940
never know how to pronounce his name I love him to the bottom of my heart we've been partying at many conferences and
00:02:52.540
having deep and profound debates poor Tschida is that her because if you
00:02:58.120
know someone for like a couple of years and it's summer you say like hey it was nice the last three years with you but how do I actually pronounce your name
00:03:04.570
it's a bit awkward so anyway he's um usually a party animal and I'm nothing
00:03:10.390
compared to him he parties like like like a maniac unfortunately he is a bit sick today
00:03:18.230
oh also yesterday he is I think he's in hospital it's like not the coolest thing
00:03:25.459
to do on the weekend but on the other hand it's a cool story like I said hey how was Friday Oh
00:03:30.970
appendix or surgery nothing special cool okay so I think we should send him some
00:03:37.879
message and like maybe we can all yeah all yell into the camera I don't know
00:03:43.459
something like we miss you or something that's
00:03:48.860
I'll count to three and we all yell this yeah so you can also wake up again so
00:03:53.930
one two three uh we miss you ma ma ma
00:04:08.530
we don't have time for applause I have so much content and only 40 minutes
00:04:13.600
so when I when I when I when I wrote this presentation 17 years ago I
00:04:20.799
titled it the end of rails question mark very controversial aggressive title
00:04:27.860
people said hey man dick you're such an you're always talking about rails and you really like aggressive and
00:04:34.070
you're not contributing enough to be so like weird and
00:04:40.000
so yeah I agreed I am a little bit of an ass so I am renamed it to the illusion
00:04:47.660
of stable api's and the great thing about this is I this
00:04:57.230
could be anything this talk and it is some random stuff and but the problem
00:05:02.510
was people started asked me so actually what's your talk about and like it's a cool title but what is it about and I
00:05:10.570
could not I did not manage to summarize my talk without saying rails and something- so I
00:05:19.400
decided to completely rewrite my talk talking about the real stuff now
00:05:26.080
also I want to be functional functional hipster just giving you a little bit Joe sorry so and what I learn about
00:05:32.330
them rakia is it's a pretty strong it's good to heal and inflammations it makes
00:05:39.140
people tweet weird photos in the weirdest hours of the day with
00:05:44.660
toothbrushes not with cats it's a bit different and it does not make you blind
00:05:49.729
that's a rumor that's not true right Raphael can you still see me yeah
00:05:55.340
yeah yeah and what's also awesome awesome
00:06:02.000
about him rakia is you I don't know I I don't get hangover from it so I could
00:06:07.130
actually manage to party yesterday on the first night of the conference by the way not the second before I give my
00:06:13.700
closing talk and so on and I could actually I managed to go and see the first talk I mean I I woke up at like
00:06:21.670
9:00 or something and managed to take a selfies to prove you that I was in just
00:06:26.770
as amazing elixir talk every time I hear just so you talk about elixir I want to
00:06:33.430
stop using Ruby and start using elixir but now this is really conference okay enough
00:06:40.380
let's talk about AP ice many people in this room I not exactly think
00:06:47.650
that I'm gonna talk about document api's yeah how cool JSON documents and yeah
00:06:53.590
and rails API and activemodel so you realize absolutely no I'm going to talk
00:07:00.010
about AP ice as in what we use as programmers yeah as a programmer you use
00:07:05.770
api's on a daily basis you create ap is when you write code okay so I'm not
00:07:12.310
going to talk about awesome JSON documents I'm gonna talk about and stuff like
00:07:18.270
constants can be part of an API or methods can be part of an API and the
00:07:23.650
signature of are you applauding me that's really nice and the the signature
00:07:29.710
of the method arguments is part of the API on API can also be the structure of
00:07:35.560
objects of functions and the workflows you use so that's all parts of an of an API and the cool thing about ap ice is
00:07:43.090
that they make my life your life not clapping anymore and all of your lives
00:07:50.100
excellent because we can use stuff other people wrote or we can write stuff for
00:07:55.870
other people and we don't have to really understand what some what's happening inside it's pretty cool
00:08:02.230
like you you just I don't know like it's a bit like the power plaque you have like you know internally it looks like
00:08:08.169
this I have no idea I mean I had physics in school and I don't know there's like voltage and something else and something
00:08:14.800
kills you and something does not kill you and on so on it's it doesn't matter I just use my power plug plug it into
00:08:21.100
the socket then I have power and can recharge my iphone that I not have and
00:08:27.780
so what API is basically offer us are it's an abstraction
00:08:33.029
extracts away internal knowledge you need or you maybe you don't even have
00:08:39.219
from your task so api's are attractions that help programmers and people who
00:08:46.180
need to charge their iPhone because you have to charge our phones five times a day apparently and you don't need to
00:08:52.120
have knowledge about the internals and the cool thing about api's is they help
00:08:58.330
but what's even cooler is when people start to extend api's and realize hey
00:09:03.750
this is kind of cool what I'm what I've done but actually I would love to add
00:09:09.300
functionality on top of that for example it's a stupid example of it it's like
00:09:14.380
this is my talk so there's lots of stupid examples and a login form is kind of an abstraction for authentication
00:09:20.740
yeah you authenticate yourself this is my username this is my password and at some point people said I
00:09:26.760
had too much rakia in my life I always forget my password so let's allow
00:09:32.110
logging in with Facebook or github because every person on this planet has github apparently and so people started
00:09:39.790
to add buttons to log in false way just say lock me in as my github whatever
00:09:45.220
handle and then you don't have to remember your password so an excellent example of how api's can be extended
00:09:51.970
when it makes sense to extend them yeah so an API doesn't mean it has to stay
00:09:57.520
like that for the rest of the of the time of this piece of software and it ap is are meant to be changed when it makes
00:10:05.080
sense this is my favorite part of the talking
00:10:11.370
Ruby on Rails so and API scum in gems an API is come
00:10:19.450
in form of Ruby Ruby internals and all this kind of
00:10:24.730
stuff API also come in form of for example the rails framework yes now you have to say oh no it's he's
00:10:32.440
gonna talk about res no not again so rails has this has a lot of like peppers
00:10:38.410
and you know the way active record works and all this kind of stuff but one part of rails API is the so called they call
00:10:44.920
it MVC yeah so the MVC pattern is basically the architectural abstraction
00:10:53.230
to help you write web applications and it's a bit like I don't know really how it's supposed to work like the
00:10:59.410
controller now is about the view and the view who gets rendered by the controller and the model can be presented via the
00:11:06.280
controller to the view and all this kind of stuff and and in in rails late they make it like super sweet like I mean
00:11:13.060
look
00:11:24.970
simple and okay it's so easy to write applications because you have
00:11:31.050
and it's really only a few steps to to to get
00:11:37.200
application running so that's this is like a typical flowchart you don't have to understand it and so it's like you
00:11:43.180
the controller assigned some variables that it gets from the model layer from the suite active record with glasses and
00:11:49.960
then it sends those data that data to the view and so on and so and so on and
00:11:55.170
again it's really like tiny and sweet and it works it's great it's fantastic
00:12:01.450
people can learn how to write applications within I would say
00:12:07.020
10 minutes yeah so you can I've done I've given a lot of lectures at rail
00:12:13.540
skills and it's fascinating to see people who have never written any code write a dynamic page in literally like
00:12:22.780
an hour but the problem is that
00:12:27.870
we have this MVC parent and we think it is perfect stop stop reading this
00:12:34.350
because we have the so called rails doctrine written by DHH himself a
00:12:40.900
fantastic guy the register train basically says MVC the way we do it or
00:12:46.990
else and you all do MVC because we have a doctrine is the way we write software
00:12:52.620
ok our abstractions our API is perfect and we write applications using
00:12:59.840
we see because the doctrine nope and some people disagree including me if you
00:13:07.280
couldn't tell and yeah for example there's a mic program
00:13:13.930
where he basically figures out okay some ruie developers don't even realize they
00:13:19.430
are writing Ruby they think they're writing rails and it takes a couple of years for them to realize rails is only
00:13:24.800
Ruby because because rails the doctrine make it really makes it really hard to
00:13:30.590
understand where are my where are the boundaries of the language to the framework and
00:13:35.890
are there many are there may be more layers I could use in my application instead of MVC only so
00:13:43.450
because the problem is that we all use this beautiful MVC pattern and we end up
00:13:49.220
with really really really convoluted code I
00:13:54.430
don't want to say messy because messy would be negative and then in the end of the talk everyone will say you are so
00:13:59.810
negative so we have what is this this is a view for examples of the views in rails if
00:14:05.360
you use the standard embrace tree you will have really big views with like a lots of authentication authorization
00:14:12.020
logic helpers rendering ten partials in a row passing down locals using instance
00:14:18.980
variables from the controller that you might change on the way and this kind of stuff so it's super hard to write
00:14:24.140
complex applications and complex views in in rails and the same is with what's
00:14:30.020
that that's a controller the same happens in the controller because we only have MVC so you have authentication
00:14:36.380
logic or authorization polymorphic dispatchers you use the
00:14:42.020
persistence layer in every different position of this of this code and you pass stuff you
00:14:50.450
change the incoming parameters you validate stuff you trigger callbacks but you it's like it's super hard to follow
00:14:57.350
what a rails developer actually does in a rails in a controller action and the
00:15:03.200
same in the model I mean it's like some people might think yeah you're a bad
00:15:08.480
programmer you you don't know how to program and it's true I have no idea how to program but there is lots of smart people out there
00:15:15.660
and they still run into this problem like we have massive models and then you know again there is like state machines
00:15:22.080
and validations and callback logic and colleagues getting triggered when you don't want them and validations being
00:15:27.150
run when you don't want them running this kind of stuff and this is not the
00:15:32.310
problem of because we are stupid I mean I'm stupid but you're not and so it in what I'm trying to say is if
00:15:41.390
you realize my abstractions are not enough anymore you have to change your
00:15:49.890
abstractions yeah your API is this is the job of a good software developer and
00:15:56.300
I do not understand why rails is so slow
00:16:02.910
in accepting that its obsession with MVC is
00:16:07.970
taking us into the wrong direction in my opinion if you like massive controllers
00:16:13.380
massive views and massive models okay and so I want to show you an example why why
00:16:22.320
this is hard to deal with and how you can easily easily change this with
00:16:28.890
additional abstraction layers okay so we all love active record I actually love
00:16:34.260
active record without certain features who does not like active record
00:16:42.020
doctrine so a typical thing to do is you have user
00:16:49.290
model and you have validations like my the name can be only twenty characters the email has to be email format H has
00:16:55.800
to be numerical so when I use user to create and a pass in some rubbish Stata
00:17:01.140
for example the name is the right boom the validation says hey sup that's not cool and that's great too to make sure
00:17:07.770
that the data the incoming data is saying that's a great feature the problem is now when I am let's say I
00:17:16.530
want to create a user when I'm as an admin user yeah I'm the admin and I want to create a user and I want to bypass
00:17:23.760
certain validations for example as an then I want to create a user and be able to give that user a name that is longer
00:17:30.650
than 20 characters just because I'm an admin I'm cool by the way what about my head
00:17:40.659
so I want to I want to create a user with a longer name than twenty characters as an admin only isn't open
00:17:46.100
the normal user should always have this validation so what I actually want is the same as before there's a normal user
00:17:52.640
without the first validation and in rails this is basically impossible
00:17:57.650
because because we focus on push pushing all the
00:18:03.500
validations into the model yeah so what they did is okay this is a missing feature let's add if else to Kent so you
00:18:10.850
can like turn often on validations depending on the context because we don't want to change our architecture we
00:18:16.820
don't want to change the API we want to keep the model have all the validations yeah so if Sun else started to pop up in
00:18:23.510
the model and I mean do we like if some else we do not like if something else in
00:18:28.730
our code really we like polymorphic code because it gets super hard to read and follow what is going on yes every time
00:18:35.299
you add if-then-else into especially in a declarative DSL or API you are
00:18:41.240
probably doing something wrong structurally but it's always easier to add something instead of changing stuff
00:18:47.630
structurally rant over so the problem is that we try to M that
00:18:55.190
we try to handle two different contexts in one class yeah we want both different
00:19:00.620
sets of validations in the user class and I know that we have the validation
00:19:06.650
context feature in rails but I also know that no one is using it so the problem
00:19:12.950
in in in in this example is two contexts creating a user as a normal user creating user as an admin are handled in
00:19:21.140
one class because we want those two contracts in one class because classes
00:19:26.179
are bad and they yeah i'm alexi oh now I know Ruby
00:19:33.460
the way this is handled in other frameworks is surprisingly simple for example who has
00:19:41.570
heard of elixir and Phoenix Phoenix is a fantastic framework it's
00:19:48.770
getting better by the day so the way Phoenix handles this is a very very
00:19:54.020
fascinating so I mean this is a lot of code don't flip don't don't go nuts this
00:19:59.570
is only we this doesn't even matter what the code exactly does but what they do is they have them
00:20:06.340
modules just say what's the exact name of this asset
00:20:15.400
modules functions whatever so in this function yeah that is that is
00:20:26.420
fields in a so called schema and then they have a change set and this change
00:20:32.480
set contains validations and typecasting and other features I'm going
00:20:38.600
to talk about in a second her context yeah so in Phoenix instead of having the
00:20:45.110
code to create a user as a normal user and there's an admin in one class or in
00:20:51.020
one function in Phoenix you can't simply have two functions and there's two functions can share validations those
00:20:57.320
two functions can use different type castings whatever and those validations there's two those two functions or
00:21:06.050
modules can be used depending on the context when I'm logged in as an admin
00:21:11.240
I'm gonna use a different function and it is surprisingly simple how they solve
00:21:18.140
this problem of I want to have two different sets of validations on four different contexts
00:21:24.970
in a relatively young framework for Ruby
00:21:30.070
hey we like Ruby right whoa I
00:21:35.170
know it's really late and everyone wants to go to the in official alpha party me
00:21:40.309
included so Trevor is a framework that works on
00:21:46.490
top of existing frameworks like hanami rails a grape Rhoda and basically brings
00:21:54.020
what we call high-level architecture into into Ruby software development
00:21:59.120
because I said we already know that I'm the author of the of it so it's a shameless plug in Trevor is that this is
00:22:05.180
basically identical to the way it works in Phoenix and we did not copy stuff from each other it's just common sense
00:22:11.390
an object-oriented or in in functional programming yeah so again
00:22:19.400
don't freak out this is only a structural code you don't have to understand all the implications in
00:22:25.490
Trezza you have what we call operation which is a class per context so I have
00:22:30.530
an operation to create a user as a normal user and I have an operation to create a user as an admin and what we
00:22:38.120
have in trailblazer is contracts so in a contract operation you define the incoming fields
00:22:45.260
exactly the way Phoenix does it and you define the validations per context so if
00:22:50.930
I want to remove validations I add a new operation with a new contract and I can
00:22:57.260
then use this validation in my operation so the runtime code is not really relevant at this time but the the point
00:23:04.340
here is exactly the same we had before yeah instead of trying to push
00:23:10.330
everything into one class just because we want to keep MVC like we can't change
00:23:18.220
instead of pushing this into one class we have two different operations they can share validations they can share
00:23:23.920
typecasting and all this kind of stuff coercion features you will always be dry but you don't have this problem of ah I
00:23:31.670
don't want this part of the code run when the context is like this you just have two different objects for two
00:23:36.860
different contexts it's really simple it's like why would I bother to push everything into one class and then
00:23:43.420
disabled afterwards instead of just having two separate classes to handle two different things so we
00:23:49.990
we what we do or what many people do is they rethink their ap is because they
00:23:56.570
realized hey pushing everything into one class for example doesn't make sense let's do something else and
00:24:03.550
it's it is actually not that hard and I don't know what's the with having two
00:24:08.899
glasses instead of one some people think oh wait are you crazy glasses object
00:24:15.039
if you use object it's gonna be slower because my garbage collection and what
00:24:21.429
objects to do one thing only and 15 things at once that's like what's wrong with you and then relax relax it's
00:24:29.179
really simple just yeah relax so using objects is not expensive because every
00:24:36.139
time you use a string or a symbol or a hash or you do an hash merge an object
00:24:41.990
is created as well so it doesn't matter if you create a hash or if you create an operation to create a user it is really
00:24:50.090
cheap in Ruby and that's because we have really smart people working on their kind of stuff well he's not paying attention
00:24:57.190
another example of this obsession of we have to have everything in one class
00:25:02.929
because is the old feature it's gone now am etter
00:25:08.899
accessible so etter accessible I don't know if I have an example yes accessible
00:25:14.090
allowed you to define if I create a user I only want to
00:25:20.330
respect name email in age everything else that is coming in should be ignored
00:25:25.700
okay so it's basically not a validation it's more like a filter and again it was
00:25:32.269
like where do we put this into the model of course because fed models can you control it so we could say if I create a
00:25:39.590
user just ignore everything but name email and age but only when you're a normal
00:25:45.950
user when I'm an admin I want to have all kinds of fields allowed because I'm
00:25:52.159
an admin how does this work in rails it is impossible again
00:25:57.639
isn't it so what they did and that was actually the right thing to do yes I can
00:26:04.789
also talk positively about good stuff but okay stuff they introduced strong
00:26:09.860
parameters at some point because they figured out hey we cannot handle two contexts with one declaration in one
00:26:15.980
model we should have one declaration per context and then they introduced strong
00:26:21.049
parameters written by our doctrine writer and
00:26:26.390
highly inspiring individual David Hansen so that was a good thing because now you
00:26:32.490
can have access control or the filtering as I called it per context um
00:26:38.510
the problem was well is that this code sits in the controller so now what
00:26:46.110
happens is you have some validation code and some filtering code in your model and your
00:26:53.310
some validation code and filtering code for example strong parameters in the controller and again I do not understand
00:27:00.270
what is the problem to just introduce a third layer validation for example that contains both parts because it's both
00:27:07.230
validation relevant and that is again exactly what Phoenix and Trevor is a do
00:27:12.480
okay look at this beautiful logo take a deep breath
00:27:18.740
here we go so in this function or whatever we called it module I'm to say
00:27:25.890
it's apparently not here I'm really really really angry so it's a function do you also college
00:27:32.520
function in fiends like is it like this is have a special name okay it's a
00:27:38.100
function a function so in this function to create a user they have this cast
00:27:43.370
function where they can say I'm only interested in the name and the email per
00:27:49.170
context because I'm gonna use this function only as a non admin user okay
00:27:54.540
and it's exactly the same introducer so instead of having it in sitting in some
00:28:01.590
random place we have the properties defined in our contract and the contract
00:28:07.320
is our operation so I use this operation as a non admin and I use another
00:28:12.750
operation with different fields for for an admin context for example so I don't
00:28:18.060
have to I don't have to deactivate features that I already
00:28:24.300
initially added for a special case I handle all my special cases with different classes of functions it is it
00:28:33.060
is so simple and I I really struggled to understand why
00:28:38.300
we why we make our lives miserable hard I am by by forcing
00:28:46.060
like people to push everything into MVC
00:28:51.170
even though what we do is not MVC yeah so a validation is not model
00:28:58.090
dependent and it's also not controller dependent so why don't we have a layer for the elevations yeah and the funny
00:29:06.530
thing is that lots of existing new frameworks
00:29:12.040
completely go into the direction of let's have one object per
00:29:17.830
context let's have one object to do one thing validation and in rails we still have this okay my
00:29:26.150
access control is in strong parameters which is awesome because it's a separate object it's actually cool but it's in my
00:29:32.390
opinion in the wrong place and my validation of the parameters once they are filtered happens in the model and I
00:29:38.840
might also do some like manual validation for example if there is a current user I have to check something
00:29:45.530
against I might do that in the controller because in the controller it's easier to access the current user and it is really hard to understand what
00:29:53.810
validation code is run in this context or in this context and this is not because the validation code is wrong
00:30:00.140
with anything it is because we don't have the right abstraction layers yeah we try to work with an outdated I don't
00:30:08.300
want to say fundamentally flawed but flawed design of objects and a lovely example how
00:30:16.660
api's and flaws were picked up by smart
00:30:21.860
people is the brand-new is it 2.3 the brand-new loli operator
00:30:28.900
also known as Keanu Reeves operator which has the following behavior
00:30:37.150
so you often have this case that you want to access a really really deeply
00:30:42.950
nested property of some nested object graph breaking the law of Demeter one hundred
00:30:48.680
thousand times but doesn't up and you always have to check like is the profile there yes then is yes so this is
00:30:54.920
actually code from from the rails guides and this is a really awkward and you have to go through like it's it's super
00:31:02.020
convoluted code to go to just to get some thumbnail URL or something yeah so
00:31:08.900
but you have this a lot because it could always be nil and you don't want to access a little bit because when you get the nil exception and we don't have
00:31:15.770
monads in Ruby yet so yeah
00:31:21.220
so what they did was they introduced tried inactive support a few years ago
00:31:27.170
and try basically allows you to go through the chain I think you have all used try actually if you use try you're
00:31:33.260
doing it wrong but you have this chain and you can write this chain in one line instead of in seven lines and it will
00:31:40.400
help you if there's nil it won't continue the the execution chain which is actually pretty cool so they people
00:31:46.220
saw hey this is really awkward in my existing API because we don't have an API for this case let's introduce tribe
00:31:52.610
and what's even cooler is that then ruby in 2.3 it was 2.3 right they introduced
00:31:59.330
an operator to do that kind of stuff so you don't even have to think about am i
00:32:04.520
using active support or not because i don't really use it oh sorry I said stop stop the ranting so
00:32:11.000
and they introduced an entire operator to handle this special awkward case of is it new or not and that's pretty
00:32:17.840
that's pretty fantastic because it is the job as I said earlier of a good
00:32:23.990
software developer to pick up here's a problem with my abstractions my API is
00:32:29.120
not entirely nice to use let's change it and that's exactly what happened with
00:32:34.520
the Keanu Reaves sorry the safe navigation operator where the Ruby core
00:32:39.800
team introduced a way to to treat execution chains and the bad
00:32:46.460
mill object that might be emitted in somewhere in this chain I wish we had
00:32:53.750
more operators like this but who knows Ruby 3.0 coming in when was it December
00:33:01.340
2 and 25 is coming and I'm sure it's gonna be packed with useful features the
00:33:08.419
Keanu Reeves operator when I appeared I was happy because I love it when people
00:33:14.929
add and extend their api's for the sake of better code but I also was a little
00:33:21.980
bit sad because it is a complete is it's another story to talk about is this
00:33:28.759
actually good code to have those long chains of responsibility in your code and I can already see how lots of people
00:33:36.409
jump on this feature and say yes let's use the lonely operator and we will save
00:33:43.669
ten lines of code and then they upgrade to Ruby 2 point 3 which is good and they
00:33:49.610
will think my code is awesome now because I'm using the lonely operator so one I happy laughing one eye a little
00:33:57.950
bit sad because it actually is and also
00:34:03.230
am a kind of dangerous tool because it might create the illusion your code is now perfect but if you have five level
00:34:11.060
deep chains in Excel to access objects you might have to rethink your structure
00:34:16.149
anyway I'm not here to talk about I actually I am here to talk about structures or whatever
00:34:23.109
a last feature I want to want to have is
00:34:29.589
or a problem that is crying for a feature is a new keyword or I'm a new
00:34:39.560
keyword and suggesting proposing whatever so when you use namespacing in
00:34:46.310
Ruby who likes to use name spacing in Ruby excellent this is an awesome audience
00:34:52.419
because nice racing is great let's say you have a class defined in
00:34:57.800
one file user dot avi and it's a user class and it is derived from active
00:35:03.020
record base it is totally fine in another file for example lip user
00:35:09.740
created a bean I want to namespace the create class into user yeah this is
00:35:16.950
how namespacing in Ruby works so there's different kinds of tricks and different kinds of tricks how to avoid
00:35:24.329
the problem I'm gonna talk about but it's all kind of has its benefits and
00:35:29.460
trade-offs and so if you use this way of name spacing you as excellent
00:35:34.680
programmers instantly see hey there is redundancy because I have this and this
00:35:39.779
twice and if I forget to add this for example in the in the
00:35:49.200
upper file Ruby will say hey stop here is a superclass mismatch if I forget it in this case Ruby won't say anything and
00:35:57.089
it will work because that's apparently a feature I was asking about that yesterday too I was asking Matz he said
00:36:03.269
it's a feature that's great if I load this file first without this then this
00:36:09.420
file will break and because Ruby doesn't know is it an active record base or is
00:36:15.150
it a is it not is it just a normal Ruby class so it is
00:36:22.549
no matter how you turn it you always run through this problem when you name space you have to be really careful with with
00:36:29.309
loading order and you have to be really careful with using the same inheritance - basically you have to be redundant to
00:36:37.980
satisfy Ruby which is cool because I don't want to have classes submitted with multiple inheritance but actually I don't want to think about this kind of
00:36:43.829
stuff I just want to say something like hey what if in the second file I just
00:36:48.869
say namespace user and Ruby will find out ah you mean the top-level user class
00:36:55.769
that is derived from active record base but in the second file the second file that is loaded I don't care about this
00:37:01.529
because I just say Ruby I want this user constant can you please give that to me
00:37:09.089
and nest they create the new create class into that namespace and this
00:37:14.400
feature is not existent in case you didn't know
00:37:19.529
there's no namespace key word even though I made it orange on the screen because I just I just marked them well
00:37:26.190
spaced and clicked font color orange so this feature is non-existent yet ah
00:37:31.369
but apparently it is already approved by the
00:37:48.540
is the way to do open source you just tell people what to do and they do it and in the end you can say oh I did that
00:37:54.750
I invented that by the way I'm waiting for whereas my there should be someone with a five minutes um sheet of paper
00:38:01.020
but no one wanted me my professional timer here warned me so what's what's
00:38:06.119
going on here what we you all love me it's gonna be such a
00:38:14.339
good party tonight so um I did try to show you some
00:38:22.349
examples when abstractions start leaking and I also
00:38:27.839
did try to show you how to solve that and usually this implies more than just
00:38:33.210
oh I'm gonna allow another argument in my method or I'm gonna change the method
00:38:39.000
name this is cosmetic little changes they do not help what you have to change is the structure of your code yeah
00:38:45.810
usually it's the structure so it's not about method names and method arguments it's about what object has this method
00:38:52.619
yeah and this is the really this is the hard part in software development is architecture and there's no book to tell
00:39:00.060
you how to find I mean these books how to find out how to when something is
00:39:05.070
wrong Martin Fowler refactoring an awesome book I gave it to a friend and
00:39:10.440
he still has it so I only read half of it so
00:39:16.550
it's a great book to find out those kind of to learn how to find out about those kind of problems
00:39:22.339
but there there's no book to tell you here is how you solve this problem and
00:39:27.810
here's how you solve this problem because you can read a hundred books about this design patterns they won't tell you how to solve you exact problem
00:39:34.200
but what you have to keep in mind when you encounter those kind of code smells
00:39:39.540
and that it's your job to think about a new API it's your job and it's also a lot of
00:39:47.420
fun to play with new architectural changes and to make sure that the new
00:39:53.150
API will probably solve stuff that might appear in the future because I could develop other things about what it can
00:39:59.570
happen in the future even though we can't see what happens in the future okay so changing api's is not wrong it's
00:40:07.100
not like oh I wrote code I have to change my API developer it's it means you're a good developer yeah always
00:40:13.730
think of this login form with where they suddenly said hey our abstraction of email and password I know it's a
00:40:19.700
horrible example but it doesn't matter it's not enough let's add some new functionality to log in with github that
00:40:25.790
was awesome it made everyone's life easier I don't have to remember my passwords anymore I can drink more akia
00:40:30.980
and and it still works okay so when you change your API is and your structure
00:40:37.670
you're doing it actually right and there's a couple of simple tricks you
00:40:42.910
will learn automatically for example the simpler your objects the less responsibility and object yes we had
00:40:49.100
some excellent talks about this at this amazing conference which has the after party on the first
00:40:56.600
day not the second day so there's some the simpler you design
00:41:02.690
your new API they're more likely you are on the right path okay but changing
00:41:07.790
stuff is not wrong and I hope that also existing huge API is found in rails will
00:41:16.130
slowly pick up this idea of hey maybe it's not okay to work with a
00:41:21.260
ten-year-old flawed MVC paradigm and instead of adding and
00:41:27.110
adding and adding new features which is awesome and I totally respect the work of the rails core team but I would hope
00:41:33.080
that new structural ideas and new architectural changes will be accepted
00:41:39.050
faster than 10 years to you know change something and
00:41:44.380
so the last thing I want to give you on your way before we all meet at the vitamin B after-party is
00:41:51.580
that if you change your IP yes you're being innovative and that is great so
00:41:58.270
you want innovation you want to cover you want to solve problems instead of
00:42:03.400
just ignoring them and or just like you know having some duct tape fix for this
00:42:08.950
kind of stuff you want to innovate your own code and that can only happen with change and not with looking at you
00:42:14.170
couldn't say oh I'm such an awesome programmer actually I do that all the time so the last thing you should know
00:42:20.470
is I really like him sunsets and
00:42:27.060
thinking you were an amazing audience and now let's go through vitamin B whoo
00:42:44.950
you