Tuesday, October 11, 2016

RailsConf 2010: David Heinemeier Hansson

ause saddam
I've been talking about real three for a long time and I
last year and I think even before that I we were talking
a lot about all the plans we have for real three older wonderful things that
we wanted to do
on but it always feels kinda by
hollow to be talking about future code it's much more interesting in my mind to
talk about existing code which is why today
I is a lot more special because rail 3
is is here we're not putting out the final release yet but
the code is there I we plan to put out either the
final beta layer today or the release candidate depending on how r
how good we feel about it I am so
since you guys are all here and I saw the hands going up we've been playing
with Rails 3 and we've been running stopping production
now is Stephanie the time to get involved rail 3 is by far good enough to
not only play with but put stuff %ah life
I at 37signals we have at least a handful about locations that are already
running in production
serving lot of requests on rail 3
I we are in the process of converting all our major ass to this while
I am and that's pretty citing it's great to see
something we've been working so hard on for so long
actually being real which is why I'd encourage
everybody also just to try the just the start up fresh experience start a new
app
simulate your own I recalling that
there at the rail so I run ball I basically put together a small apt while
you're here
try it out because the fresh experience is really
awesome we've done a lot of things that are not just about improving
things for existing applications a lot of it is about improving
the getting started experience and we'd love to see
atomic be back on that I am so I'm gonna give you a presentation of
the things that I basically care about the l3 rail 3 has tons and tons of new
interesting parts and features and improvements and
there's no way I could talk about all of them so I'm just gonna do the selfish
bastard rundown
which is the four major features that really gets me excited
um wanna billion
keep things to get me excited about any new version I've rails
is taking out annoyances taking out things that just
been boiling my blood for too long
until finally somebody does something about it or I do something about it
on one of the first things that I've been annoyed about for really long time
is this when i download so one of our 37signals abt that I have been used in a
long time I'm installing it on a new computer
and trying to get it up and running now up until this point that's been so love
black magic because all abt depend on
a variety of things they'd band and gems they depend on plugins they depend on
all sorts of setup
and the process I've had so far for
figuring out what this after pence on is dowling
running the test and seeing the break the test all
I'll I hadn't all this damn alright info let him try it again
he and sooner or later you start hating though the
I am and that's really just a crappy start to experience
and I've been seeing is for a long time for years
I and it's really been bothering me especially because
I remember back I think if not the very first or else comp then
number two I Dave Duncan Davidson
was giving a presentation on e-commerce site they were making at the time
it was talking about this repeatable environment that they had
they had everything summed up in one thing that they could just run and they
would get the right version um
Apache in my seek wall in the gems and everything
and magic would happen and you could run the right away and I thought for use
about that story how awesome that environment would be
but I never took the time to to make it happen I am
so we sort of attack this from a bunch of different
weird angles I one of them was called
I'll external
which we ran through capistrano which was sort of this yeah I'm all set up for
how to specify where you could get here on
plug-ins from but it certainly was no hole solution it didn't talk about
cancer just talk about all the internal stuff that we had at
thirty-some signals in all our plugin for news was alright
but it certainly was one was in great now what is great
is bumbler on this the coat on the screen right now is actually the
I the bundle for for Basecamp
we're not completely done with it yet but as you can see which is run through
all the dependencies that we have
are all the games list them out by version some of them
we don't even care what version it is I am
and you run this bundle install Magic
and bone your environment is there and I can't tell you how big a difference that
makes
for any app love even moderate complexity
to just know all the dependencies that are there
and be able to install and in just one command I
Carling you who has done a fantastic job on this
despite tons and tons a pushback
biggest I've been seeing this ring for a long time
I knew the pain was there if you've been working mainly on one ever to happen you
had everything set up in you don't change it around a whole lot
you don't necessarily remember that pain all that often it's something that
happens to other developers
setting up your app so what do you care well
I you should care now
the push back that originally came around are back from bundler
was forgetting one thing the magic the bunker does is that it creates its own
little bubble and that is both the
blessing and the curse of the system that a crazy little bundle
were all the dependencies are mapped out it also means that nothing
I am you don't tell it to be there is there
which if we look back at this I am Tim filed that we have
for per for Basecamp things that I would forget all the time in the beginning and
I would
swear up and down about fun being a piece of shit
until I I figured out that oftentimes up
sometimes it was bogged and oftentimes it was my own inability to just
remembered the butler
is a bubble so for example if you're a map to my sequel TM
my sequel is not there Butler didn't care that is on your system
because like the whole point is that you can have a system
also some things but did great is tiny little bubble were just the thing to you
say %uh there
she need to say everything that you need in your apt to be there
that's the number one trick soon issue internalize the fact that
system James do not exist as anything else but a cash
for installing Bangla gems it all
make sense the same thing with Ruby park for example
as eyewitnesses because our air messages aren't perfect
I you'd run debugger in your apt and its alot burgers not installing Uruguay talk
about I have it on the dump
08 enlisted in my I don't file some others which you probably think hard
about what can we include
the fall by default what should be listed as part is just a
a Ralph requirement but this will be true for a lot of other things
tell is a gem that one of our plugins that hasn't been converted to a camp
depends on
and again it was one of those things were like what the hell
why isn't this working is not working because I didn't mention in my ball
so rails 3 is a la carte
dealing with annoyances things that just
I pisses you off and now they don't pick you up anymore
which is great but we're not just all about being grumpy old man
we also about appreciating the beauty of things
Active Record worries which is basically taking
I action active relations and putting them into Active Record
I'm at all this fancy relational algebra blah blah blah blah
I don't even really care about that stuff what I care about is
my coat got a whole lot prettier you take this
I am very simple you sir all
quarry I you seem like you have your all you have your conditions your name your
hash
it's sort of like a mouthful and this is a really simple
version that I most or lot to Cory's have a lot more
ship going on I am and it becomes sort of a long Hashem all these other things
which is which is kinda have sought now
replace that with the new version we have in rail straight
if the whole lot prettier what are the key things
I'll talk about this both here later is hasher's are great
but I'll we've been drunk on them for sometimes
I passions are finally passing options and all these things but you can
definitely take it too far
and there's been plenty of places where we have taken it
too far I am
see here you say you so where name equal something
instead of the whole conditions pointing at our I
and another hash in all the setup it just feels like this is too much
and secondly the awesome part of this stuff is that you can keep
decorating it that's when I really love about it I
active relations in Rails 3 made everything lazy
no Korea's immediately executed until you need something from the quarry
so you can keep building it up I am
and then it's triggered when you actually need to think when you're
pulling uses out of that array that you just a
or the query did you just build up I
cool thing about this is it seems like I am just billing records what am I really
getting from this
I it's like a prayer that's fine what you're really getting from this is that
you can build your Korean stages
so high-rise which is what are the implications we haven't 37signals
as a pretty heavy-handed permission system who can see what and what times
you know what every single Corey everywhere to
know about that you want to bubble up commissions from somewhere down below
and you would not believe the hoops that we have to jump through to make that a
pleasurable
process before we had yes whenever Korea's just executed right away
it's a real hassle to building in faces
cell this is going to be great for for stuff like that
no what's also great about stuff like this is that it provides a more
consistent E
to this stuff that we already have we already have teeth scopes
and scopes now are just part of that partial build-up
there named I am worries
on the existing classes that we have and we can combine all this stuff
with the new beautiful syntax for the clearing
I worries end with the
the stuff that we already have like you can combine it and
put a scope after another score bonilla automatic this figure out what's going
on
latest with middle name I will run these two cores and merge
the conditions together in a very easy
I to use kinda way there's no up all this with scope
nonsense we had to use blocks and blah blah blah end
you can keep decorating on a 20 which is really cool as well
so you can say user latest would middle name and say you know what
known this query returns 50 items yeah I didn't it 10 right now
and it's not a limit after the fact like it's not like first record database for
10
are 50 items and then you just cut it down to 210 you
after database to whole lot less which is just
it's amazingly pretty it's more efficient I am
you get to delay you Corey should get to build them up in stages
and it becomes easier and this is really the magic
up a lot of the rails 3 stuff its
is not that we're tackling harder problems with heart solutions
its that we're tackling harder problems with stuff but simpler
than what we had before and that's really the key and that's why we spend
an enormous amount of time
worrying about the API because I think it's very easy as a framework which
jurors
to move with new users so you stay focused just on the people already know
railed who are already deep into it and you just want to solve their more
complex problems
well that doesn't take very long until you end up with something that
only the I am people you already had all along can use
nobody else can come in anymore and I think that's probably
departed rails 3 I'm most proud about that I think the barium entrance is gone
dow we're stalling a whole lot other
intricate complicated problems that existing rail to Baba's have
but for new guys coming in the whole thing looks simpler
works simpler it's more consistent and prettier
on that's really a big part in it now
these two parts I yet relations
stuff which I pratik work the bunch on getting into the code and and Carlin who
worked a bunch in
on Butler are all awesome things now our talk
but if you think that I worked on myself
and go over so that the decisions that made is
come to I'm to where we are go through how do we actually develop an API
how do we actually get into why is it supposed to be named this white
posed to be named that because I think you're shed some light on just the
development process that we happen hopefully invite more people to get into
the game
I am a big part real three obviously is that we have
I hundreds and hundreds of jupiter's if you look at the Packers going into real
three
just on a weekly basis you see new names
all the time I am and the more so than inlining sink
are API development process and sensibilities are
the easier and more patches we can apply passer
are the router so
the router as it is in its current 23 form
I started a long time ago it started out a long before we worried about resources
I which I believe within rails 12
was the first %ah I attack at that
and Airways it was a clutch
like we added on something he says and that was mean
the sign for this to happen I think we pulled it up
fairly well and it was sort of an experiment in the beginning
we all weren't sure whether this was uprooting
good way to develop applications and whether we would keep on with this
reston resources stuff for a long time well the answer has been in for a few
years
we r like we're not going back we're not going back to our
and non rest world for the majority of applications coming out and is
is a good way to develop applications laws
was take a step back look at what we have and realize
I'm if this is going to be default path
the optimal approach to developing Rails applications
the coach should reflect that that should be the majority case
so let's look at what's wrong with this
map resources people at one avatar
and it has a member actions well first of all
it is doesn't look good it has the same problem that the other code we looked at
I am there's like too much stuff going on into little space
it's very concise you can say I
intensive number characters
or actually not even turf care contempt number blinds it's very concise
but conceptually it's not very concise at all very muddy
what are the reasons here is flow ownership
so if you look at the half one hash one avatar
half one avatar at to at one avatar
and then the next one is member pointing to something
so board member actions for those for the
avatar or those for the people if you do is read it out like you normally would
ill kinda looks like it would never talk it kinda looks like
who does this belong to it's not clear from just looking at it
and I know we get into the pattern we know our work something doesn't bother
us but
when we take a step back and look at it like this isn't right there something
wrong here at the flow
is wrong second hasher rightists
we have the same problem that we had with the with the worries
this is too much action going on with all these pointers in
all this stuff I'll were year
it doesn't feel like we are cramming too much into it
we have to come up with some sense above
up all these things apart so it's not just on mashed into one
big complex think now one thing we try
was alright let's do a yield so
what's all the house one avatar and just to yield instead
and then I'll say alright members little closer to
to people now so it's all close a relationship I am
but yeah then you have this problem with the yield over at
then you had to say do people and people the resources
me
I'm didn't feel quite right now this is
the new API for l3
and the router so much simpler so much cleaner
the only thing we use is this simplicity opened ended scopes
you say resources people start the scope
although it has a resource avatar it's not all tangled up in one line
it actually way more code if you did our a code lock thing would say
what the hell you balloon my Rails app from two lines to
6 what eight lines a terrible setback
not not this is so much easier to read we are trading
line length for I am
lore complexity now it's also both the
about the clone a ship because it's very clean out his intention everything runs
up that
it's all the hasher rightist by just making these
get post and put I member operations really explicit
I am and there's no yield over had well
it's pretty up free might be progress but
I thought you hated Anthony Ball for a long time I've
ranted and raved against ins the mall I which is
the the concept have not using our I
a yielded parameter like do people and just
two straight do something and then a value aid what
what's in that block within the scope of where you came from I don't even know
that the grand exploration
but brought something like that because it fell more
complex in something a if you want to put your own code in there
I were you gonna trigger something that was already there were you going to
override something
when you when you're yelling yielding a specific variable
what you can chain everything of that and you know like I'm not messing with
anybody else's stuff
in this instance all I am
if I'm calling something member like I'm calling the yield function
here II I can't not do that so
there's plenty reasons not to like it n
when you're rocked by look something like this:
it's just all chain of one major yield
that is the right choice and that's I think a fair amount above what I want to
talk about yours like the
pressures the concerns I am
the things we have to worry about changed the way the route while
used to work where everything with you single line there's no
deep nesting everything which is controller action
value lineups it work right even work great for the symbol map resources
comments
and in those cases it is worth to keep
I instant email out it's not worth the same
map what it is worth though if you look at this second example
which is a real example I yanked all these example straight from the route
fault I have one
specific abt there's too much it's not worth it
anymore and I think that that's the interesting part about a lotta
trade-off that we did for Rails 3 I'm with their times were both approaches
makes sense
it is figuring out when is the majority case
once the tipped it over now the bottom line is the majority K
the top 10 not win your case anymore so it's time to to do something about that
and
in turn the ball made everything all up for you so
coming off Anthony Maule I want things I
with the roof will queasy about was well what do you wanna do a lot of Ruby
inside iraq prop route RBAC through the part you can run every
any peace go to you on and in a raid in Baba Baba and
in Sanibel I don't like that when there's too much mingling I don't like
when you have an in San evolve based DSL I'll
would want to run too much if you are on call because that's when
I see like that the complex that arise self wanna the
reasons for pushing back against this was the notion
up I with options this is again a peace Fr
running code after one of the app's the is integrated new style
what we have with options which is basically just saying all this stuff
that's being yelled that are going to have the same
hash options here like this was an example using generic pesar
Rubik 02 automate some parts of the route API
I this was pretty much the only 1i would fight
I was looking through all my route follows seeing
this was repeated over and over and over and over again on the
January pieces I'll I syntax I was using
the common pattern which is with options so
obviously you think alright Missy a coming Paden
within your syntax well also the bells should go up
time first extraction time for extraction we should pulled it out
and make the simple which is what we get
so if you take all that pizza Co we just had you can now we're I did into this
everything can be billed as a scope
are following the same rules love a flaw as we had the other examples they're not
just
related to resources anymore this will work on anything
this for example is not up a resource map up
in fact this is going to happen were using in
high-rise what we have two different paths that go to the same controller
I and we only use those paths and index action
we have a party's controller and you can get to it from people
even get to it from companies and we do different things interview depending on
it
but this just looks so much simply
because we realized with options with this common pattern interest extracted
into Skype
and when you extracted into skull you start looking at the second set
well two parties
index this a very short fixing
way a tribe something feels a little weird I'll I
when we first premiere this there's a lot of pushback but this is kinda like
the Ruby syntax for declaring
whether something is an instance variable on a class
wide use in lower case and it's not really a class
I am like what's going on here like this doesn't feel quite right
now if you look at how this plays out these are the two
sources of inspiration that we have to let syntax so on the one hand we have
the former
where declaring were a route went to controller in action
I and on the other hand we had the inspirational looking at just the
the common Pat enough up declaring our
an instance method on a class now
interesting thing I think in to sign an API
this API design is not slavishly
just following existing conventions it is looking for peace is a
inspiration pieces up recognition
in stopping already have and then extracting that out
refusing it together I am and coming up with something that's derived from that
like that where the magic happens the magic wouldn't happen
if we had just said alright gotta fall do exactly the same format as the
I ruby glass it would have to be capital P E parties controller
hash mark index because now we would have all these control control control
control all the way down because
everything you're up to 60 there would be right
I'll so this is sort of the pattern that we've
with you that now awesomeness comes
when you then realized that one inside opens the door
to a whole slew other simplifications
this goal think that we just talked about we can use that for anything now
one of the key problems with the previous implementation up map resources
was
if you wanted to do anything that was exactly map resources
US crude you have to basically do everything
I from the start that didn't work very well now we have
this generic scope think that we can go through I
and use everywhere and he's just a few example real-life examples
the people using scope or were they can keep the existing resources
there's one for token we have two talking to get into room there's one
freeman using an
optional scope for a a locale for language about
the side to get in there and you can combine them actual points
use namespaces with the scope and if you can see here
this reminds me so much about what we did for for Active Record
it's the same way of deriving something and boiling it down to a few simple com
are I ideas that you can combine SU
see fit and it has internal consistency
and it works first stop that sa but even outside the box that was a big part a
bitmap resources with hardcoded macro
that only works for exactly that case these concept work for everything
alright this is the first 10 just translating but let's come the same
like there's not a whole lot of difference there translated a little bit
more and we can start having this progressive inferior
we start taking options away as they are
decibel from the thing you came from and all the way down to just get account
camp
it's pretty awesome I is also comes with the fact that we
killing the all the wild card mapper
like which is basically the tombstone saying
resources and a new epic learn things is the way to go not just use a while Kate
mapper anymore it's over it's done you can add a bag and if you're
legacy the advocate depends on it but it's bad news
I I action mailer
action mailer is another one of those things that for very long time
earth me dissuaded ugliness
this without you still look we had these instance variables we would assign
things to when they're all the spare both this a real example we still have
this
coding in back now we tried the first app
at making that slightly prettier and all we did was end up removing their
instance variable markers air that number parade
the hold up here was realized that we had all these things we have to decide
make a how can we make this simple can't just turn into happy we're gonna have
all these keys we can just make a method called im gonna have all these call
this is just too complex and that was the underlying assumption
number underlying something was there was five calls you have to make for
every male
and there's no way around that which are try words stand still for so long
now alright someone we start looking this more critically
and seeing patterns first ball from being set
I always said from constant or class variable it was a hidden people
it was not something that every single male action needed alright
we could probably deal with that percent thing
same thing was I get test mechanics we put in there for easy comparison have
up to strengthen male don't need that anymore either
I'm unnatural consistency we're trying to shove
the passover bearable to the view into the same syntax because that was what
the other five called for
and without you got this consistency nato
if you read about all these three things you can get to this
so much prettier we extracted the default into a real t-fal
put up in the top no more males have to to worry about this
I am and then we built the rest as
control mills for a long time have this
split personality on the one hand they were kinda like gun control on the other
hand they
were kinda like a model because they were you call them yourself we wouldn't
have this battle calling them
I and their it was stuck in the middle and was getting the worst of both worlds
now is that alright screw that this is going to be a control
there is a pattern that we're gonna fall an old Southern things just
but there's no time left but that was the breakthrough just making a decision
think this is that
as you can see this is the comparison up a controller and a
a mailer and they look just alike I the syntax for
is almost the same now once that breakthrough came
IQ sort like opened floodgates you look at something like this which again is
on with the real peace coach horrible way of declaring
a mail having to are two parts
and assign yeah really just nasty nasty stuff and we're all doing it
in the new way of doing it we've all exactly the same unless we do for the
controllers they have moved to view they can have multiple
template and if they do you are mad render them and if you need to do
something special about them
you should format but there was no this time left: we just
for all the concepts as well as we could and it turned out at all just work
the bar in concept goes even deeper look at this one where we're trying to
at attachments to to the mail now
in the new format which is using I
attachment axis which works just like cooking asses
ashes that like for a long time was just a how do we add these attachment we
already did all the design work
now we have to break through they can't work just like cookies
actually these things often feed into psych as soon as you start realizing the
one breakthrough
you have now to implementations have the same idea you start seeing
something that was wrong with the original idea cook it was a great
example that
dip this could be set up where you would assign a hash to it and
I will happens all over record I wanted eternity cookies and they were just
there for a long time now we wrap that up in just could be stopped permanent
that will automatically set this that it's going to last for 30 years
much simpler approach to it we've adapted signs such as you can
assigned something I that you need to keep
unchangeable for the user something we ought to do with the remember me cookies
I'm and a final thing here just that on
seeing there's no parity here so did and a synchronous or
hash abiu sign something on cookie stop permit the time
when you read it on cookies because it doesn't make sense or doesn't matter
whether you reading from now this actually the next slide
fed straight back into this last night Mikel was working
on the I action mailer API and we were
treating this bag into the
I the set up to have this is going to work like how are you going to link to
an attachment in email
I am yet this idea you would assign something to variable and then you
wouldn't act that variable
we don't need to do that used the same ID air from
I am cookies
like we have could be stopped permanent there could be a stop sign we can just
use
attacks in stock in line I had to run this up
and you can have an online test men and you can link through its anarchic now
you can just call ty Burrell you don't need to sign anything
internally I awesome all this flowing from just realizing the similarities
and reiterating across that right there's my sprint
on I rails 3 on the
main features that I care about this a this was all we had to be more than play
a reason to upgrade and a lot of fun to play with these new API's
I'm but just before stop I'll
I do sometimes get sucked into vaporware code
and it is kinda fun just to talk about what is
going to going to come I'm so let me talk briefly about
just court three quick ideas that I have a real three
one that I want to work on I or
actually prefer we want somebody to work on so I can enjoy
I am
number one acid pipelining
so right now we have this is split were all the important stuff
is an app and the junk drawer assets
%uh JavaScript style sheets and images aren't public
and public is usually a big mess
just throw shit in there and then you'll into it and app is this beautiful place
where you use extractions and
neatly organize everything like public is for the signers those messy can't
Abbas for the high level programmer stop I
that we care about now that's not really
on a good we're going about because assumed to put something into don't
brought you forget about it
and we've been forgetting about style sheets and JavaScript and ways we can
optimize that for a long time
I let's not do that anymore what we're
trying to do is we want preprocessing to happen
we want JavaScript in south east to go into the app
directory such that we can work on it with quote it's not just
tax that you can Mangal anymore now
it's going to be cold just like regular view so you can use Irby
and you can use anything else you on it most importantly wanted in that
process we can compile it down to something
so there's a lot of different or something called sprockets for
JavaScript stirs
lot of other ways of trying to get are JavaScript into one piece of JavaScript
I'm issued actually being real every single app out there
has a few huge performance benefit for compiling
JavaScript and CSS down to a single file a single request that can be
neatly compressed answer to use as fast as possible and you don't have to do any
work or
and the cool thing is the sooner you start saying all right we have a
pipeline
we're processing we have called you can apply magic opens up
number one piece a magic I'll dealing with
icons images and balling them down into sprites
craning sprites today is a freaking hassle and it's a huge benefit
on I am high-rise right now we're currently working on
falling into sprite I believe we had 29
separate image requests to request a high-rise index page
29 request but you have to do to get all the
icon stick trash the plush doll that sell
if you compile that interest pride a single image
and just reference it through started so much faster to go through
so that's where we're going to CSS it now Cote
we can insert helpers in there so we can say alright
sprite CSS results in a corner this worse I am
you pointed at I don't get too excited you pointed at
a a folder icons in automatically
render a sprite based on the files that are in that
so trash into plus and you can reference it
in the interview just a sprite tak
you all have the the the CSS buildup and you just references logically from the
PATH variable
no configuration no setup it just happens as part of their compilation
pipeline
I am now the quickening as you can see I'm
getting increasingly ep we've actually been for a long time obsessed with this
pita bread publications
and what we found by looking at we'll stop is of repeat pattern
stop because the matter much anymore if you coach is reasonably fast say
five on a male second to last users don't know it what they noticed
is that all the other shit takes three seconds downloading the CSS downloading
starts his Baba Baba
a big part that is look at this chart so this is some app
rendering yet the first part taking almost a hundred milliseconds
I for the code to generate and you have all the other stuff coming past
a after that now Jeremy came up with is awesome
idea I'm jury saw for somewhere else and I actually just read that
Facebook is looking into this with big pipe which is the notion of the flush
so you could flush your head section of whatever it is that you're generating
the part that links to style sheets and CSS before you're done processing the
rest at the stop
you allow the browser to start pressing these things so much
sooner you can basically move all the rest at the processing up
about five in milliseconds or however long it is that it takes to our new pact
all this printing as strategic name flush awesome
well filed yet I am
I'm always looking at these API's I and
thing think you just annoy me this is a key them something that annoys me
CREATE TABLE drop table worth the drop for the down part
a migration is always the fucking thing I I always see just drop drop drop drop
drop
and it's always naming the same thing it's always just naming the inverse
where that's really unnecessary we don't need to do all that manual labor
what if we instead just had a a proxy that we could
record all the stuff of city could record what it is that we were
adding to it and then it would automatically know what we have to
to go back from alright that's the whirlwind tour thank you so much