RR 318 Metaprogramming with Jordan Hudgens episode artwork

EPISODE · Jul 11, 2017 · 45 MIN

RR 318 Metaprogramming with Jordan Hudgens

from Ruby Rogues · host Charles M Wood

RR 318 Metaprogramming with Jordan HudgensToday's Ruby Rogues podcast features Metaprogramming with Jordan Hudgens. We have panelists Jerome Hardaway, Brian Hogan, Dave Kimura and Charles Max Wood. Tune in and learn more about metaprogramming![00:02:00] – Introduction to Jordan HudgensJordan is the Lead Instructor at Bottega. Bottega has locations in Salt Lake City, Utah and in Phoenix, Arizona. They’re a full-stack development code school.[00:02:55] – MetaprogrammingMetaprogramming was one of those scary concepts. At the code school, when the students learn about metaprogramming and how it works, you can tell that it’s definitely a pretty exciting thing. Its formal definition is it’s a code that writes code. It can dynamically, at run-time, render other methods available to the program.[00:04:10] – Use cases for metaprogrammingThe best use case that Jordan has ever seen is implemented in Rails and that’s code that can run database queries such as User.find_by_email. By passing the email, it will go and find the user with that particular email. Now, there is no method in active record or in the user model that is called find_by_email. That’s something that is created at run-time.Another one is something that Jordan has implemented and that’s a phone parser gem. It essentially parses and validates a phone number. It also has a country code lookup. With all the countries in the world, that would be very time-consuming. But within 8 lines of code, it could do what a hundred lines could do without metaprogramming.[00:06:50] – Performance implicationsJordan never had performance issues because the generation of methods is not something that’s incredibly memory intensive. You might run into that but it would be a poor choice to do in terms of readability.In Brian’s experience, it comes down to the type of metaprogramming you do. If you have a bunch of logic somewhere and method_missing, that’s going to be a performance bottleneck. And if you’re generating a bunch of methods when the application starts up, it might increase the start-up time of the application. But after that, the performance of the application seems to not have any fluctuation at all.There are 2 main types Jordan works with. First is method_missing. Method_missing could have a little bit of performance hit because of how Ruby works. The system is going to look at every single method. The second type is define_method. In define_method, you’re really just creating a large dynamic set of methods at runtime. When you start up the Rails server, it’s going to build all those methods but it’s not going to be when you’re calling it. Whereas in method_missing, it has a different type of lookup process. [00:11:55] – Method collisions on monkey patchingThat’s one of the reasons why monkey patching can have a bad reputation. You don’t know who else may be overriding those set of methods or opening up that class. Jordan’s personal approach is trying to separate things out as much as humanly possible. If there’s something that can be done in the lib directory, you can place that functionality inside of a separate module. And if you’re creating a gem, you have to be sensitive to other gems in that space or even the Rails core.[00:17:25] – How to be good citizens to other developersMetaprogramming has a lot of potentials to do great things but it also has a potential to cause a number of problems in the application. For Jordan’s students, what he usually does is walk them through some examples of metaprogramming where it can be done poorly. But then, he will follow it up with showing exactly when this is done right.He shows examples of poorly written classes that have dozen nearly identical methods. And then, he also shows how they could take all those methods, put the names in an array, and show how to leverage things like define_method to generate them. He also shows them how doing monkey patching can cause issues, how they can actually open up the string class and change one of the basic functionalities. Show that when they override that, that affects the entire rest of the application.[00:24:45] – Worst examples of metaprogrammingJordan ran into this hive of metaprogramming. When he opened up one of its classes, he had no idea what that class did. It was method_missing all over the place. Usually, there are 4 or 5 lines of code inside of that. It’s relatively straightforward and makes logical sense when you read it. This was nothing like that.They had multiple conditionals inside of the method_missing. One other hard thing about it is it does not have any test whatsoever. You need some test to make sure you’re capturing that functionality and to check if changes broke anything. You can’t also decipher what the inputs and outputs are.[00:28:35] – TestingFollow as much as real world examples. For example, in the phone parser gem, you can see some tests in there for that. You can also pass in the input that you plan to give. See if that matches the output. Jordan tells his students that respond_to_missing is as important to putting method_missing in there[00:35:25] – Resources to get started Paolo Perrotta’s book Metaprogramming Ruby is one of the standards for metaprogramming in Ruby. He also gave some fantastic examples. He created a story about a new developer who goes into a company and learns how to implement metaprogramming from senior devs. It’s very entertaining and it also covers all the different aspects to think of metaprogramming, when to use it and when it could be a very bad idea to use it.PicksJerome HardawayDon’t Know Metaprogramming in Ruby? By Gavin MorriceDave KimuraSherlock TV Series on BBCBrian HoganiOS application: WorkflowOverwatchCharles Max WoodRuby Dev SummitAngular Dev SummitFocusterJordan HudgensPetergateComprehensive Ruby Programming by Jordan HudgensTwitter @jordanhudgensInstagram @jordanhudgensBlog crondose.comSpecial Guest: Jordan Hudgens. Advertising Inquiries: https://redcircle.com/brandsPrivacy & Opt-Out: https://redcircle.com/privacyBecome a supporter of this podcast: https://www.spreaker.com/podcast/ruby-rogues--6102073/support.

RR 318 Metaprogramming with Jordan HudgensToday's Ruby Rogues podcast features Metaprogramming with Jordan Hudgens. We have panelists Jerome Hardaway, Brian Hogan, Dave Kimura and Charles Max Wood. Tune in and learn more about metaprogramming![00:02:00] – Introduction to Jordan HudgensJordan is the Lead Instructor at Bottega. Bottega has locations in Salt Lake City, Utah and in Phoenix, Arizona. They’re a full-stack development code school.[00:02:55] – MetaprogrammingMetaprogramming was one of those scary concepts. At the code school, when the students learn about metaprogramming and how it works, you can tell that it’s definitely a pretty exciting thing. Its formal definition is it’s a code that writes code. It can dynamically, at run-time, render other methods available to the program.[00:04:10] – Use cases for metaprogrammingThe best use case that Jordan has ever seen is implemented in Rails and that’s code that can run database queries such as User.find_by_email. By passing the email, it will go and find the user with that particular email. Now, there is no method in active record or in the user model that is called find_by_email. That’s something that is created at run-time.Another one is something that Jordan has implemented and that’s a phone parser gem. It essentially parses and validates a phone number. It also has a country code lookup. With all the countries in the world, that would be very time-consuming. But within 8 lines of code, it could do what a hundred lines could do without metaprogramming.[00:06:50] – Performance implicationsJordan never had performance issues because the generation of methods is not something that’s incredibly memory intensive. You might run into that but it would be a poor choice to do in terms of readability.In Brian’s experience, it comes down to the type of metaprogramming you do. If you have a bunch of logic somewhere and method_missing, that’s going to be a performance bottleneck. And if you’re generating a bunch of methods when the application starts up, it might increase the start-up time of the application. But after that, the performance of the application seems to not have any fluctuation at all.There are 2 main types Jordan works with. First is method_missing. Method_missing could have a little bit of performance hit because of how Ruby works. The system is going to look at every single method. The second type is define_method. In define_method, you’re really just creating a large dynamic set of methods at runtime. When you start up the Rails server, it’s going to build all those methods but it’s not going to be when you’re calling it. Whereas in method_missing, it has a different type of lookup process. [00:11:55] – Method collisions on monkey patchingThat’s one of the reasons why monkey patching can have a bad reputation. You don’t know who else may be overriding those set of methods or opening up that class. Jordan’s personal approach is trying to separate things out as much as humanly possible. If there’s something that can be done in the lib directory, you can place that functionality inside of a separate module. And if you’re creating a gem, you have to be sensitive to other gems in that space or even the Rails core.[00:17:25] – How to be good citizens to other developersMetaprogramming has a lot of potentials to do great things but it also has a potential to cause a number of problems in the application. For Jordan’s students, what he usually does is walk them through some examples of metaprogramming where it can be done poorly. But then, he will follow it up with showing exactly when this is done right.He shows examples of poorly written classes that have dozen nearly identical methods. And then, he also shows how they could take all those methods, put the names in an array, and show how to leverage things like define_method to generate them. He also shows them how doing monkey patching...

NOW PLAYING

RR 318 Metaprogramming with Jordan Hudgens

0:00 45:43

No transcript for this episode yet

We transcribe on demand. Request one and we'll notify you when it's ready — usually under 10 minutes.

JFK The Enduring Secret Jeff Crudele An in depth tutorial and discussion around the assassination of John F. Kennedy, (JFK) the country's 35th president who was brutally murdered in Dallas Texas on November 22, 1963. The series comprehensively explores the major facts, themes, and events leading up to the assassination in Dealey Plaza and the equally gripping stories surrounding the subsequent investigation. We review key elements of the Warren Commission Report , and the role of the CIA and FBI. We explore the possible involvement of the Mafia in the murder and the review of that topic by the government's House Select Committee on Assassinations in the 1970's. We explore the Jim Garrison investigation and the work of other key figures such as Mark Lane and others. Learn more about Lee Harvey Oswald the suspected killer and Jack Ruby the distraught Dallas night club owner with underworld ties and the man that killed Oswald as a national TV audience was watching. Stay with us as we take you through the facts and theorie Explicit 暗黑森林 The Dark Forest 榮忠豪/Ruby 盧春如/Joanna Wang 王若琳 社會總是希望人人都活在明亮。但一旦人的黑暗面露出的時候,社會會怎麼反應? 人性的黑暗總是被壓抑的而不被允許顯露, 但若這些邪惡的行為無法被壓下來 會有什麼事情發生? 本播客想透過真實殺人案件與其他暗黑的故事來探索人的黑暗面,但就像暗黑的森林,在黑暗的樹枝之中還是看得到光芒,提醒人們黑暗之處還是有希望的存在。 除了只關注故事的黑暗,『暗黑森林』也會專注在人們對於彼此的關懷,同情,與自我保護的重要性。來吧!跟著主持人 榮忠豪/Joanna 王若琳/Ruby 盧春如 一起走進 「暗黑森林」 Powered by Firstory Hosting Explicit Rogues Gallery 27th Letter Productions Kristen, M.J., and Chris investigate pop culture's most memorable villains, antiheroes, and misunderstood monsters to find out how they make being bad look so good. New episodes every other Thursday. Explicit Ruby Ryder – Pegging Paradise Ruby Ryder Your guide for pegging, anal sex, and bdsm Explicit

Frequently Asked Questions

How long is this episode of Ruby Rogues?

This episode is 45 minutes long.

When was this Ruby Rogues episode published?

This episode was published on July 11, 2017.

What is this episode about?

RR 318 Metaprogramming with Jordan HudgensToday's Ruby Rogues podcast features Metaprogramming with Jordan Hudgens. We have panelists Jerome Hardaway, Brian Hogan, Dave Kimura and Charles Max Wood. Tune in and learn more about...

Can I download this Ruby Rogues episode?

Yes, you can download this episode by clicking the download button on the episode player, or subscribe to the podcast in your preferred podcast app for automatic downloads.
URL copied to clipboard!