Duration 38:39
16+
Play
Video

RailsConf 2019 - The Elusive Attribute by Chris Salzberg

Chris Salzberg
VP Engineering at Self-employed
  • Video
  • Table of contents
  • Video
RailsConf 2019
May 2, 2019, Minneapolis, USA
RailsConf 2019
Request Q&A
Video
RailsConf 2019 - The Elusive Attribute by Chris Salzberg
Available
In cart
Free
Free
Free
Free
Free
Free
Add to favorites
1.67 K
I like 0
I dislike 0
Available
In cart
Free
Free
Free
Free
Free
Free
  • Description
  • Transcript
  • Discussion

About speaker

Chris Salzberg
VP Engineering at Self-employed

I am a full-stack Ruby on Rails developer leading an engineering team building payment and e-commerce systems for the Japanese market. I speak fluent Japanese and also have experience in translation and editing.

View the profile

About the talk

RailsConf 2019 - The Elusive Attribute by Chris Salzberg


Is it a method? A database column? Over here, it's a field in a form. Over there, it's a parameter in a request. It's the thing we decorate in our views. It's the thing we filter in our controllers.

We call it an “attribute”, and it's all these things and more. We take it for granted, but this innocent little idea is a window into the beating heart of our web framework. Behind its magic are valuable lessons to be learned.

Join me as we delve beneath the surface of ActiveModel and ActiveRecord, to the complex abstractions that make attributes so powerful, and so elusive.

Share

So I think Sebastian text apply for organizing this track, my name is Sebastian said, it's Chris elsberg. I love talking to you loose about tribute. Thanks for coming to talk. I was really worried that being the last tour the last bit of talks of the conference interview be dead in the Witchwood come to the stock, but I'm really got to see some people here. So this is a track on unpacking rail has anyone mentioned that you know, this really really big and it's a lot to unpack and rails ends Auto Parts in there and there's some of those parts that we know there are other parts there that

that we don't know but we kind of know that we don't know them, but I said, I think it's a lot more until this is a quote by guy. You may know named Don Rumsfeld of a famous quote actually probably he said as we know there are known knowns there are things we know we know. We also know there are known unknowns that is to say we know there was some things we do not know but there are also unknown unknowns the ones we don't know. We don't know. So I know bicycles.

I've been basically on bicycles as far back as I can remember before I could even walk really this is a picture of me when I was something like I think four years older. So I with my dad on a bicycle. My dad is touch and the Dutch are very fond of their bicycles you may know and my dad is no exception. So he raised my brother and I have a real kind of respect for the importance of bicycles and I grew up in Montreal Canadien. You may know that much about leaving. I know I want y'all to recycle city, which is kind of surprising given how freaking cold it is that I have to hear

you really couldn't imagine an exception. So when I was there and then I moved to Amsterdam in Holland for a couple years and times for the world Capital biking cyclists. I was biking the whole time I was there and then I mentioned I move to Tokyo with a fly live for many years now and I still like in Tokyo and that is not me but I have a section and so bicycles are still a really really important part of my life. I use them everyday. I really I would out my bike. So I know I know I also know that there are things that I don't know about bicycles. So if my

bike brakes or something and it send you anything beyond sort of thing back on I'm kind of Clueless and I don't really know if I just bring it to the shop and they fix it for me something that I didn't know that I didn't know about bicycles. Which is that I didn't know how to draw a bicycle. I never tried this before in your head right now. Try to do this try to put the frame the pedals and the chain on this bicycle and you may find it's a surprisingly difficult thing to do. In fact, it's such an interesting

thing that cognitive psychologists have studied it as a demonstration of how our mind can trick us into thinking. We know things that we don't actually know these are for a drawings of bicycles from a study are participants were asked to draw the pedal chain and frame on to his wife as you can see, none of these bicycles whatever actually work is all kinds of all kinds of interesting Innovations on this bicycle, but you can sing wrong with it. And and so one way you can

kind of see whether I know it's wrong advice like this would actually work is to go out and actually told about implemented in fact has been sort of implemented in this is actually what it might look like if you were actually to build this bicycle. And this is kind of interesting of this is actually a example 11 rendering from art art project by artist named bicycle. So fascinating that he went out and asking everybody can do to drawing bicycles. And of course most of the bicycles I like the ones I

showed you were in some way they had problems with them, but he found so fascinating are all different. He went on the run to the moment like this. So you should look it up in pictures because it's not wrong with the bicycle would not work. If you if you sat on it would pretty much collapsed and so in this in this process of getting something really interesting this is from an interview where he talks about this thing, he found that people even like myself who ride a

bicycle everyday they they generally don't know actually how to draw a bicycle completely accurately, but they're there is one group who is statistically Statistically much better at drawing bicycle. And these are people who actually saw to fix bicycles with their hands actually know how the parts work together and they got they do more than just the form. They know the function of that for him. So this is a quote from an interview where he says people who are really into bikes start out from the frame. They represent a small percentage of people who get the drawing perfectly

right most other people tend to start from their most sure of so for nearly everyone. It's the wheel I saw many people drawing all the rest in the hope that and pedals would help them figure out the frame. What is what is the top to do with attribute? Right? So I think I should be a little like bicycle for myself. Anyway, people who ride them. People know them are or something. It's really familiar to us. Right if you're using rails using attributes and using them everywhere are using them in your views to rain in interviews hear your filter in the controller if

you're sending through channels, I mean, they are everywhere and they seemed kind of simple on the surface. Right but what I'm going to do today and explain to you today is that I have to be to actually Elusive and they fall in that category of things. Like I mentioned that you think you know, but you actually don't know that you don't know. And one way to bring out these things that you think you know, but you don't actually know that you don't know it's like those drawings of bicycle this actually draw how this thing would actually work and I think if I asked you all to draw how not to get

work, of course, it'll be different from that art project I mentioned but I think they'll be some common elements elements. I suspect would be that you would draw this you draw nothing, right? This will be like a title on your on your post mall or something and this is like the wheel on your bicycle ride to something that you know must be there. And then then you probably would like that active record. He probably draw call him. That's where the thing this thing gets its information from its data from and your table in your in your database from the method

to the call. And this is like the frame of the bicycle right? And I bet many of you would draw this last. And so what I want to do today is we're going to we're going to do this in three parts from the first part of me to take this picture here and like that picture of the bicycle. We're going to kind of implemented. I never going to sit on it and we're going to watch it crash. I'm in the second part then we're going to redraw It Started from the frame. I really see how that looks that's going to be something more accurate presentation of how it actually is implemented in

practice and possibly improve it. What is reported that it's nothing to do with me? This is my kind of laid introduction are these are kind of my ass because it said, my name is Crystal Iceberg. My handle is shili. I'm out which is which is approximately when I work for a company called Indica here and they are graciously find me to be here. So if anybody's interested working at a great company in Tokyo, I'll let me know. I'm a blockage in my car, And also I haven't allowed Jam called Mobility for translating model data

about a month-and-a-half ago and the border customs called give generator at three methods module in meme. It's a very small for a change and it's a one-line Edition that was merged. So if you want us there now to see what it does you can go and you can take any active record class. I'm picking up like a post here and you just look at the ancestors. And this is before the change. So if you look at the ancestors here you going to see a bunch of mixed in modules and

classes that we inherit from him is going to think what I want to highlight here at least two things here. These are actually they look different from the rest because they don't have a constant Ashland. They are Anonymous modules. They're actually instances of a subclass of the module class called active record at three methods generated at three methods. And this is actually a module Builder. I'm not going to talk in detail about that. But I talked about it before in the bottle before you can look it up. Basically you just need to know this is an anonymous module. And so if you jump to

master Branch right now, we're real sex when it comes out. This is what it will look like in this is what that changed. I thought it was did it gave these things are named. So now it's like post generator. Sweet nothing but it's pretty important because these modules are in one layer very important. Go to see how they're important and create a posterior so credit post give it the title The List about you and then we can go and speakers talked about introspection. Somebody's introspection here. We can stay post give me the method object for this method title. This is

Rubino's not reels. We just okay, we want this thing to this method. I'll pick everything everybody is an object. So you get the title and then we can say OK method. Where are you to find? This is actually a useful trick, by the way right now. It will return to exactly that module D post generator athlete methods module. And if you call instance methods on this thing, you're going to see a whole slew of different methods, right? You're going to see the methods are all the methods that

have to do with the title. Call him came from user title? But you also see the same set of methods for all the other columns on this on this post table CID before Type-S all these things like that and these are called important because they're actually modules for this interactive model and also an active record and this stuff seems kind of actually you see when you look at on the surface, but actually active record override a lot of them model modeling in this thing is actually not so simple and this is not all about you. It's what I'm going to talk about

here. I'm going to talk about you message. It's not all about trees, but it's kind of the entry point. If you want to learn more about how to reach work you really have to understand that and it's not easy to understand. So that's what I'm going to try to cover now in the next government 7 headlights. So we can add a contact this method sits in a in a month, which is an instance of this generated a street methods thing and that's in your model. Okay, so now we're going to sit

on the left side of this picture Here and Now what I what I want to do this but like a genetic experiment where you kind of Nakajima out and you see what happens with and without the gene so we have the smallest. We want to knock them all out and see what happens if we take out that much because I had all those methods on it, but you can't take models out and Ruby you can't just take him out a lot of the ancestors, but you can do kind of thing which is to remove all the methods on the module so we can do that. We can just say OK module. Give me all

your instance methods then iterate over them. And for each one, we're going to use this method to remove method. It's a private methods. So you have to call it with send so you call remove method you give the name of the method in this where we've all the methods and you can check you can say no modway your instant message and I'll return Olympia right? We've removed all the message from the module. And you can double-check you can say Okay post give me your message titled previously this gave you back the method object now, it will raise the name error undefined method title. So we're

sure there is no title method on this thing anymore. So now we can go and take a post. What's your title? And surprisingly I think probably the most people it will still return The elusive attribute. So this module has anyone since it seems like it's really important belief is removed it and it seems to be working fine. So what's going on? So we can go back to our picture here and what if we done we've knocked out this this method right and yet it still seems to be working and if you know, you probably know this only really one way this can be happening which is that we're hitting method

missing and somehow method missing at handling that call and seems to be doing the same thing as before it still mapping to the column value. Okay, so now I want to shift to the other side of the picture. So what we did in the first part is we couldn't remove them at the message from the mall. So we thought would happen never going to go to the other side of the picture and try to remove the columns which is going to be a kind of similar kind of think what I mean by when I say we're going to remove the columns. I don't mean we're going to remove the columns from the from the database we're

going to we're going to make active record think that there are no columns on this table supposed to see what we can do this. We can grab this thing called ischemic Ash and this is what I could record uses to what it sounds like to cash the schema schema is what tell dr. Record what are all the columns and all the tables in the database inactive records not going to let us a trick to do this kind of thing. It's not going to be easy for us, but we can do this like this. So we can grab you can reach inside of this cash and grab this thing called a column cash, which is an instance

variable. You have to get it with instance variable that because there's no public method to get it and then what we can do is we can set the the value for the key posts in the Collins hash to an empty house and what this will do is that anything then what we'll do is we'll tell a record. Okay. I've already cashed this thing and the value of an empty house with means there are no columns on that table. Normally these ashes would be a mapping napkins from call names of types. But since it's empty active records been interpreted to mean

there are no columns on the post table. And we can go and confirm this we can expect the post class and this is kind of funny. Right? I mean, we don't normally stay active record models whose tables have no call him cuz it's kind of a useless thing. You would never really do this. But this is what it would look like if you had one and same thing, it looks kind of funny cuz it doesn't have those are three normally would help me with title of whatever whatever but that's not there because there are no columns on the stable now. And then we can go and we can't. Okay. Do you have a method

telecenter method or any of those other methods? It's going to raise in a merry doesn't have any of those methods which is not really surprising. We can try this. The title. Anyway, maybe it's going to a method missing. It doesn't have to be there. Then we can just look at the blank house. This is not surprising. We told active record. This table has no columns. So it's pretty much acting weird expected to act. But now we can do something a little bit different. Instead of creating a post we can fetch the first post and assume now that our table has one entry in it with a post with a

titled elusive attribute and post them to have anything on it. So that's not surprising but notice that were making the select statement right where select Post star from post which is always what you do when you when you grabbed the first thing of a bottle and the database River the database does have those columns on the table. So the davises going to return all those values even though I can record of leave the house with columns. I know you can again go and check those methods like the guitar method here think I'm going to reason a mirror so doesn't have those methods, but what's your

title? And it's beginning to return the elusive out. You would even though active record doesn't think this thing has any columns on the table. And in fact, you can check everything. And what's Happening Here is actually that we're kind of exposing here. Is it active record treats out to be some kind of two different ways than one kind of privileged way it treats out to get to sort of the ones that are actually defining your schema. So you're scheming says he's the title on this on this table under the comments on this table and those are kind of

special in a way, but then then it's also have to be in terms of the lease returns. And what do they base returns? You can see if you do this kind of thing here, you can just called what actually happens internal you can call exact Aquarion the doctor Bricker base connection and give it to SQL string that it would normally use and look at the result in is going to return to this active record result object. And you can check the columns on this result object. I use the the word Collins here is kind of their clothes for the Liberals tend to

these things and the key Point here is that this result that comes back from the from the query is completely independent of this whatever the schema cash is. And you can check to see if it's okay to post what you're calling names and it still didn't tell you to call names are there's nothing in the stable, but it's happy to return to these things and let you access them. So if we go back to this picture now what's happened now knocked out the calling from the schema and this is sort of knocked out the method. In fact, it never defined the method for these things because

there was no calling for them. But when we call the vet said what happened was that it it went to Tim to go through nothing missing boy from a message to some value which is which corresponds to a column on the table, but then does another route actually what you probably don't know about which goes through method missing and get the value if there's a result from the result in the database and this may seem kind of artificial and I kind of tricked into thinking there were no columns on the table and why we just never even matter, but there's a reason this is here. And as far as I know,

I'm the first person to give me the reason for this. I've never had anybody else to explain this. This is the reason it's here. It's there. If you ever use this type of pattern, this is not a super common pattern, but it's pretty frequently use. I think probably most and you have actually seen it. This is the case for you. Do I select or group and you given sum SQL and then you Alias something right? So you Alias like title to the sky was super example. And then you grabbed the first thing first one. And then you call Foo. And now if you think about it Foo can't be a method. He

right it's not going to be a method. If you actually wanted to be method you have to define a method every time you get a party like this. It's not practical Proctor biking to do that. So what the reason why there is a method missing thing there is to it is to handle this this case where you're really saying something to something else the database when I return to pooh thing and somehow you have to be able to access it and that's what it's there for we can go back to the picture and to make things a little more concrete. Now, we've got like this title method method. We're going to hit

when we when we just do it like the first so we select post from post and then and then front door Routier and then nothing missing when we do Select Title as food who is not going to be a method. So we're going to hit nothing missing but nothing nothing is going to go for this back door and it's going to get the value for the result which was returned from the database. Okay, so that was sort of the first the first I can now I want to come and look at a better. I think a more accurate way of looking at this actually works which is to start from the frame and this is going to be in terms of

these things called mattress and dispatchers. So I got to think about this. I want to come to think about it in terms of not if they're describing how things are but how in terms of the constraints that this Frame actually satisfied. I just need to be kind of determine how this works. And the first one is a constraint not rails. It's a ruby and probably a lot if you are familiar with this is very basic thing and Ruby methods are fast relatively speaking thing. It's slow. Nothing missing is very slow. So you generally want to avoid method missing if you can. The second thing

is that the scheme of static and this I think it's obvious that this chemo wasn't static. It would kind of defeat the purpose of having one in the first place. But I applied to show you that Flex statements examples of any name you want them to have you just realized something and you can be anything and so active workout has to deal with this has to be handled. And so the solution that is there in the code has these kind of two different things one at the front door route where we where we kind of take the scheme up. We did find a

message for the everything is in the scheme and those are fast, but when you at least something we go to this doctor route and then I'd case we was nothing missing to handle these Dynamic catchy names And the thing is going to sit sort of in the center of this whole thing is going to be this very innocent thing called his method matter. If you're looking this up you look this up. It's inactive model are three methods towards the bottom of the file. It's a very simple class. It's not complicated, but the role that it plays is not obvious at all and not not physically documented anywhere as

far as I can tell and this thing is just admit. This is a combination of a prefix and a suffix the dirty. Why is matter what you may have used Traverse vs Direction, I'm going to refer to it as for the back door and into itself is going to be confusing. So what do we do? We take all these calling from the database into this machine here and then it pops out it puts the prefix. And then we're also going to need to think it's Hargett which is where we're going to take the string attribute and do the same thing that's going to

give us a treat was and then we're going to we're going to create what's but I'm going to refer to hear the dispatcher method, which is just title define Title wise and it's going to take the argument and then it's going to call this this this method asked me was if it's kind of a generic method Hassan title. What does the name? And this house and working this is where is the front door code where this actually is used. This is you can find us in Acton ma Lottery methods. This is not terribly complicated but it's going through these mattress. So it just for reference. There are currently 18

of his mattress most all of the majority of them were for dirty dirty matching 3 tracking bunch of other ones as well. So what are we doing everything possible from the schema? We're calling method name here, which I just saw you and now we're taking with the name is like title was we're taking the Target that and it was it named title. And we're sending them to this method Define proxy call Selena really intuitive and it's going to do that for every

column for every every of each of those each of those patterns, right? I thought this is the front door. This is a little bit easier one to understand the other way were going to look at this in terms of the back door and hear the way to think about this. I think it's a machine a kind of flip it and reverse and we're going to convert them to the prefix in the suffix to a regex. So now we're matching stuff in this is where the match your name comes from. The metronome is really confusing because mattress and fasting is not the main thing that a does anymore. Anyway it once did you can do a bit of

get archaeology on this then you can go back and originally the main role with matching stuff, but it's not much anymore but it still doesn't matter. It's going to be handling something like this. So we got a method like who was there's no message who was missing and nothing missing is going to get a pass this to all those mattress and they're pretty much all going to return. No because they don't match any of the other patterns, but this matter here is going to match its going to capture food here. So who's going to be a cop show from this thing is going to have this a 3 was

Handler method and so previously we were defining defining methods Handler methods and now we're going to be but now we're going to actually dispatching from method missing and this is where that code this is the code to Second does this This is a like a fantastic method name. I think Ashley method mattress matching. Disco here. You can ignore. I'm in a debate with a real person to get this removed currently right here. So we're going through all the matches listen to say Tina in

this case for food wise. There's nothing to match except for the wise match her while I see one more year and it's going to match who said the cops are his food and then the other methods actually was and it's going to dispatch to that thing until we can try to visualize what this whole thing looks like if we were to actually draw it. So we're going to put the mattress thing in the middle of this picture now, What is the matter that can be 18 to do not yet, but we're just going to look at 1 for now. This is like the was matcher and then what we have for each match, we have a

dispatch Target is going to be a method that is actually defined. I'll tell you in a second. So the lottery was method and then we got two different directions, right? So one method we're going to define a method and this is the case of Death Metal. I showed you define proxy call on this this Arrow here is not a calling Arrow. This is like a method definition Arrow the word defining an ethical title was and entitle was calls after he was with the argument title. That's what that message will do and then the other direction is that we're coming from method missing. So we're coming this way. And

now I'm nothing missing is calling match with his food wasn't all the matches. And again, they're pretty much all going to return and then in this is important method missing. Is that going to say OK it matches the capture his food, but before it actually dispatcher distance OKC who actually my results like is that food that I actually get something cold flu in the results. And if not, it's Going to ignore it, but if food it come back if we Alias titled the flu and there was a few something in the in the database results results. Then it's going to then do the same

and you noticed you're the both has or ending up in the same place and that explains a little bit. Why earlier on when we took away the module and we called title. It still ended up in the same place because whether you go through the method which is faster preferable or whether you had meth and missing you both end up in the same place ultimately. I'm so the top one here at the front or root as I mentioned the bottom when here's the back door through method missing. Antissa, see where this actually happens. You can go into active model dirty. I just a Class A or

class methods to Define these mattress. And so this is for the 30 seconds isn't asked me to message suffix here and it gets a bunch of suffixes and needs to find the we looked at the wise matter there, but they're a bunch of other mattress. And I think there's a total of 18 ampere therefore to find right here and for each of those those things there's a method I'm telling you just one of them here like this which will actually handle these these mythic also this is actually was and it tells you what the previous value open not to be named out of here while I was Okay.

So now we come to what is in some way for the punchline of the stalk the title of the elusive actuator and I've been talked about this but and then there are 18 is mattress, right but when nobody will actually tell you if you look at the code anywhere as far as I can tell. There is one matter that is vastly more important than any of the other mattress and you really couldn't have any any meaningful rails application without this matter and that this matter here and and talk about their declared but this was not declared. It's just the default value

in this afternoon method matches are right, you never declared it's just there and not only that it doesn't take any arguments. And if you look at the tree method match your class and see what happens when you don't pass anything into the initializer what happens if you get a blank prefix in a blank suffix. Do this default matter is the matter with a blank prefix in a blank suffix. And what does it matter with a blank prefix in a blank suffix do well in in the legal in the the front door and we're defining methods. If you pass it a called me like till it just doesn't do anything

to it is to find title. And if you want any other direction and you're coming with food it's going to call Matt format is always going to return true cuz the Red X is going to be like always true and then you're going to take food and check is it actually results that was returned from database. And if so, you would forget her methods by which is the most important are three methods we have So we can go back to the picture that I have here or we had all this was stuff and we can kind of considered what is actually the more important case hear the case where we have a blank prefix and a suffix

this seems kind of weird. Cuz what's the point of a mountain with a black people like this is actually the most important one which is which is one of the things that's really hard to understand about this whole thing. So what happened to yours when we have a wee Define all the gator methods and those two and a method named after you because we don't depend we don't pretend anything. We don't depend anything. We just get the message and that's what I should call from inside the title method and the same thing when you pull through method missing with a meth with a with a colleague food this

weekend fall through to the same method attribute and this method you can find an active record a few methods the read module and it's there at the bottom. It's very innocently sitting there. It's actually at the earliest a private Alias to make it yet more elusive. Cumming internal house about to be so we can go back to this picture now and we're almost there we're getting there. So we need to find it it calls this method has the title and nothing now aliases to read after me which then gets it from some hash internally and nothing missing is

basically the same thing except it's a little more complicated that unfortunately tricky things about unpacking rails is that everything is quite heavily optimized and so I mentioned are 18 matches and work like this, but the two most important ones which are your and your second life are most important because you're you're getting your Setter those ones have to be off tonight. So actually for reasons that are kind of hard to explain in a sock what actually happened to active record to bypass that they'll listen to find in the custom weight. So what actually

happens is this So who the title method actually is Define so busy. The same thing but in a slightly faster way. And now this is far as as far as I'm concerned. He's an accurate depiction of how I should be directly to find inactive record and also basically not tomorrow but not to record and I think if we look at this now and I hope at least you got a sense of how this works, but you know, this this works its reason but it's like I would say no no way. I hope I haven't lost everybody in the process of unpacking.

So I think we can think about maybe what there is maybe to improve here and that's what I want to do in the last a little bit that I have left. So I'm in case anybody has been you know, totally ignoring my whole talk because you've been tormented trying to figure out what a bicep impact. He looks like. This is what it looks like and I think it's relevant to look at a bicycle friend because the bicycle frames are kind of Allegan in the way, right? You know, if you can't just make a frame. However, you want like that. I showed you an introduction there. It was based on a drawing would

never work right because it doesn't reflect the actual loads on a bicycle bicycle frames are designed to Wheels. Right? And I think that's kind of really elegant right? They don't do anything more than that do just that I need to look at bicycle. They tend to have the same type of frames because they optimize they solved that problem and I'm kind of a minimal way. Unfortunately, I don't think the solution that I just showed you is actually minimal in that way and that makes it harder to understand. So what do I mean by that? So as I said,

the reason that we have that whole method missing route, that would let is the hard part to understand the people don't really know about is to handle this pattern. This is why it's there, but nobody told me this is the only reason I know this is why it's there is because I said, why is it there? I yanked it out. I run a test on certain ones fail on this is appointed fail membership, but I'm pretty sure this is the only remaining reason why it's really there this pattern.

I forgot what in the world is going on with this thing kind of dug Deep Run. Is it? Okay, you know, we need to support this pattern, right? But actually what I showed you in that picture of the frame it's designed to support more than that actually right and if you think about it because of the ways to find it's going to support this as well. It should And it should also supported this is an example. I was showing you early and some of you may have to sort of wondering. Why are you doing a wise on something at the earliest? It might seem kind of weird, but it's the support of this is

also supported. If this doesn't seem strange to you, we can substitute this select to this. And now this is starting to look a bit weird, right this actually works. So you can Elias the number 120 any you can touch a whiny and they give you back when you can also change one to two you can check what one was and it'll tell you what it was and then you have to change on one will tell you change from one to two you obviously can't save this because you can't change the number one, but this seems weird sort of a bug in a way.

Black see it kind of gets weirder. This is a slightly contrived example, but bear with me here. So I work at a company with a payment Gateway in Japan. They're going to raise the tax. They say from 8% to 10% this year. They said this for many years and we never actually do it. So it may not actually happen. But for the amount we select the amount on 0.083% to get the text. We slept the amount time 0.02 to get the tax change that's a 2% increase to 10% And then we say, okay get the first payment we get the amount. It turned out to be a hundred Yen. We

checked the tax at 8% of a hundred yards. That's 8 yen exchange. I'm not to be too but it's actually me. This is actually true. This is actually what happens if you do this, and if you were able to follow what I've been saying so far in this talk if I didn't speak too quickly through it all you should kind of maybe have an idea why this is happening in this is exactly why it's happening. So what's happening is that you get this text changer you're asking for texting two different. There is no message exchange. So texting is okay mattress, you know,

most men don't match but the change matcher will Matteson they will capture text and then it was okay is tax in a tribute and it will say yes. Thing two packs as the change to the tax attribute, which is kind of meaningless actually, but it won't change in tax. Which doesn't make any sense because you can't change tax. You can't change things your aliasing raw SQL. So the interpretation your doesn't make any sense, but this is actually how it work. And if you if you're going to think about

this this kind of brings up a real Point here, which is that I told you that we have this in the front or in the back of the route and they're connected by this match your thing. And the mattress thing is called a match her but the main role is not see the match to Define method and its secondary roles to match. Why do we want the match so that we can handle this case where you call Foo and foo foo by title, but in the case were you actually match that thing you only care about to get her message, right? You don't care about this kind of stuff. And in fact in the rare case where

this actually matches. It's actually more like a bug than what you want. So I think I should just up shouldn't even be there. I'm so why am I telling you all this? Right? So one of the reasons is that well, this is this is sort of a picture to allow me to fix this. I'm pressing it's real because I asked people do you know how I can return to find inactive record? Right? And I didn't really get anybody who could really explain it any level of detail how this works and actually took me a long time to figure out and I think that's not good right at this is bad

for reals as a community. We should know how are atoms are defined. I think this is really important. And the problem is that this this code right now is really hard to unpack. It's really hard because I said it's not minimal in the sense of that bicycle frame is doing more than it needs to do in that more. It's very hard to understand because he could find a reason about why it's there. It doesn't really make sense until you look at the history of it and everything that came before. What is another point that I kind of want to make witches that you know, this is a track on unpacking

rail. So on the theme of unpacking rails, I think I see a lot of people Reddit writing about you how they're opening up rails and I'll look at the Amazing Mirror programming in the spirit of reverence. Like this is Holy Grail or something. And I think that's the wrong attitude right? I think we need to be questioning the stuff and take it apart and see where Because that's the way you're going to understand right this way. You're going to send it works. And so, you know, he don't learn to draw bicycle by just kind of staring out at you learn to draw bicycle or gain understanding by

actually kind of fixing the bicycle. So I think the message here that I want to leave with is that you know, don't just unpacking is great. Don't get me wrong but don't unpack stuff when you're unpacking it breaks. You'll realize that you know, you were too stupid in or whatever. He didn't realize and actually was a reason for it and then you learned something. That's great. But that remaining 1% of the time you may learn something that's actually important right? So don't don't just ride the bicycle fix it. I'll help you to understand better Hodgy Beats work. That's how you learn. How

real work will help everybody understand. How real swords Thank you.

Cackle comments for the website

Buy this talk

Access to the talk “RailsConf 2019 - The Elusive Attribute by Chris Salzberg”
Available
In cart
Free
Free
Free
Free
Free
Free

Access to all the recordings of the event

Get access to all videos “RailsConf 2019”
Available
In cart
Free
Free
Free
Free
Free
Free
Ticket

Interested in topic “IT & Technology”?

You might be interested in videos from this event

September 28, 2018
Moscow
16
167
app store, apps, development, google play, mobile, soft

Similar talks

Ylan Segal
Staff Software Engineer at Procore Technologies
Available
In cart
Free
Free
Free
Free
Free
Free
Molly Struve
Lead Site Reliability Engineer at DEV Community
Available
In cart
Free
Free
Free
Free
Free
Free

Buy this video

Video

Access to the talk “RailsConf 2019 - The Elusive Attribute by Chris Salzberg”
Available
In cart
Free
Free
Free
Free
Free
Free

Conference Cast

With ConferenceCast.tv, you get access to our library of the world's best conference talks.

Conference Cast
575 conferences
23117 speakers
8618 hours of content