Merken

Zen and the Art of the Controller

Zitierlink des Filmsegments
Embed Code

Automatisierte Medienanalyse

Beta
Erkannte Entitäten
Sprachtranskript
thank for that and and that the the the and if I also going as they started on my name is Michael going on and no cereals they've been doing this for derails rough 5 years of been dead for on off the 50 total and as you can tell from my from this line you program and we'll talk about rails controllers today and so before started and others in the junior track and musician hands who here is actually a junior developer somebody you were to the technologies and what they're good good so how many people here are a few developers were here to judge me on my presentation yeah well good OK so I'll have to present you got good deal good deal and so I am a start off and I guess that we're talking about controllers you've all seen them you've all dealt with them in some way or the other and a lot of times what you see especially for new developers and community Bhutan or maybe some you know uh a run on tutorials online and those lines way so perhaps that's me the it and the project don't are there but through balsam we've seen index actions to show actions so you've all seen the standard cried I but that's what I'm coming here to talk about is what actually happens on 1 controllers you see when you step on to a new job or you pick up a new product something like that and actually the 1st slide I have is 1 such controller no your nose was
read that we're not going to go through them 1 by 1 nothing like that that's that's atrocious but that's over 350 lines of a single controller with over eating different actions and hundred lines of just boilerplate code that's wrong if it buys wondering that's wrong I what i will talk well that is how will we get this nastiness I
don't what is essentially our standard controller the 1 we've all seen I'm actually happens a lot of a lot easier than you think it does i'm so what we have here is is the standard you have your index showed you create all the standard actions on but
a lot of times what you hear people say is that they they blame controllable on things like rapidly changing requirements and uncontrolled feature growth may be changed new team or or even in the worst case refactors elsewhere in the AP make you add things your controller and that's all wrong every bit of it every time you read something like that it's incorrect you that's not what happens these are all controllable things exist in every business every software product these things happen and there's a way to was to maintain a good controller so what actually causes this how do we end up with 300 lines of garbage well the main thing is that is isn't misunderstanding about what your actions are actually doing what resources are actually working on because so I wanna work Walker's through of a small example but I believe is a little bit closer to real world but have a glossary review things for 4 time here and so on and take for example and the sex is something that I've done a few times and would say you're working somewhere and that your company is in charge of running ads for its clients on Facebook Twitter of social platforms you guys so the fairly standard requirements and you'll see on your way to a kind of browse and and deal with the acts create them edit them things of that nature I will serve to have a way to control those sets of Paul's them activate them a basic on all style features and then the last I users have to be a to see the performance of their eyes see how many people are seeing and see who clicks them how many times they've been clicked with impressions are so so in this example I am not going build a whole at animal when you deal 1 controller and call this the the ads controller so the 1st
thing we do we come in OK we have an ad object somewhere and we wanna be able to do the standard Croat operations or will see there I actually prefer the term bread and because it includes the indexes browse read edit and delete that's just nomenclature thing and I'm weird that way but yeah so we saw this before this is just really implemented and in this context as matched control pretty straightforward I don't even have any features and they're like paging more surgery thing like that just straightforward and actions so so we this would push into production and everything's fine and the next thing want sort of so we have a total of 7 actions and the date that every controller as these most do I saw already talking about something that has 7 different context a trip to keep mentally the but like I said
before we have to control these ads and we want the energy that's a nifty can way maybe some JavaScript button on the front end and we click it and it makes some uh Ajax called or I our ap and pauses in that so the we
come in and this is something you'll see a lot of times uh I would say naive but but you know the developers will take these actions go cable the Ajax actions was just a command and control that's what we're dealing with right characters that same controller with those actions and don't worry if I if you can't read the code it on the screen there actually want you to keep a discount and keep a mental model of how how they control their shape and how old how much information is there OK we're not looking at specific implementation today but you see there are actually count as ballooned up to 10 I as not 10 different context and ways this controller can be used now that's great you know we have these these 3 new actions that maybe kick off a background job at the talks to Facebook or Twitter something like that then
when you're execs Watson and this is a phrase of earlier multiple times I so we want more responsive you why we want a some way that are page can load and unload individual visuals for ads asynchronously so we
come back over your trusty adds controller and maybe we we need pain to preview the and so the user can can see what a look like on Facebook and maybe there's uh we want some little widget it'll show them generic status you know with a list of the at something of that nature so come and we had to more actions now these actions of you can see it there but all they do is render our partially something for Ajax to process in certain page again we are actually counts back at the 12th be so they control doesn't look so bad and now I'll I'll let you know each 1 of those actions is minimally implemented as possible of the rendering of partials is a single line of background jobs or a single line of so any logic added here is only going to complicate matters Oh wait now we have to be a
dual the stats of statistics about these
so once again we come back let's say we want Hazel show our in the audience of people who have clicked or that's these are people who have interacted with our that we want to maintain a list of those and maybe wanna dashboards to come see how the eyes user and performance in general so we come back and we have a few more actions and these these actually deal with maybe some help or objects to do some calculations but maybe there's us some aggregation war of processing that goes on this data and here we are in our 40 now I don't know of number of a mention of that original controller I you we had 17 actions so we're not that far off and you can see how I again if he kind of logic this answer these actions if you ever need if-else blocks if you add in Edie estate statements anything of anything directly in these actions all you can do is turned back into
that progress were not that far off it's actually pretty easy and it happens without thinking about it you know you're thinking about that 1 feature adding a preview for adding statistics page but not you controller as a whole so the answer to this I
had to keep yourself from getting out of control what goes to break it up break your controllers up into pieces and now I have a lot of talks to a couple you developers before about this topic directly and a lot of times people have trouble breaking the context you know in every 1 of his actions we were dealing with ads so it makes sense mentally to stick in the ads controller but what I where argues might actually dealing with ads in all its actions so today can help you out a little bit and these are some different
ways you can think about uh what kinds of controllers you're going to to build to so in that in that example we had a actions that dealt with a static or review where data this is the processing of partial were on doing with maybe a static agents a landing page things of that nature we had actions that I excuse me dealt with things that are a composite concepts are concepts that are mere directly by like an Active Record model or something about nature and and then finally there we have aggregate actions things that collectible into data together and pipe down to the front end up and so let's take the example I'm works break up along these lines
so it's usually looking into static control use of static and you the style actions these are the same actions from a previous controller we you can actually read those men that's that's a form you can read again so these are the preview stats actions and I've separator amount stuck in a different controller because what you're dealing with here is a view of an ad non-AD itself a cracked as a different resource but different quote model that you're dealing with is the same thing over here will you composite controllers but now these are things that you'll see a lot of times devices actually good example of this and if you use device for authentication or authorization thing like that and there's all sorts of section controllers that you can override manager and functionality nobody that I know of is ever built session model in a rails at yeah and or like a like in this example so those others Ajax actions that would pause activator ads actually what we're doing is we're starting a job on the back and starting something some call other Facebook tell to pause a specific at so broken those up as well into this adds jobs controller and jobs controller and exist we're dealing with is jobs not at and the same thing goes for aggregate data are audiences that something is pulled from every and we have the dashboard that pulls information about every and we have yeah so it's a a it's an aggregate resource is not a single model the yeah and then of course we have our standard crud controller the index show create add to leave blah blah blah so but what we've done i is a
seperate all these pieces of different different controllers and it's not immediately obvious what the benefits to doing something when the far i'm but
1 is easier to debug your controllers it's easier to navigate and mentally because if you have a problem with say the previews that we talked about a minute ago and maybe we need to render them differently or something about that is breaking we know right where to go in this 2 actions and I controller so we can make those those without having to build the entire mental context that adds controller that we talked about earlier and the other is and you'll see this a lot set about the real world of learning and onboarding is among the toughest things the developer does and that's step into a new application of so when no when you're learning a new app dealing it's easier to take 3 50 lines and dig out the bit that maybe 2 lines you need to deal with on 2 lines you need to learn how a specific action works it's a lot harder when you have to dig through that big giant mess with Solomon go the other is you localize your changes and this is this is something that a lot people talk about encapsulation of you know a separation of concerns and what not but ultimately like I said before if you're dealing with say stats you to calculate something differently you changes are gonna current that controller not in 1 big giant met so if you go and you add say before action you now want to run authenticate this call for I do some objects set up before the action comes and i've you've got 20 different actions that controller you now have to explicitly control which actions that filters called on you know do a before action except always others are only these 2 and so now when you make a change only affects the pieces of functionality that you want to In the last year and this is 1 that that I haven't seen talked about quite a lot and that's that he actually easier to coordinate of working a larger team if you've got multiple people working on this code that's maybe you're working on on improving statistics adding more information and data there and you're here working on making the previews look slicker look cooler and maybe you over there you're working on the you know improving the medicine business logic we need to add to creating and had some kind of check we need to include all we can do that now not all making changes to a single file that then conflict's we get emergent the so and I got
blasted through a little faster than I expected but I the the main things I want to take away from this talk i r of that she'd actions look at actually what your actions in dealing with regret you're not not all dealing with an ad resource or a product resource for user resource these are different conceptual ideas that is dealing with and new controllers I wanna see a lot of controllers but that was the big giant ones I don't wanna see on 300 lines with 20 different actions in fact actually challenge you that that controller song beginning the standard crud controller make that the most complicated controller you at the 1 you see in this tutorial so when you see on line in the perfect examples make that the most complicated controlling that its is challenging a can be but ultimately that was most complicated when I showed you outside of the The Tragic and color of the so the the main point here like a set and then you'll see actually had a couple people ask me and how this relates to RESTful design and which is a fun buzzword in our world I and II and make the argument that this is restful to to create a REST resource a an object that can be created that can be destroyed that can be changed you have to actually find what that object it's and it's not I promise you it's not the same as all the other actions dig and take a look at that time because I so I've ever gone way under time here but but I had had happened over caffeinated but but but doesn't questions and I would love to go back through and talk about in more detail the the question was if
I have any examples of where is you know permissible or OK to add some actions on top of the standard cried actions and ends in some cases it can be I mean as developers we can play a balancing act in between the right way and the achievable way of you know if you if you have a feature going out or it needs to be in production in 20 minutes or fix needs to be in production very quickly it can be very hard to do a refactoring the 3 different controllers and test all those controllers and push the market and review the whole 9 yards but in so what you see is a lot times earlier on in a I'm in a project I it's is very convenient to add small actions like like that like positive Ajax actions or maybe the view actions and and it's it's alright early on you know if you have a total of maybe 3 controllers and you want tax in small functionality on their as fine didn't in get pushed out not a big deal but and the the main thing tho is is understanding when you introduce a new concept and so for instance if I had the previews that I mentioned if and that that was a very small feature early on yeah will stick that needs control not a big deal so but if this is a concept that you are approaching the apple lot and you gonna come back to the previews and maybe some stats which it or a know further widgets along those lines of this is something is going to keep happening separated out you don't don't just happen on the extra 1 because it will grow uncontrollably what actually build like an API namespace and but that's answer the question was so with the but they had previously written out partials but you after you've created a few of those 5 starts to appear like kind of private API you know you're your front end apple in front page is making use of these private calls to get these these partials at what point do you look to refactor that too so this lecture API namespace and and again just like everything else it's a lot judgment calls on but the it tends to decision like that tends to matter more when you for the and still developing future so if you know you're you're writing your 1st couple that that render a partial and then in you know a few more coming along maybe you're even dealing with uh sense Sun elements in uh serializing Uriah objects in a certain way and really it comes down to win an abstraction like that yeah I buy is win the the elements you're adding to justify the work necessary for the abstraction of and you'll see a lot of times the it's it's an interesting balancing act because I like al jump into and out like that and you know I've done that so many times creating new this internal API that that I can crank that out in a few minutes so the level of difficulty is different based on developer is picking it up and if you ever dealt with the agile development you you've estimated that way in the so a it can depends on the velocity moving forward you know where you're headed and to to come further your question little bit at what point is that stopped being an API embedded in your app and a dedicated API launched at a different your you know that's those those levels of abstraction in the app itself and really can depend on I will use to get going on from a design perspective from architecture perspective on its that's something that had to this day still didn't arguments of my you about you know like a whisker ahead and abstract this thing up there so I got some work this off the right now and and you know you make the debate back and forth and ultimately you know when when he got you to use a comma this API and they don't they OK you know we all can come to that same decision this time it does it does it and I do the right here that the question and then so is his question was on ideologue designs that is dealing with some of the the designers you know don't follow restfully maybe you know they view the design of an actor and how users can interact with and and that's actually crux of my point here is that designers to deal controllers designers will never do or the control of the controller is your or side of that so in that situation on I would I would make the effort to to maintain the separation you know a customer's controller a I'm sorry questions controller a student controller on and then leverage your front end to combine that data if necessary whereas the rejected something about nature now if it's extremely heavy and so you have lots and lots of places that these 2 objects or injured or or serialized together and then you start to think certain look at it more like a of a composite resource can like I mentioned earlier and so if you're always rendering those together then create a controller that encapsulates a concept you know this is a I I'm not sure what your context is but I we call this a student questions controller and it renders them out as a on a grouping of that data that decision you go 1 way or the other on that tends to go Tim's matter more how much you're doing how closely tied they are consistently throughout the AP on but I I tend to what designers to like me so because I'd since you force my code into a good design and and yell at a little bit of work to to got converges on the front and and but in my mind the benefits of of the ease of development on and localize changes really away that because a lotta times I refers to things are rendered together at the same time a the changes you want to use the logic associated creating a student or viewing them I will that apply the students self regardless of if it's winter together or separately and in which case you want that separated into his own controller and so a lot of times it's it can be hard especially in a meeting room but it's you know your code is is your code the designers design is the design and there has to be a line of separation and you know what I'm implement will achieve that design but I'm doing my way so that my code is still understandable still maintainable and otherwise remained in the fights them later on when you can't change something to the way they want because you can't locked into this this marriage of the 2 resources this paper is in philosopher well consider stole title from Robert person United is in your motorcycle maintenance and let's say that you know it's is like the same concept about and looking at looking at what's in front of you and you can see it from both the the functional and the esthetic perspective must swallow reasons why said don't try to read the code just look at the follows a hole you'd be surprised how much and I for esthetics on your code why actually do for functional and vise versa you know is is always you can apply also to a much more whole mind-set to it and while I am a not time you'll resident and then the other much of a few if the if the the the the the this 1
Rechenschieber
Weg <Topologie>
Prozess <Informatik>
Automatische Indexierung
Gamecontroller
Gruppenoperation
Güte der Anpassung
Projektive Ebene
Booten
Biprodukt
Optimierung
Softwareentwickler
Kombinatorische Gruppentheorie
Gerade
Freeware
Automatische Indexierung
Gamecontroller
Gruppenoperation
Textbaustein
Gerade
Code
Computeranimation
Keller <Informatik>
Standardabweichung
Bit
Facebook
Total <Mathematik>
Natürliche Zahl
Gruppenoperation
Systemplattform
Term
Computeranimation
Homepage
Client
Software
Gamecontroller
Gerade
Nichtlinearer Operator
Systemplattform
Automatische Differentiation
Kontextbezogenes System
Biprodukt
Objekt <Kategorie>
Chirurgie <Mathematik>
Twitter <Softwareplattform>
Menge
Automatische Indexierung
Refactoring
Standardabweichung
Umwandlungsenthalpie
Shape <Informatik>
Facebook
Subtraktion
Gruppenoperation
Implementierung
Automatische Differentiation
Kontextbezogenes System
Zählen
Code
Computeranimation
Energiedichte
Informationsmodellierung
Twitter <Softwareplattform>
Prozess <Informatik>
Gamecontroller
Debugging
Information
Softwareentwickler
Touchscreen
Facebook
Natürliche Zahl
Gruppenoperation
Einfache Genauigkeit
Mailing-Liste
Automatische Differentiation
Partielle Differentiation
Mathematische Logik
Computeranimation
Homepage
Rendering
Prozess <Informatik>
Last
Gamecontroller
Widget
Visualisierung
Gerade
Objekt <Kategorie>
Befehl <Informatik>
Statistik
Prozess <Physik>
Gamecontroller
Gruppenoperation
Zahlenbereich
Mailing-Liste
Statistische Analyse
p-Block
Rechnen
Mathematische Logik
Hilfesystem
Computeranimation
Statistik
Bit
Kontrollstruktur
Gruppenoperation
Automatische Differentiation
Kontextbezogenes System
Menge
Computeranimation
Homepage
Gruppenoperation
Arithmetische Folge
Gamecontroller
Kontrollstruktur
Hydrostatik
Facebook
Subtraktion
Natürliche Zahl
Gruppenoperation
Computeranimation
Hydrostatik
Bildschirmmaske
Informationsmodellierung
Datensatz
Datenmanagement
Fermatsche Vermutung
Prozess <Informatik>
Typentheorie
Gamecontroller
Gerade
Funktion <Mathematik>
Umwandlungsenthalpie
Trennungsaxiom
Autorisierung
Lineares Funktional
Sichtenkonzept
Systemaufruf
Automatische Differentiation
Sichtenkonzept
Quick-Sort
Landing Page
Automatische Indexierung
Debugging
Authentifikation
Garbentheorie
Information
Standardabweichung
Domain <Netzwerk>
Bit
Subtraktion
Mathematisierung
Gruppenoperation
Kartesische Koordinaten
Geheimnisprinzip
Mathematische Logik
Code
Computeranimation
Open Source
Gamecontroller
Softwareentwickler
Gerade
Internationalisierung <Programmierung>
Trennungsaxiom
App <Programm>
Lineares Funktional
Statistik
Solitärspiel
Systemaufruf
Strömungsrichtung
Statistische Analyse
Kontextbezogenes System
Elektronische Publikation
Objekt <Kategorie>
Information
Bit
Punkt
Natürliche Zahl
t-Test
Gruppenkeim
Element <Mathematik>
Übergang
Homepage
Eins
Gerade
Softwaretest
App <Programm>
Parametersystem
Lineares Funktional
Namensraum
Sichtenkonzept
Benutzerfreundlichkeit
Abstraktionsebene
Güte der Anpassung
Stellenring
Systemaufruf
Partielle Differentiation
Biprodukt
Kontextbezogenes System
Gruppenoperation
Entscheidungstheorie
Softwarewartung
Menge
Verbandstheorie
Rechter Winkel
Projektive Ebene
Standardabweichung
Instantiierung
Geschwindigkeit
Subtraktion
Total <Mathematik>
Ortsoperator
Gruppenoperation
Mathematisierung
Mathematische Logik
Code
Perspektive
Widget
Softwareentwickler
Trennungsaxiom
Statistische Analyse
Summengleichung
Objekt <Kategorie>
Modallogik
Debugging
Kantenfärbung

Metadaten

Formale Metadaten

Titel Zen and the Art of the Controller
Serientitel RailsConf 2016
Teil 42
Anzahl der Teile 89
Autor Kelly, Michael
Lizenz CC-Namensnennung - Weitergabe unter gleichen Bedingungen 3.0 Unported:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen und nicht-kommerziellen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen und das Werk bzw. diesen Inhalt auch in veränderter Form nur unter den Bedingungen dieser Lizenz weitergeben.
DOI 10.5446/31576
Herausgeber Confreaks, LLC
Erscheinungsjahr 2016
Sprache Englisch

Inhaltliche Metadaten

Fachgebiet Informatik
Abstract So you’re fresh out of boot camp or just off a month long binge on RoR tutorials/examples and you’re feeling pretty good about MVC and how controllers fit into the whole framework. But projects in the wild are often far more complicated than you’ve been exposed to. In this talk, we’re going to discuss several techniques used by seasoned engineers to build and refactor controllers for features you’ll actually be working on.

Ähnliche Filme

Loading...