Talks

The Case Of The Vanished Variable - A Ruby Mystery Story

After a stressful couple of days at work, Deirdre Bug is looking forward to a quiet evening in. But her plans are thwarted when the phone rings. “I know I’m the last person you want to hear from…but...I need your help!” Follow Deirdre as she embarks on an adventure that features a looming Demo Day with serious prize money up for grabs, a trip inside the walls of one of the Ruby community’s most revered institutions, and some broken code that appears to be much more simple than meets the eye.

RubyConf Mini 2022

00:00:19.619 happy face when you attend Ryan Ruby um we've been to multiple ruby and rails
00:00:25.439 comps together and as the token Brits we sort of tend to hang out together sit at the front and sort of affirm and support
00:00:32.579 each other as we talk nonsense with a microphone um plus we bicker like an old married
00:00:37.620 couple when we're at conferences um we first met in 2013 when I was
00:00:42.719 invited for drinks with a guy called JB was opening the pivotal Labs office in London uh and I met this ferociously
00:00:50.280 intelligent young woman who had just finished makers Academy which is one of the london-based boot camps
00:00:56.219 so I slidled up to JB and I said she's amazing I would love to hire
00:01:04.140 I think she'd be really really great to work with and JB smiled and said I already have
00:01:11.939 damn it and so I've never had the chance to work with her and post pivotal Labs she's
00:01:17.460 been doing her own stuff which you'll hear about hear about soon so Nadia is a proud rubiest
00:01:24.060 a podcaster a dancer an ambitious entrepreneur taking on Amazon pretty much like single-handed
00:01:30.780 and most importantly
00:01:35.820 most importantly and fortunately for me my friend and now your keynote speaker Nadia o'donaya
00:01:56.360 it's such an honor to be keynoting Ruby company thank you Gemma Emily and Andy
00:02:02.100 for having me do this and thank you for the lovely introduction Andy so I'm Nadia Oda Isle I'm the founder and CEO
00:02:09.239 of a company called the story graph are we thanks
00:02:16.140 a Reading Tracker and book recommendations app we help you to choose your next book
00:02:21.480 based on your mood and your favorite topics and themes we've got a whole range of stats where
00:02:28.200 you can learn about your reading habits and see how they develop over time we've got machine learning powered
00:02:34.920 personalized recommendations it's like a trusted go-to friend who knows your preferences but whose brain is also a
00:02:42.239 book Encyclopedia you can find your next perfect read by filtering lists of books by mood Pace
00:02:50.040 fiction versus non-fiction genre book size and more
00:02:55.440 you can also read alongside friends adding live reactions to specific parts
00:03:00.720 of the book and the comments remain locked until your friends reach that specific specific part in their reading
00:03:08.040 and there's a whole lot more on offer we have three million unique monthly
00:03:15.000 visitors 36 million Pages a month and each month we serve 110 million
00:03:22.620 requests people often ask what is story golf built in and I love that I can say good
00:03:29.940 old review on Rails
00:03:37.019 and with all of the website and app activity we get a lot of customer feedback feature requests and Bug
00:03:43.920 reports given that I run the company's Instagram and Twitter accounts I'll often receive
00:03:49.980 messages that include something like if you could pass this onto your Dev team that would be great
00:03:57.599 while I have an absolutely awesome co-founder in Rob freelo the web and app
00:04:03.599 Dev team is made up of just me in fact I recently gave a talk at the
00:04:10.620 inaugural rail SAS conference run by Andrew Culver held in La last month my talk was titled getting to 1 million
00:04:18.359 users as a one-woman Dev team I spoke about the ups and downs in building storygraph and there were some
00:04:25.500 real stressful moments in this journey some real dark times where I felt stuck
00:04:30.660 where I questioned whether I could keep going and as the talk blurb says it was a
00:04:37.199 personal intimate story but
00:04:43.080 I saved the real intimate details for the rubyconf mini audience
00:04:49.320 I have a secret don't tell anybody you see despite all of the focused hard
00:04:56.340 work and stress that went into building storygraph into what it is today I couldn't help but keep up a little
00:05:02.940 side gig I'm not just the founder CEO and sole
00:05:08.580 developer of the story graph I'm also a private investigator
00:05:14.960 and what is it I investigate you ask Ruby crimes not Jewel theft I
00:05:23.220 investigate crimes and Mysteries relating to our favorite programming language
00:05:28.500 why go into private investigating well there'd been rumors circulating of a
00:05:34.860 shady Mastermind causing havoc and confusion amongst Ruby developers worldwide with his constant meddling in
00:05:40.860 the source code I wanted to be the one to put a stop to him
00:05:46.160 oh and I'm sure all of us know just how lucrative the world of Ruby private
00:05:51.600 investigating is I decided that I couldn't do this side gig under my
00:05:57.240 normal name no I needed to protect my identity so I decided to call my Ruby private
00:06:03.539 investigating Alter Ego Deirdre bug D for sure why well
00:06:10.680 isn't it rather obvious now I've got several stories from my years
00:06:17.520 of doing this work but for today's Keynote I thought I should tell you all about a
00:06:22.800 case that happened within the very walls of one of our communities most revered beloved institutions
00:06:29.580 this is the case of the vanished variable chapter one
00:06:35.940 it was June of last year I'd had an incredibly stressful couple of days at storygraph
00:06:42.900 Rob and I had just finished dealing with our first experience of serious online controversy around our product
00:06:49.860 our content warnings feature came under Fire after a series of well-known authors brought to light that inaccurate
00:06:56.639 warnings were being attached to their books things were going wild on Twitter
00:07:04.440 Rob and I stayed calm and modified the Twitter situation before coming up with
00:07:09.600 a proposal for adjusting our system we sought feedback from the community
00:07:15.539 and after our ideas were received positively I coded all day and night to implement the changes
00:07:22.259 it was a wild and stressful time but we pulled through being the sole software developer though
00:07:29.639 this had really wiped me out despite knowing that it wasn't the case I'd felt personally attacked in all of
00:07:36.780 this I needed a break from storygraph and I was in the process of planning a
00:07:42.900 relaxed evening when the phone rang immediately upon answering I heard a
00:07:48.060 breathless anxious voice say I know I'm the last person you want to hear from
00:07:53.940 but I need your help oh I recognize that voice how could I
00:07:59.039 forget it Jenny who's Jenny some of you may be wondering
00:08:05.039 she was 29. a seasoned Ruby developer who was obsessed with all things rails
00:08:11.580 she also betrayed her best friend during one of my earlier cases by giving him
00:08:17.039 faulty information about how Ruby method lookup worked I'd heard through the
00:08:22.199 grapevine that she'd learned the error of her ways and was on a good path now but I was hesitant to trust her
00:08:28.800 Jenny worked for the famous world-renowned Ruby Institute of professionals
00:08:35.039 the organization whose whole reason for existing was to see to it that the Ruby language and Community stayed Alive and
00:08:42.000 Kicking forever slightly unfortunate logo anyway
00:08:47.100 it was a job related issue that had Jenny calling me that day you see the rip had started up this new internal
00:08:53.399 incubator a competition of sorts all within the organization's aim of
00:08:58.980 improving Ruby's image and usage worldwide people within the organization could get
00:09:04.560 into teams and submit various startup ideas the winning team would win a 500 000
00:09:11.100 investment and the opportunity to work on their startup full-time fully supported by the rip
00:09:18.300 and for the very first round of this Jenny Steve had made it into the final two
00:09:24.420 we're building a platform that assigns grants from a pool of money that the rip has available for this kind of thing
00:09:30.540 they'd go to fund Ruby developers and organizations there are three different types of award
00:09:36.300 on offer that vary in Grant size and can go towards different types of projects
00:09:41.820 for our demo we simulate an automated draw for the grants including doing
00:09:46.920 multiple redraws until the maximum number of Grants has been assigned
00:09:52.260 but the number of awarded grants came out incorrectly in the semi-final today which was embarrassing
00:09:57.720 we thought we'd be out but the judges put us through it's so close between the final two
00:10:03.540 teams but the judges will be looking for any reason to disqualify one of us but here's the problem
00:10:09.959 and genocides heavily at this point our lead Dev Alex is now very stressed
00:10:16.680 and he won't admit that he needs a second pair of eyes we're the only two devs on the team and
00:10:22.620 not only do I have other jobs to get on with I really hate working with him
00:10:28.200 the final is tomorrow and there's only a few hours left to get to the bottom of this
00:10:33.420 we need you he finished I was quiet while I thought about it
00:10:39.839 Not only was I wary of helping Jenny out knowing her dishonest past
00:10:45.000 or my incredibly stressful couple of days at storygraph I was meant to be relaxing
00:10:50.760 but well debug can never resist a challenge and
00:10:55.860 it's never a good idea to pass up an opportunity to go into the rip after all
00:11:02.160 I was sure they'd pay me handsomely for my work I agreed to take on the case
00:11:10.440 chapter two I don't need help Alex said bluntly after listening to
00:11:17.579 Jenny's explanation of why I was there he sat in his office chair with his arms crossed a mix between sulking and
00:11:24.420 glaring Jenny started to protest but I had an idea
00:11:30.480 I dealt with this type several times before you know the self-proclaimed 10x
00:11:36.300 hero developer who knew everything and declared that they could solve all of the company's problems in an afternoon
00:11:41.940 if only people would leave them alone I knew what would loosen him up a little
00:11:48.120 I'll tell you what Alex I said I won't distract you I won't say much I won't
00:11:53.579 touch the keyboard I'll just sit next to you and be your rubber duck
00:11:59.100 you can just talk me through the code in the bug bounce ideas off of me of course
00:12:04.260 you'll find the solution by yourself and you'll get all the credit but this way you'll find the bug quicker and time is
00:12:11.459 of the essence we're all silent while Alex thinks about it frowning before finally saying fine
00:12:21.959 Alex had already turned back to his keyboard as Jenny gave me a subtle triumphant fist pump and said she'll
00:12:27.360 leave us to it as I go to take my seat next to Alex though he Brusly puts an arm out to stop
00:12:32.579 me I just realized that I can't show you the code base as is he says
00:12:37.860 there's confidential code in here from some of Rip's clients and partners let me get rid of it
00:12:43.920 I was wary that a couple of hours had already passed since Jenny's call but I couldn't really argue with the issue of
00:12:50.220 me seeing potentially sensitive client information so I instead pulled up a chair a couple
00:12:55.440 seats down from Alex I decided to make the best use of my time by opening up Duolingo after all
00:13:03.660 there was no way I was going to take down the Shady Mastermind if I didn't stay on top of my Japanese right
00:13:12.540 40 minutes later and Alex is finally ready to show me the code now I'm only showing you a simplified
00:13:18.600 version of what I saw that day first each award type had its own file
00:13:24.120 that looked like this here Alex had defined a class named
00:13:29.160 award a which inherited from another class called Grant then there was a class instance variable
00:13:35.579 called award count which was set to zero there was a class method also called
00:13:41.339 award count which returned the value of the class instance variable then there was a method called assign
00:13:48.959 which incremented the award calc class instance variable by one and Alex quickly showed me how the files
00:13:55.740 of the other two award types were exactly the same except for a change in
00:14:01.260 class name and then there was the grant class itself
00:14:06.720 there was a constant called Max grants which was set to 100. the grant class had its own award count
00:14:13.560 class instance variable which didn't seem to be being used anywhere the grant class also had its own award
00:14:20.399 count class method which added up the award count on all three award types
00:14:26.459 then there was an awards remaining class method which was used in the redraw to
00:14:31.500 figure out how many awards still needed to be assigned it took the maximum number of Grants
00:14:37.200 permitted and subtracted the number of awards that had already been given out
00:14:42.540 then there were scripts that assigned some awards 50 lots of award a
00:14:48.240 30 lots of award B and 20 lots of awards C
00:14:53.639 and finally a script that checked how many prizes were left and then performed a redraw if necessary
00:15:01.260 so remember in the code Alex showed me there were a maximum of 100 grants that
00:15:07.260 could be awarded and 50 plus 30 plus 20
00:15:12.540 equals 100 which equals the maximum number of grants that were available
00:15:19.620 are you following so far or do you need me to go over it again Alex asked no I got it I told him
00:15:27.300 if anything I'd been holding back from suggesting places where his code could have done
00:15:32.519 with some improvements I mean that wasn't normally my style usually I just focus on the problem at
00:15:39.480 hand and avoid making quick judgments about the quality of unfamiliar code bases but Alex's Behavior was
00:15:46.680 frustrating anyway on the whole his code looks straightforward I couldn't see what
00:15:53.279 could go wrong Alex ran the scripts
00:16:06.899 what 300 Grants awarded maximum number of Grants exceeded
00:16:15.660 what a mystery chapter three
00:16:21.300 I spent a few moments feeling baffled before I remembered that I was the great
00:16:26.820 debug a private investigator I had to stay calm and focused and I had to play
00:16:32.699 my cards with Alex carefully he seemed to be opening up to me so my strategy
00:16:38.040 was to let him keep driving and to slowly nudge him into what would hopefully turn out to be the right
00:16:43.740 direction something had stuck out to me during the code demo the cloth instance variables
00:16:51.000 now I thought that class instance variables belong to one specific class only but the four classes all had one
00:16:59.459 with the same name given that the three award classes all inherited from Grant and we had three
00:17:06.780 times as many awards being assigned I wondered if some overwriting was occurring
00:17:12.959 what if I said cautiously to Alex each class were to have a differently
00:17:18.780 named class instance variable perhaps they're all conflicting with one another
00:17:24.000 Alex glared at his display as if he hadn't heard me but then he Shrugged and said sure we
00:17:30.299 can try that and so he took each award class and adapted the name of their class instance
00:17:36.299 variable to include some reference to its type like so he then run the program again
00:17:51.539 same result so it wasn't the fact that the class
00:17:57.900 instance variables with the same name in one inheritance chain were interfering with one another they did in fact as I'd
00:18:05.160 understood stick to their own classes I was wondering what to suggest next
00:18:10.380 when we were interrupted by one of Alex's colleagues Alex he said you'll never guess who's in
00:18:16.679 the office we both turned up to look at him Max
00:18:24.179 maths maths maths maths everybody loved him
00:18:31.140 but I knew different I knew he was not to be trusted
00:18:36.720 but in that moment his appearance worked in my favor because the way Alex jumped
00:18:42.539 up and sprinted away from the computer towards wherever Max was you'd think he'd heard that somebody had dropped a
00:18:48.660 billion dollars on the floor and the first person to pick it up got to keep it but I didn't care because finally I
00:18:55.440 could get my hands on the keyboard Alex's fancy clacky keyboard with no
00:19:01.500 labels on the keycaps didn't phase me oh no now I could finally do what I did
00:19:08.100 best solve this mystery while I'm all over what to try I
00:19:15.000 immediately out of habit because of my excellent git hygiene if I do say so myself
00:19:21.000 type get status into the terminal there were changes in the repo so I type in git diff and I'm casually looking
00:19:27.780 over the output before it hits me oops I probably shouldn't be looking at this there might be client data in here that
00:19:34.260 the rip don't want me to see and so I quickly exit but not before something catches my eye
00:19:42.200 151 lines added to this simple script that Alex had created to demonstrate the
00:19:47.340 bug but the file that we had been looking at had only been a few lines long
00:19:53.640 I quickly tabbed over to the filing question hit command on the down arrow to jump to the bottom of the file and
00:19:59.580 this is what I see the grant class had been reopened the
00:20:04.740 class instance variable award count had been overwritten to be 300 and the class method Now read from the class instance
00:20:11.520 variable directly no wonder that what are you looking at Alex had returned and wasn't too happy
00:20:18.299 to see me sitting in his chair touching his keyboard he looks over my shoulder at the screen and sees what I'm looking at
00:20:25.679 he looked a little alarmed at first before confusion took over
00:20:30.900 uh where did you get my old code from he asks suspiciously
00:20:36.120 that's from an old demo well it was right at the bottom of this file I say
00:20:42.179 and all of a sudden Alex starts to look incredibly embarrassed like he wants the
00:20:47.460 ground to swallow him up he explains how when he was getting the repo ready for me he'd been making quick edits copied
00:20:54.419 and pasted a bunch of code from one place to the next by selecting the whole file then deleting whole swathes of it
00:21:00.600 and must not have noticed this bit of code being left behind in his haste but I say
00:21:07.980 this code must have been hanging around for a while surely you would have noticed it unless
00:21:15.539 you never do parcel commits
00:21:22.700 now copy and paste errors can happen to the best of us I've certainly been caught out by them
00:21:28.620 before I have to admit though after his behavior throughout the day it was
00:21:33.659 rather nice seeing Alex humbled a bit but however trivial the bug a case isn't
00:21:40.860 over until I see the code working and so I deleted the code from the bottom of the script and ran the program again
00:21:57.020 while it didn't end up being a meaty problem to sink my teeth into and distract me from my stressful storygraph
00:22:03.659 situation the case was closed my work here was done
00:22:09.659 chapter four I was on my way out of the rip building when I hear someone call my name
00:22:16.559 it's Jenny I've just heard from Alex that the two of you have figured out what the issue is she says he's gone off to go and
00:22:23.760 implement the changes now I'm not the Told You So type
00:22:29.280 but it was the class variables wasn't it I knew that him using them was a bad idea
00:22:35.460 you mean class instance variables I say no class variables says Jenny
00:22:42.900 you don't mean class instance variables I ask because there wasn't a single class
00:22:48.000 variable in sight Jenny only class instance variables and I don't want to like the expression
00:22:54.360 that Jenny starts to give me do you have time to come back upstairs please she asks I'm not I want to get to
00:23:02.280 the bottom of this confusion we head to her desk where she starts to fetch the latest code from GitHub and I
00:23:08.760 tell her to be careful so that I don't see any confidential code and she says what there's nothing confidential in
00:23:14.880 here we started up a whole new code base for this project and now it's my turn to raise my eyebrow
00:23:22.340 but it's not long before the expression on my face turns into one of shock because Jenny is now showing me the code
00:23:29.280 and it looks exactly the same as the code that Alex showed me except for the fact that all of the class instance
00:23:36.059 variables in the award classes are in fact class variables and the grant class no longer has its
00:23:43.559 class instance variable apart from that it looked the same let's run the code I see
00:24:01.380 okay so it still works but hey check this out I say to Jenny
00:24:07.140 pointing at something in the web browser tab that's visible behind the terminal
00:24:12.179 Alex had made a commit 14 minutes ago it was a one-line change
00:24:17.640 he'd removed a line from the grant class so before his last commit the grant
00:24:22.860 class instead of looking like this looked like this the grant class also had a class
00:24:29.880 variable let's run this code I say I had my
00:24:35.280 suspicions
00:24:45.539 and my suspicions were proven correct this code failed in exactly the same way
00:24:50.940 as the earlier bug that Alex had presented to me and now I'm really confused
00:24:58.320 so there was in fact a bug but Alex knew how to fix it all along but didn't tell
00:25:04.200 his teammates and then gave me a fake problem to solve when I came in
00:25:09.900 let's go and find Alex and get to the bottom of this journey suggests it's past 8 p.m and there's hardly
00:25:16.440 anybody left in the office Alex is not at his desk he's not in the kitchen he's not playing ping pong Max
00:25:24.120 is gone so we know he's not somewhere falling over him I spot the colleague who'd come over
00:25:29.520 earlier we asked if he's seeing Alex anywhere I just saw him he was trying to find a
00:25:35.820 quiet corner to take a personal call we hurried off in the rough Direction the colleague gestured to planning to
00:25:42.240 grab Alex as soon as he came off the phone and we were about to turn a corner when we heard snatches of hushed
00:25:48.539 dialogue Zoe they almost caught me
00:25:54.179 even brought in a private investigator faked some code for fun and to buy time
00:26:02.460 Jenny will be nosy so I fixed the real code for now but don't worry honey
00:26:08.760 I'll put the bug back in before the final tomorrow my eyes widened Jenny gaped at me before
00:26:15.720 we rounded the corner to confront Alex and then it was his turn to look absolutely mortified
00:26:24.419 chapter five it's two hours later and I'm sitting with Jenny at her desk thinking over
00:26:29.760 everything that I managed to piece together after my interrogation of Alex
00:26:35.460 so Alex is dating another of your colleagues Zoe and Zoe is in the team
00:26:41.820 competing with yours for the final 500 000 prize at some point throughout this whole thing Alex became fed up with your
00:26:49.020 team and your idea much prefers Zoe's team's idea which he had a hand in coming up with and he wants them to win
00:26:55.799 so that he can go and work on that team alongside his girlfriend and so he set out to sabotage his own team by
00:27:02.460 introducing a bug to the code but anybody who had a chance to look at the code would have immediately suspected
00:27:07.980 the class variables and so he sent me on a wild goose chase and a bid to waste time instead
00:27:14.580 yeah wow so much Ruby drama
00:27:21.559 here I was trying to escape drama in my day job and instead I ended up in yet
00:27:26.580 another mess during my side gig I said goodbye to Jenny and headed home
00:27:32.400 knowing that despite the hour my night wasn't over as soon as I got in I went straight to
00:27:39.059 my computer and opened up a prize session I had things to investigate
00:27:44.640 first I created a class called Grant which had a class variable named type which returned Grant
00:27:50.460 I also defined a class method name type which Returns the value of the class variable
00:27:56.400 then I created an award a class which inherited from Grant and looked exactly the same as its parents class except for
00:28:03.419 the fact that the class variable type was set to a So based on what I'd seen earlier if my
00:28:10.440 suspicions were correct then Not only would award a type return a but now Grant type would return a to
00:28:22.260 I was indeed correct unlike class instance variables which have their own separate copy no matter
00:28:29.039 the inheritance chain class variables seem to share a value amongst objects in a chain
00:28:36.980 doesn't matter which direction I go in I wanted I had created a subclass and set a class
00:28:43.799 variable with the same name there what if I reopened Grant's superclass and set the class variable there too I
00:28:51.840 confirmed that Grant superclass was object and then we opened the object class giving it the same class variables
00:28:58.380 and class method as Grant and award a so object type returned object and
00:29:06.000 ground type return to the wrong time error class variable type of Grant is overtaken by object
00:29:12.840 what about award a type exactly the same error including the
00:29:18.179 reference to Grant okay so it looks like with class variables of the same name there's
00:29:24.360 definitely only one value shared in The Inheritance chain referred to from only one class in the chain but you can only
00:29:31.620 set them in one direction if you reopen a superclass and define a class variable
00:29:37.260 that's already been defined in any subclass it raises a runtime error in those subclasses
00:29:44.460 I then wondered how far up the inheritance chain Ruby went looking for class variable definitions
00:29:50.399 I first confirmed that the highest class in Grant's inheritance chain was basic object before reopening the class and
00:29:56.580 giving it the same class variable and Method its type being basic of course
00:30:04.559 Yep looks like Ruby goes all the way up to basic object when dealing with class variables
00:30:10.320 now at this point I had a lot in my head and I don't know about how your work but I always find
00:30:16.140 diagrams so helpful so it was time to sketch out what I pieced together and see if it matched up with the behavior
00:30:22.440 in Alex's code first I knew that in the C Ruby internals for every Ruby class there's a
00:30:30.120 corresponding r-class structure this stores things like a table of the classes methods its attribute names and
00:30:37.140 also a table of class instance variables I assumed that there was another table
00:30:42.840 for class variables so if I took the grant class from Alex's code we'd have an R cloth structure that
00:30:49.860 looked like this with an entry for award count in the class variables table
00:30:55.440 when the award classes were first defined including the setting of a class variable with the same name there were
00:31:02.100 no problems initially my prize session had indicated that Ruby journeyed up the entire inheritance
00:31:08.700 Chain Looking for the highest superclass that had the same class variable set there and then over the value
00:31:16.200 in Alex's code all of the classes had the same initial value for award count
00:31:21.419 zero but then the scripts had started assigning Awards and this was where the
00:31:28.380 behavior of class variables had started to cause issues every time an award of one type was
00:31:34.140 assigned the value of the award count class variable was incremented by one
00:31:39.899 so after 50 lots of award a had been given out it was the one and only stored
00:31:45.000 value of the class variable on the grant class that was being updated
00:31:50.640 so after the first script had been run when the scripts had been called when these called award count on method a it
00:31:57.000 had correctly returned 50. the calling the same method on award B and C would
00:32:03.120 have also yielded the same result despite the fact that we'd not actually awarded any grants of type B or C yet
00:32:10.740 and then we had the script that awarded 30 lots of award B and the one copy of the class variable
00:32:16.559 gets incremented 30 more times and by the time we award the final 20 lots of award C we have this
00:32:25.200 so when the final redraw script was run an award count was called on the grant class which adds up the result of the
00:32:32.340 same method on the three award types three lots of 100 equals 300 which
00:32:37.820 exactly matched the bug in Alex's code
00:32:44.760 I was feeling rather pleased with myself having pieced this together but I wanted someone a teeny bit wiser
00:32:52.320 than I was to verify that I'd got it exactly right luckily I knew just the person
00:33:00.240 chapter six despite the hour I wasn't surprised that my contact replied straight away saying
00:33:07.140 she'd be up for jumping on a video call with me to talk about class variables who was I speaking to
00:33:12.779 Ellen now who on Earth is Ellen some of you may be wondering Ellen was 45 and experienced freelance
00:33:20.760 developer who'd seen many things and who regularly brought what she'd learned on her adventures to the Ruby code base
00:33:27.899 I talk her through my diagrams including the bug I had been dealing with and the general picture I put together on how
00:33:34.260 class variables worked did I get it right I asked
00:33:39.539 Yes except for one small thing Ellen says toss instance variables and class
00:33:46.500 variables are actually stored in the same table in the R class structure
00:33:52.440 the extra at symbol on class variables means that they don't get mixed up okay cool I say but there's been
00:34:00.720 something on my mind Ellen class variables only seem to cause a lot
00:34:05.820 of trouble what are they good for well it says Ellen they're really good
00:34:11.580 for application configuration in fact your favorite framework rails
00:34:16.919 uses them extensively for that very thing okay fine but that's a whole framework
00:34:24.540 the everyday developer doesn't have to care about them right well says Ellen
00:34:31.200 let me tell you a story you discovered today during your investigations that when accessing a
00:34:38.460 class variable Ruby will go up the whole inheritance chain all the way up to basic object in order to check which
00:34:45.599 class was the highest to set the variable right well Eileen uchatel of the Rails core team
00:34:52.859 and Aaron Patterson who is on both the rails and Ruby core teams wanted to dig into this fact some more
00:34:59.760 the bug that you dealt with at the rip today only featured an inheritance chain that was two levels deep
00:35:06.720 but Eileen and Aaron with their expert knowledge of Regal's internals knew that
00:35:11.820 not only did rails make extensive use of class variables The Inheritance changed
00:35:16.920 there went a lot deeper
00:35:24.780 surely rails is extensive use of class variables was incredibly inefficient and
00:35:31.920 might be having a performance impact on Rails apps everywhere much more efficient would be if instead
00:35:38.579 of going up the entire inheritance chain each time to check for the highest superclass within which a class variable
00:35:44.880 was set there was instead a cache and so
00:35:50.700 that's what they built with the cash instead of Ruby checking every single class in The Inheritance
00:35:57.960 chain when trying to find the value of a class variable the method points to a
00:36:03.480 cache which tells your code exactly where to look for the class variable setup
00:36:09.480 and after testing that there was indeed a performance improvement with this cache Eileen and Aaron submitted a PR
00:36:16.200 for Ruby that got merged in just the other day because these two took the time to
00:36:22.859 understand how things worked under the hood and then developed this change with Ruby 3.1 rails apps can see a six
00:36:31.560 to seven percent request throughput performance increase now
00:36:37.380 why did I tell you this story Ellen asks me well
00:36:42.839 people are always saying things like Ruby is slow Ruby doesn't scale
00:36:50.339 Ruby is dying and I've had a lot of conversations with Eileen about this and I know how she
00:36:56.940 feels about it and I feel the same
00:37:02.520 you see if only more of us took the time to learn Ruby really learn Ruby
00:37:08.280 and understand how it works under the hood understand why it is the way it is and
00:37:14.339 get to grips with all of its quirks and gotchas then we'll be able to spot pain points
00:37:19.500 and opportunities for us to improve Ruby and make it faster make it great for
00:37:25.440 scaling apps and so much more if we spot things that we don't like
00:37:30.660 about Ruby or think something could be better instead of complaining about it
00:37:36.780 we should be much more like Eileen and Aaron investigating experimenting benchmarking
00:37:43.200 building and fostering conversations in the community we should be doing all of the things
00:37:49.800 that'll help keep Ruby alive make Ruby a no-brainer tool of choice
00:37:55.320 for developers and organizations at all stages for decades to come
00:38:02.339 as with any conversation with Ellen I left it feeling super inspired
00:38:08.280 there and then I vowed that whenever I got time away from storygraph even
00:38:13.980 though it wasn't often I would continue striving to understand how Ruby behaved under the hood and do
00:38:20.940 what extra I could to contribute to the amazing language and community
00:38:34.520 thank you