Summarized using AI

How to Break into Reading Open Source

Kasper Timm Hansen • September 13, 2024 • Sarajevo, Bosnia and Herzegovina • Talk

The video titled How to Break into Reading Open Source featuring Kasper Timm Hansen at EuRuKo 2024 explores the importance and strategies for reading open-source code. Hansen emphasizes the wealth of knowledge found in open-source projects and presents a guide for developers eager to learn from others' code.

During the session, he shares his personal journey of reading code since he began with Rails as part of Google Summer of Code in 2013. The following key points are highlighted throughout the presentation:

  • Two Reading Modes: Hansen introduces two modes of reading open source code: Ahead of Time and Just in Time.

    • Ahead of Time: This involves exploring code at your leisure, which enhances familiarity with new syntax, techniques, and concepts. This mode is beneficial for general learning and better prepares you for debugging in the future.
    • Just in Time: This mode is reactive; you dive into the code when an issue arises, such as when debugging or upgrading. Preparation helps ease the stress encountered in this mode.
  • Practical Example from Rails: Hansen recounts his early ambition to read the entirety of Rails, introducing actions and code structures within gems like Active Support. Breaking down how 'blank?' and 'present?' methods work encourages learning through exploration.

  • Key Principles for Reading:

    • Just Click Things: Encourages curiosity and exploration without immediate pressure to understand everything.
    • Remain Neutral: Advises against self-judgment when facing difficult code. Emphasizes that learning to read code is a process.
    • Keep Coming Back: Promotes regular practice and revisiting the codebase to gradually build understanding.
  • Learning from Errors: Hansen illustrates a recent debugging scenario where understanding concepts from previously read code (such as YAML parsing) proved crucial in solving a problem with the ‘audited’ method in a migration context.

Hansen concludes with the message that reading open-source code is not a daunting task but an achievable and rewarding skill that enhances a developer's toolkit. He encourages viewers to immerse themselves in code and remain curious, reinforcing that the knowledge gained from exploring such code can significantly improve their coding proficiency. With practical examples and a relatable approach, Hansen equips attendees with actionable steps to demystify the world of open-source software and empowered learning.

How to Break into Reading Open Source
Kasper Timm Hansen • Sarajevo, Bosnia and Herzegovina • Talk

Date: September 13, 2024
Published: January 13, 2025
Announced: unknown

There's a treasure trove of code that you could learn from hiding in plain sight: Open Source.

By reading other people's code you can pick up new tricks, names, and concepts — and apply them to your code. You can even be exposed to things you'd never think of.

My journey reading Open Source for the hell of it started back in 2013, when I set out to read all of Rails as a Google Summer of Code student.

Join this session to see how I've grown my skills through reading and have the process demystified so you can too. You'll walk away knowing how to start breaking into even the gnarliest codebases.

EuRuKo 2024

00:00:10.160 uh hello everyone uh I'm Casper let's
00:00:12.240 see I'm just gonna get this finger let's
00:00:14.000 see um used to be on a rail score team
00:00:16.400 these days I just do Consulting focus on
00:00:18.640 Rails um and today I want to talk about
00:00:21.400 how we often as developers we end up
00:00:23.840 talking about writing code but today I
00:00:27.480 actually want to focus on just reading
00:00:30.240 see if we can do this part uh
00:00:31.840 specifically reading open source uh
00:00:34.640 because I've gotten a ton out of just
00:00:36.200 breaking open gems and seeing what's in
00:00:37.960 there and learning from what other
00:00:40.000 people have written um and I think this
00:00:41.440 could help you out a ton too and of
00:00:43.200 course with open source there's a vast
00:00:44.760 library of code you can read are you
00:00:47.719 good with levels okay let's see um
00:00:52.239 because in fact for Ruby there's over 18
00:00:54.039 180,000 gems so there's a ton of code
00:00:56.160 out there you could read and potentially
00:00:57.480 learn from and some of the things I've
00:00:59.680 got out of this is just seeing new Ruby
00:01:02.079 syntax in the wild how is endless
00:01:04.519 methods working or whatever how does it
00:01:06.040 look like new Ruby methods like a
00:01:07.880 repetition or things like that or New
00:01:10.400 Tricks here's how you can do something
00:01:12.960 maybe a in a way that's a little bit
00:01:15.200 more clever but still readable or new
00:01:17.119 names A New Concept and part of what I
00:01:19.720 do is I try to be a sponge when I'm in
00:01:21.560 something immerse myself in the library
00:01:23.600 and see what it's doing I just read
00:01:24.880 through it kind of um let's see so today
00:01:28.000 I want to Define sort of two two
00:01:30.200 different reading modes that I've sort
00:01:31.680 of used I'm borrowing a little bit of
00:01:33.520 from compiler language if you've seen
00:01:35.000 that where uh I like to read ahead of
00:01:37.560 time diving into a library kind of from
00:01:39.479 the top down and start breaking it a
00:01:41.479 little bit apart and see what it's doing
00:01:43.280 and then I also like to sort of readj in
00:01:44.920 time when you trying to figure out a bug
00:01:47.439 or something like that okay let's get
00:01:49.799 more to that so ahead of time is where
00:01:51.759 you open a gem or repositor what you can
00:01:53.880 you basically follow your interest if
00:01:55.560 you're not interested anymore you just
00:01:56.600 skip to something else and ahead of
00:01:58.560 times for Preparation and practice this
00:02:00.159 so it's both to learn new things like I
00:02:01.479 was talking about uh then you can then
00:02:03.439 use when you next set out to write code
00:02:05.119 but it's also to prepare you for reading
00:02:06.560 just in time for we get to that now just
00:02:09.879 time is what I Define as learning just
00:02:11.680 enough when you need it like when you're
00:02:13.160 upgrading a gym or figuring out a bug
00:02:15.959 for instance um but then when you're in
00:02:19.080 that mode of trying to figure something
00:02:20.720 out diving into and reading new code is
00:02:23.080 potentially quite stressful particular
00:02:25.400 if you're already frustrated or angry at
00:02:27.080 a difficult bug so this is where they
00:02:29.599 kind of work together where I like
00:02:31.280 reading ahead of time because that helps
00:02:32.800 prepare me to see new code if I'm then
00:02:35.239 having to debug something in a gym or
00:02:36.560 whatnot so I want to make sure this link
00:02:37.760 is clear enough so in Ruby we got
00:02:40.040 acronyms we got minus one of course so I
00:02:42.080 think I found out one that's that's just
00:02:44.159 as easy to remember uh basically I think
00:02:46.680 just room for one more and of course
00:02:48.159 it's super easy super simple um read
00:02:52.080 ahead of time so we can also read just
00:02:53.640 in time and it it's uh yeah exactly
00:02:56.000 super easy to pronounce uh you do you do
00:02:57.959 yourself um now where I read when I do
00:03:02.879 ahead of time I tend to do it just on
00:03:05.560 GitHub because it's um it's just less
00:03:08.480 friction than having to manage a copy or
00:03:10.280 whatever and github's UI these days I
00:03:11.680 find to be quite good at this and they
00:03:13.680 have like a symbol representation where
00:03:15.519 we click around and so
00:03:17.280 forth uh but then when I I do the just
00:03:19.920 in time reading I tend to just do bundle
00:03:22.080 open and if you don't know that you can
00:03:23.599 also soorry what anyway say or is it
00:03:26.840 like
00:03:27.640 feedback okay
00:03:30.319 cool so bundle open lets you basically
00:03:33.159 pop open a gem the one that you're using
00:03:35.120 in your app at the same version and
00:03:36.599 everything and then you can see the help
00:03:38.280 output if you want to here and you can
00:03:40.040 configure whatever editor you want for
00:03:41.640 that I just happen to have set set up as
00:03:43.680 default cool
00:03:46.280 see and then the reason I use bundle
00:03:48.680 openin is because I'm usually doing the
00:03:51.120 just in time reading where uh I want a
00:03:54.680 specific version of the gem that I'm
00:03:56.040 bundling because it's something in there
00:03:57.480 that I'm trying to debug so that's the
00:03:59.319 re
00:04:00.519 so today we'll cover three different
00:04:02.920 cases uh two ahead of time readings one
00:04:05.400 I did in rails at one point and
00:04:06.720 something I learned from mini test
00:04:07.920 reading that and in adjus in time case
00:04:10.840 that basically happened last week
00:04:12.079 actually where I healthy bug something
00:04:14.239 let see you can't see okay cool I saw a
00:04:17.120 notification on my screen
00:04:19.199 Barrow but I didn't show up there so
00:04:21.160 that's good fix uh let's
00:04:24.160 see okay so I want to walk back to how
00:04:26.240 this started for me when I first got
00:04:27.479 into just reading things um BAS
00:04:29.720 basically in
00:04:30.880 2013 Google runs this thing every year
00:04:33.440 that's called the summer code where they
00:04:35.000 pay a student to work on open source for
00:04:37.400 a summer I saw rails for participating
00:04:39.840 and so for two weeks I worked on a
00:04:41.360 proposal submitted it in and then I got
00:04:43.680 picked to do it essentially can you see
00:04:46.039 that okay announcement back in 2013 I'm
00:04:48.960 at the bottom there there was one more I
00:04:50.400 couldn't fit in but um yeah something to
00:04:53.360 do with uh HTML sanitization and so
00:04:55.240 forth so as prep I figured I'll just
00:04:58.880 read all the rails
00:05:00.720 it probably be easy right I'll just
00:05:02.120 start from one end read all the way
00:05:03.360 through I'll just read ahead of time and
00:05:04.960 it'll be fine but then even in 2014
00:05:07.400 there's a ton of code in there so I
00:05:09.240 don't know why I thought this was
00:05:10.440 possible it was just you know being a
00:05:12.400 junior I guess um so when I showed Tom
00:05:14.639 as a friend of mine he basically
00:05:15.720 described as what a truly dumb heroic
00:05:17.600 Endeavor um and I really like that
00:05:19.400 phrasing for it but anyway I want to
00:05:22.360 replicate what that actually looked like
00:05:24.199 just a starting point of it so I think
00:05:25.600 we should just proceed uh basically so a
00:05:29.240 tiny bit more background before we get
00:05:30.840 to what it looks like just how rails is
00:05:33.680 actually configured or set up uh it just
00:05:35.880 bundles other gems basically what we
00:05:38.840 need to for now and back in 2014 there
00:05:41.199 was these libraries in there action pack
00:05:43.680 action controll is basically would in
00:05:45.440 there and action view as well and
00:05:47.639 there's AC dis as routes mailer for what
00:05:49.960 you send out with mailers rail TI sies
00:05:51.880 everything together uh active record you
00:05:54.280 probably know active support is in the
00:05:56.319 one I knew about because it's a lot of a
00:05:59.840 fogal small things so it's easy to read
00:06:02.919 so let's
00:06:04.800 see okay I think we're up to okay so now
00:06:08.039 I got to do something here let's see got
00:06:11.840 and go back to mirroring okay and then I
00:06:15.039 found where was the window so basically
00:06:17.400 what happened was okay I think read is
00:06:19.520 okay so I just went to rails rails on
00:06:22.440 GitHub uh like 11 years ago and then
00:06:26.280 clicked on active support which is right
00:06:28.560 here and I wa for that to
00:06:31.560 load okay okay cool and then there's a
00:06:34.840 bunch of files in here we don't have to
00:06:36.199 care about I'm just going to show you
00:06:37.400 where blank and present live essentially
00:06:40.039 so we're going to dive into the lip
00:06:41.639 directory and we're going to dive
00:06:43.479 further into the active support sort of
00:06:45.560 nested structure here and then we want
00:06:47.680 to go into the corex folder and when I
00:06:50.800 was doing this like 11 years ago I was
00:06:52.680 just clicking with regular with Reckless
00:06:54.199 abandon it just seeing what happened and
00:06:55.840 what was in there we'll get to more that
00:06:57.599 in a second so see I think it's an
00:07:00.520 object actually blank there we
00:07:04.319 go and so this is the default
00:07:06.319 implementation there's some overrides
00:07:08.440 since 2014 for um active record itself
00:07:12.919 that sort of optimizes a little bit but
00:07:14.919 this is what they actually look like so
00:07:16.240 you probably Ed blank before if you Ed
00:07:17.680 rails or present as well and here's
00:07:20.199 where they are so not too scary in this
00:07:22.879 case to dive into it um cool so's the
00:07:27.440 first bit I think let's see got to jump
00:07:29.319 back
00:07:30.440 okay
00:07:33.599 okay and
00:07:36.319 then okay cool
00:07:38.759 perfect so see here summary we went to
00:07:41.639 rails rails we clicked on active support
00:07:43.720 and drilled into it a little bit more
00:07:45.039 then we read what blank and present
00:07:47.240 do um so in my case this went on for a
00:07:50.879 while I was just clicking through
00:07:52.199 reading things seeing what was in there
00:07:54.360 and then I ended up you know giving up
00:07:56.720 on trying to read rails because there's
00:07:58.000 a lot of code there um I didn't need it
00:08:00.360 for the product I was doing at the time
00:08:02.000 that was just an action view so it's
00:08:03.360 just I don't need it right now but I
00:08:05.199 still learned a ton from just diving in
00:08:07.400 and seeing what was in there and what
00:08:09.639 stuck with me from doing this was that
00:08:11.680 it's not about getting it 100% uh really
00:08:15.199 it's about taking advantage of the fact
00:08:16.720 that open source isn't a blackbox quite
00:08:18.759 literally you can open up and start
00:08:20.479 reading the source so in my case I
00:08:23.919 suggest is reading the parts you can and
00:08:25.680 then you want to come back and then read
00:08:27.319 more or go read something else and
00:08:30.039 what you've learned from that then helps
00:08:31.319 you read the other part and all of this
00:08:32.959 stuff helps you read what you do in your
00:08:35.760 every day so it makes that code easier
00:08:37.279 as well it's just less of a potential
00:08:38.800 lift if you will um and for my case what
00:08:41.880 I'm doing ISU I've come up with a few
00:08:43.240 reading principles that I kind of keep
00:08:44.600 to as I Was preparing this talk
00:08:46.680 basically the first one is to just click
00:08:48.640 things just see what happens
00:08:51.800 um I'm actually going to dive into a
00:08:53.720 little bit more later okay and then you
00:08:55.160 want to remain neutral and then you want
00:08:56.360 to keep coming back so let's dive into
00:08:58.560 what they mean for me when I say just
00:09:00.560 click things it is just kind of what I'm
00:09:02.399 doing in a demo like we don't have time
00:09:04.120 to show all of it but it's just clicking
00:09:05.440 around see what happens click on a
00:09:07.200 method click on a file see what's in
00:09:08.920 there and just basically be curious and
00:09:11.160 see I wonder what's in here okay um and
00:09:13.720 you're not necessarily looking for
00:09:14.880 anything particular you're kind of just
00:09:16.240 following your interest and at some
00:09:18.519 point something you haven't seen before
00:09:20.079 pops up it's like oh this I haven't this
00:09:22.160 is okay I want to dive into that little
00:09:24.000 bit more you might be saying things like
00:09:26.120 oh that's an interesting name or what
00:09:28.320 does this method do is is this a ruby
00:09:30.040 thing oh why did I lose what happened
00:09:32.880 there let's see
00:09:35.800 okay or also what the hell is this which
00:09:38.240 I kind of just did at a presentation
00:09:39.880 okay so the next bit is remaining
00:09:42.320 neutral when you encounter a file that's
00:09:45.640 either quite Advanced or whatever you
00:09:47.519 might be saying other things to yourself
00:09:49.880 like um I should know this stuff already
00:09:51.920 like what could this even mean or if you
00:09:53.360 never seen prision before it's what's
00:09:55.040 going on here or I should need to dive
00:09:57.519 into this right because all the real
00:09:58.920 Developers can just figure everything
00:10:00.560 out from the documentation or things
00:10:03.720 like I'm not smart enough to get this or
00:10:05.880 there's too much magic but what I would
00:10:08.519 recommend to you is if you judge
00:10:09.959 yourself what is going on
00:10:11.920 here okay that's not what I
00:10:14.519 wanted it's a little slow okay uh but
00:10:17.800 judging yourself stops you so for
00:10:20.640 instance there was a number of different
00:10:21.760 Clicks in a small demo there where if I
00:10:23.480 had been like I can't I shouldn't look
00:10:25.279 at this or whatever it would have slowed
00:10:26.399 me down a ton as opposed to just being
00:10:28.000 able to just click around and see what's
00:10:29.399 in there and not interpreting just
00:10:32.519 meaning something about
00:10:34.480 myself uh I basically try to think of
00:10:37.639 this more as like listening to new music
00:10:39.519 you probably wouldn't say to yourself
00:10:40.959 can I even listen to like jazz if you
00:10:42.839 never listened to Jazz before you don't
00:10:44.639 tend to describe it as something about
00:10:46.320 yourself as more like do I like this or
00:10:48.079 not let me try it and see what happens
00:10:50.079 so like gu with music we basically just
00:10:52.519 try listening and recomended with the
00:10:53.920 same thing if you try to open and read
00:10:56.120 something to do the same just try
00:10:57.480 reading and see what happens and another
00:11:00.519 point I want to make is that for me at
00:11:02.519 least when I see a lot of super smart
00:11:04.480 people here it's kind of for me it's not
00:11:06.800 always smarts for me because of having
00:11:08.680 done this reading work I know it's
00:11:10.079 partly context like even though I don't
00:11:12.680 understand anything I saw ear from the
00:11:14.040 elama talk kind of it's like I know
00:11:15.920 there's bits and pieces and keywords
00:11:18.040 that I can kind of put together and I
00:11:19.480 know that it's obviously he's smart but
00:11:21.480 that's not what I'm saying but it's more
00:11:23.160 it's the context too so you can still do
00:11:25.399 it even if you haven't done it before it
00:11:27.440 just takes a while to immerse s and
00:11:29.639 learned that uh okay so it's having seen
00:11:33.440 similar things in the past and then also
00:11:35.079 expanding your knowledge bit by bit and
00:11:37.200 then for me reading helps me build that
00:11:39.240 context it helps me have this base that
00:11:41.360 I can keep diving into new code that I
00:11:43.200 haven't seen before and expanding it so
00:11:45.560 then I know more that I can do later and
00:11:47.240 so forth or using my own code um I also
00:11:50.720 try to set anger and frustration aside
00:11:52.600 like this is more if you're working on a
00:11:53.920 bug or something like that's that's
00:11:55.240 grinding you or whatever um so it's easy
00:11:58.320 to get any FR through when you're in
00:11:59.720 that state but those shut you down it
00:12:02.320 then make it hard to have new ideas to
00:12:04.399 understand what's going on so I try to
00:12:06.000 set those aside and basically have an
00:12:08.399 open mind um and then part of the
00:12:12.360 exercise is also just to keep coming
00:12:14.120 back um for me to get good things out of
00:12:17.839 this it's important to just have it be
00:12:19.320 more of a practice you want it to be uh
00:12:22.880 something that you revisit over and over
00:12:24.399 essentially and those two first
00:12:25.800 principles like just click things and
00:12:27.600 remain neutral are there to help keep it
00:12:29.480 fun and engaging and pressure free to
00:12:31.120 read so you do come back to read because
00:12:33.320 otherwise you're probably not going to
00:12:34.320 come back and then the good news is
00:12:36.079 where practice you'll be quicker you'll
00:12:37.839 basically be quicker at oh it's freezing
00:12:40.800 here is it ready
00:12:44.160 no you'll be quicker at paring brand new
00:12:46.720 code than splitting it into chunks
00:12:48.720 either picking up new names or concepts
00:12:50.399 and already knowing how to integrate
00:12:51.760 them spotting different styles and
00:12:53.560 patterns you'll basically find your own
00:12:55.639 way over time and part I want to say to
00:12:58.680 is that this is a pro come on this is a
00:13:01.560 process it's not just a one-time task
00:13:03.360 it's not just like go in and read one
00:13:04.600 file and then I'm done it's basically
00:13:06.360 using those principles to keep coming
00:13:08.320 back and keep read either rereading the
00:13:09.880 same thing or finding something new and
00:13:11.279 then having that extra expertise help
00:13:13.639 you with the first thing sort of so it's
00:13:15.000 kind of back and forth in that
00:13:18.160 sense so it's these three basically they
00:13:21.000 help keep me going back they help keep
00:13:22.360 me curious so I'll basically try to look
00:13:25.040 um because in my experience it
00:13:27.560 is oh it's just racing a little bit no
00:13:31.120 no
00:13:32.680 no it's much better just to look because
00:13:35.680 sometimes you'll be surprised that it's
00:13:37.000 easier to read than you thought like I
00:13:38.959 don't know how many of you looked at
00:13:40.000 blank and present before what they
00:13:41.320 actually do but they were both on liners
00:13:42.920 and one of them just used the other so
00:13:44.720 those were in and enough themselves not
00:13:46.399 too difficult I hope um you could also
00:13:49.639 form an idea in your head that open
00:13:51.240 source is for just the wizards but it is
00:13:53.360 just code at the end of the day and
00:13:54.639 somewhere might be closer in your reach
00:13:56.120 than you
00:13:57.680 think okay
00:14:00.920 okay
00:14:02.040 okay be gentle okay let's see um before
00:14:05.720 the next part I just want to Quick aside
00:14:07.279 I want to make a broader point about
00:14:09.040 learning something that I've also found
00:14:10.519 really useful when I'm basically trying
00:14:12.199 to learn something because there's I
00:14:14.040 kind of see it as two paths when you're
00:14:15.680 learning something you can even like
00:14:17.480 follow a lay out path like a tutorial or
00:14:19.560 class and that's you really about making
00:14:21.560 things easier and that's totally fine
00:14:23.279 but for me there's another option that
00:14:25.720 I've been using and that's basically
00:14:27.399 making things come
00:14:30.399 on way harder there we go okay uh I've
00:14:33.600 gotten so much out of this like the
00:14:34.959 basic thing of just I'll just read rails
00:14:37.160 it's fine we'll figure it out um but you
00:14:39.839 have to acknowledge that you're doing
00:14:41.040 something that's kind of way outside of
00:14:42.240 your capacity so you don't go back and
00:14:45.079 judge yourself and then you'll get what
00:14:47.320 you get out of it if you only get 5% out
00:14:49.480 of it then you take those 5% you don't
00:14:51.279 have to do the whole thing you can still
00:14:53.079 learn a ton from doing that um so that's
00:14:55.800 sort of my Approach is
00:14:57.440 just at the deep end isn't that deep
00:14:59.720 let's just dive in there and then we'll
00:15:00.920 see and then sometimes it's a little bit
00:15:02.279 too deep and then other times it's kind
00:15:03.680 of not too bad okay so in my quest to
00:15:08.279 read things ahead of time I also dove
00:15:10.560 into and read mini test Source um and I
00:15:14.240 basically learned a concept there that's
00:15:15.639 stuck with me ever since it's a common o
00:15:18.360 concept we'll get to
00:15:19.680 that so the reason I do inunity test is
00:15:23.720 that it's Ruby's default test framework
00:15:25.959 so if you know how it works you know how
00:15:27.639 the default test framework in Ruby works
00:15:29.319 and these days is around 1,200 lines at
00:15:31.800 least the main file I checked the other
00:15:33.240 day back then I think it was like a
00:15:34.680 thousand lines so it's grown a little
00:15:35.800 bit um so it's something that you can
00:15:39.000 sit down and read in maybe a couple
00:15:41.000 sessions or things like that you don't
00:15:42.360 have to understand everything but at
00:15:44.959 least I felt a super confidence boost
00:15:46.519 when I'm just trying to try to parse it
00:15:48.720 out and what I was doing so so within
00:15:52.440 many test there's there's the there's an
00:15:55.519 abstraction that handles this stuff both
00:15:57.560 printing the dot when you run a test
00:15:59.160 like the the period there or an F or an
00:16:01.360 S for you know a failed or skip test and
00:16:03.560 there's also someone that runs this line
00:16:05.680 here with the one runs one a shance and
00:16:07.920 so on so as I was reading I found out it
00:16:11.160 was handled by this basically there's a
00:16:14.279 reporter class it responds to this
00:16:15.880 record method and it takes a result
00:16:18.319 another thing by the way notice there's
00:16:19.560 no parentheses there this is another
00:16:20.880 reason why I think it's fun to read mini
00:16:22.360 test because it's using what's called
00:16:23.759 Seattle RB style where they don't want
00:16:26.600 to add any parentheses they basically
00:16:28.399 try to remove move parenthesis until The
00:16:31.279 Interpreter complains so so everything
00:16:34.639 has no parentheses if they can get away
00:16:36.319 with it um so I think that's really fun
00:16:38.920 to see because it's quite a different
00:16:40.360 style um than sort of what's common
00:16:42.440 today because this you know before ruub
00:16:44.160 even assisted and so forth so there
00:16:46.800 these reporters it responds to this
00:16:48.920 record method and does something with it
00:16:50.959 and there's these other classes here
00:16:53.240 there's a summary report which handles
00:16:54.800 the dot and there's a statistics report
00:16:57.040 which handled these one assertions and
00:16:59.440 they also respond to this record method
00:17:01.399 and do something with it so but I was
00:17:05.039 wondering but wait Min uses both of
00:17:06.959 these at the same time but the
00:17:08.319 functionality split between two classes
00:17:10.640 how does this work at the time I just
00:17:12.439 couldn't put two and two together for
00:17:13.839 how this was actually working so I also
00:17:16.000 found it was this thing called a
00:17:17.319 composite reporter and I already I like
00:17:19.559 the name I was like composite that
00:17:20.679 sounds really cool I don't know what it
00:17:22.000 does so I saw it also had this record
00:17:24.280 method like the other ones and it also
00:17:25.679 inherits from the same abstract reporter
00:17:28.600 class we don't have to get into that but
00:17:30.919 it also has this the shovel operator as
00:17:32.600 it's called where you just like pend a
00:17:34.400 reporter to some sort of internal State
00:17:36.880 we don't have to see that right now but
00:17:39.000 then on the configuration side mini test
00:17:41.000 does this it does selft reporter puts it
00:17:43.320 into this composite reporter shovels on
00:17:46.520 both of these the summary and the
00:17:48.160 statistics and then somewhere it calls
00:17:50.360 record and the result the reporter will
00:17:52.600 then be a composite reporter and I still
00:17:54.760 couldn't wrap my head around how this
00:17:56.320 was working because I think how is this
00:17:58.000 record doing this stuff it must be super
00:18:00.120 complex and so when I didn't saw what an
00:18:02.760 AI was doing I was kind wait what it's
00:18:05.640 it's just it is just this it's just
00:18:07.559 looping over an array and then calling
00:18:09.080 the record method uh on the internal
00:18:11.760 reporters that it has like the summary
00:18:13.640 and statistics and I just like wait what
00:18:15.960 it's that simple I could not put it
00:18:18.039 together of how it was actually working
00:18:19.480 I couldn't believe that it could be that
00:18:20.559 simple now I'm a self- thought
00:18:22.520 programmer so I didn't know at the time
00:18:24.640 this was a common Concept in computer
00:18:27.600 science which is part of why I like
00:18:30.000 reading things because I rediscovered an
00:18:32.360 actual concept outside of like a
00:18:34.360 university setting just by diving into
00:18:36.120 reading things uh and this is basically
00:18:39.600 polymorphism it's where you have
00:18:41.240 multiple types that respond to the same
00:18:43.159 method and interface and then reuse that
00:18:44.960 so you can swap them out and call you
00:18:47.520 know record on these different reporters
00:18:49.280 and it will kind of just work basically
00:18:51.960 um and have sort of these like elegant
00:18:53.600 interfaces I feel where it's just doing
00:18:55.720 in each Loop and it works and you can
00:18:57.400 just shovel the UT reports on and you
00:18:59.000 can add your own too which is what a lot
00:19:00.440 of gyms do okay see now let's dive into
00:19:04.679 a jit case I has from last week where
00:19:06.640 we're reading just in time so there's a
00:19:08.280 little bit of setup to this one too I
00:19:10.039 was helping someone debug a case they
00:19:11.600 had where they were using well actually
00:19:13.760 they had this like they didn't have a
00:19:15.320 post class but something like this where
00:19:17.080 they were originally having this post
00:19:19.080 have a Content column on itself but they
00:19:22.400 know swapping that over to using action
00:19:24.360 text which is what the hassard text does
00:19:26.799 but they were also using the audit G
00:19:29.039 which I didn't know existed before last
00:19:30.600 week uh I just hadn't worked with it
00:19:32.080 before but basically what that does is
00:19:33.960 it tracks changes to classes so you can
00:19:38.039 you know have an audit table for what's
00:19:39.919 someone did something here and we want
00:19:41.240 to be able to capture that or maybe show
00:19:42.640 it in UI something like that so they
00:19:44.440 were trying to migrate their class to
00:19:46.200 using action text but then what action
00:19:48.320 text actually does is it doesn't use the
00:19:49.840 column on like the post table here it's
00:19:52.200 a separate accent text Rich Text record
00:19:55.120 so they had found a GitHub issue on
00:19:58.760 audited was someone suggesting to do
00:20:00.480 this bottom line where they're calling
00:20:02.159 the audited method is the main interface
00:20:04.840 to set it up so tracks changes but then
00:20:07.480 they were hitting a different issue they
00:20:09.320 didn't know something else was happening
00:20:12.159 and let's see if we can demo some of
00:20:13.280 that okay quick aside then let's do a
00:20:15.400 little bit of ahead of time reading uh
00:20:17.159 for this as well because it's going to
00:20:18.480 be useful for what we're doing so a
00:20:21.280 while back or whatever you know I just I
00:20:23.400 tend to dive into things I don't
00:20:24.520 remember when this happened what but
00:20:25.760 just C how does yaml actually work um
00:20:29.520 how does the parsing work how does The
00:20:30.880 Dumping how does the loading work I just
00:20:32.440 want to see it so sometimes I just go to
00:20:34.280 the you know the front page of it and
00:20:36.080 start seeing what's in there and
00:20:37.480 exploring out so we're going to look at
00:20:38.559 that now and Ruby API is technically not
00:20:40.760 the official Doc I just think it looks a
00:20:42.080 little bit nicer so that's kind of my
00:20:43.840 let's see what happens see if I click
00:20:45.000 here okay and then I need to
00:20:48.679 mirror cool cool cool okay okay you can
00:20:51.840 see this right okay let's see maybe bump
00:20:53.760 it a little bit so part of what we're
00:20:56.600 seeing here is that yaml is just this
00:20:58.640 mod a ruby interface for data calization
00:21:00.679 in the yl format okay the yl module is
00:21:03.400 an alias of Psych okay and then that's
00:21:06.960 the yaml engine for Ruby okay
00:21:08.400 interesting but you do a require you can
00:21:11.159 do a load on some syntax okay and then
00:21:13.720 you can dump it as well and you get
00:21:15.600 something similar looking out to what
00:21:17.360 the was passed in here okay so there's a
00:21:18.960 load on a dump on this yaml module and
00:21:21.320 then there's also this thing called Psy
00:21:23.120 okay so I'm going to file that away for
00:21:24.679 later and then let's see I want to show
00:21:27.480 you something else actually
00:21:29.120 so I just want to demo what it looks
00:21:30.720 like because typically what I do when I
00:21:32.120 try to process something like this is
00:21:33.559 just open up a console start playing
00:21:35.600 with it uh let's see if we can do that
00:21:37.559 so I want to show you these things where
00:21:39.640 let's do I think I have a rails console
00:21:41.279 here I hope this is let me boost this a
00:21:43.360 little bit okay what happens if I do
00:21:45.320 that okay cool okay let's see boost a
00:21:47.080 little bit more so I'm just going to
00:21:50.159 Define this class call it hello there's
00:21:52.760 nothing special about it and then let's
00:21:54.120 see what happens if we try to dump
00:21:56.440 this okay dump it that works okay let's
00:22:00.440 see what happens if we try to load it
00:22:01.799 again just for
00:22:03.159 fun okay so we get a an error that says
00:22:06.679 it's a disallowed class okay and it says
00:22:09.159 hello there and try to load an
00:22:10.919 unspecified class okay so we're not
00:22:13.480 going to dive into this more right now
00:22:15.000 but I just want to show what that looks
00:22:16.640 like um it's important for what happened
00:22:19.480 last week and another thing we could do
00:22:22.080 actually quick aside is in IRB these
00:22:24.919 days there's also a show Source method
00:22:26.720 so you just point it at the method you
00:22:28.039 want to look at
00:22:29.360 and then it likes to show it to you
00:22:31.480 let's see here what's going on here you
00:22:33.400 don't have to read this part I know it's
00:22:34.679 ironic where I'm saying read open source
00:22:36.120 but it's a way to dive into methods and
00:22:39.120 maybe that Safe Load will give you a
00:22:40.520 clue to what's actually going on and
00:22:41.799 what some of all the other options are
00:22:43.200 we don't have to get into that right now
00:22:45.120 because let's
00:22:47.240 see so what was happening was we had the
00:22:51.159 post
00:22:52.279 model same looks the same and then we
00:22:55.120 have the line in config application RB
00:22:57.600 the one I was talking about or just set
00:22:58.880 up the audited thing but then what they
00:23:00.919 were
00:23:01.840 doing was they were trying to do post.
00:23:04.440 create I think content and they were
00:23:07.080 doing like you know they had some HTML
00:23:08.640 in there and some content in there some
00:23:11.120 very you know cool content whatever and
00:23:13.600 it tried to serialize that but then
00:23:15.120 because they configured audited to try
00:23:17.159 to also capture what's going on with
00:23:18.640 these actor records on this action text
00:23:21.000 Rich Tech record they were hitting this
00:23:22.360 error we just saw this like and this
00:23:24.880 action text content thing uh don't know
00:23:27.559 what that is but so what we do and my
00:23:29.960 Approach again is just to look so we
00:23:31.799 basically did let's see if I can H this
00:23:34.320 I did a bundle open on audited I hadn't
00:23:36.799 seen it before I don't know what the gem
00:23:38.000 does so I just want to open it up and
00:23:39.200 see what's in there and then what we did
00:23:41.320 was we just searched for audited and so
00:23:44.840 okay so there's some different results
00:23:45.919 here let's try to just search for the
00:23:47.039 whole word and see if it's we just want
00:23:48.360 the one method okay so it seems to be in
00:23:51.159 here in this auditor class and it's a
00:23:54.640 long method what we did on the call was
00:23:57.000 just walk through
00:23:59.159 section by section and block by block
00:24:01.200 and seeing what it's actually doing like
00:24:02.760 I'm just going to call it out a little
00:24:03.799 bit here you can see setting up in has
00:24:05.600 mini so on the action text you would
00:24:08.000 have a has many audits for instance um
00:24:11.039 there's also a bunch of callbacks being
00:24:12.360 set up here that's also prly interesting
00:24:14.640 now as it happened there wasn't anything
00:24:16.720 like a smoke and gun in here for what's
00:24:18.720 going on so but for me it was least
00:24:22.039 helpful just to settle in my mind okay
00:24:24.240 now I know roughly what this audited
00:24:25.880 method does because I hadn't seen the
00:24:27.120 gem before so just reading it just in
00:24:29.000 time just to see what it's doing and I
00:24:31.200 could just like put that away for now
00:24:32.640 and see what's going on so the other
00:24:34.600 thing we did was and I have to run back
00:24:37.080 here we also did now I want to dive so
00:24:40.279 once we've seen that I want to dive into
00:24:41.520 what's in action text and then I want to
00:24:44.000 see what's going text because I had read
00:24:46.279 this before and I remember some parts
00:24:47.880 about it there was a line that we wanted
00:24:49.880 which is this one to see where it lies
00:24:52.080 and then there that action TT content
00:24:53.840 again so now what I'm curious about is
00:24:56.159 seeing what's in the content then so
00:24:57.799 that's what we're doing we're just
00:24:58.679 jumping back and forth we're just trying
00:25:00.279 to find keywords that seem helpful to
00:25:02.640 what we're looking at right now and then
00:25:04.080 using as a jumping off point to dive
00:25:05.760 into the next bit and not reading too
00:25:07.640 much right now okay so now we're in the
00:25:09.880 content thing it does a bunch of stuff
00:25:13.159 uh let's see we're just I'm just trying
00:25:14.600 to basically scan for see what's
00:25:16.080 relevant this looks like complex all
00:25:17.559 this stuff uh but I see there's a
00:25:19.320 calization here so let's try to dive
00:25:21.000 into that first
00:25:23.080 calization okay so that's interesting it
00:25:25.960 has a load and a dump now because I read
00:25:28.360 well we also read the uh well that's
00:25:31.200 actually not important right now but I
00:25:33.360 know from having read what's going on
00:25:34.799 the serialized method from actor record
00:25:37.039 I know it uses these load and dump
00:25:38.799 methods so immediately as I saw it it's
00:25:40.559 was like oh I know what these are that's
00:25:42.120 what that using and then you can see in
00:25:44.600 the compatibility layer for Marshall is
00:25:47.080 another a sterilization format but it's
00:25:48.520 basically aliasing these methods because
00:25:50.080 it uses underscore load and underscore
00:25:51.960 dump so that's what's going on down
00:25:53.200 there it's like oh we're in the right
00:25:54.799 spot for what's going on and we know
00:25:56.679 what how this action Tak content wants
00:25:59.000 to be serialized because we can see that
00:26:00.559 in this method it wants to use to HTML
00:26:03.600 so storing raw HTML in its format and so
00:26:06.760 basically what was happening with this
00:26:07.880 audited record was that it's trying to
00:26:11.159 save the changes to this internal
00:26:14.919 content um as like a yaml column in
00:26:17.679 itself so it could be potentially quite
00:26:19.120 large so that's what we found out from
00:26:21.600 diving into it and then we knew that the
00:26:23.320 next place to look for was try to figure
00:26:25.000 out how can we make this work with yaml
00:26:26.880 loading essentially in trying that out
00:26:28.880 so that's what we did I don't have time
00:26:30.039 to cover that but that's a with there
00:26:32.399 let's see let me get back
00:26:34.080 out cool but that works okay no wait
00:26:37.240 wait wait you're gonna see my notes
00:26:38.240 aren't
00:26:40.480 you just St me WR thing okay go go yeah
00:26:44.039 okay Works cool so that was what we did
00:26:46.520 just in time demo so to summarize that
00:26:48.919 we read our bit of yaml ahead of time
00:26:50.559 and then we fil that knowledge for later
00:26:52.399 I'm simulating what it is for me you
00:26:54.080 know um in shortness of time we use that
00:26:57.320 knowledge to debug and issue and helped
00:26:59.080 us find what we're going for faster
00:27:02.200 instead of spending hours on it we spent
00:27:03.760 a little bit of time on it instead uh in
00:27:05.520 real life that's what happened you know
00:27:06.960 last week when this actually happened
00:27:08.960 then we looked at a source of audited
00:27:10.320 and action text and used that as jumping
00:27:13.159 off points to find the next little bit
00:27:14.679 we needed um and we saw it action text
00:27:17.080 content doesn't support y calization so
00:27:19.120 that's the ne clue for what we're didn't
00:27:20.600 figure out we don't have time to cover
00:27:21.640 what we did but um so that's kind of
00:27:24.120 what I'm doing that's let's wrap up of
00:27:26.039 seeing what the hell we just did uh we
00:27:27.880 learned about ahead of time reading and
00:27:29.480 just in time reading we nipple at some
00:27:31.080 realse reading we also became expert at
00:27:33.279 polymorphism from mini test I think I
00:27:35.320 think that's clear clear we I I count it
00:27:37.679 as a win okay we used to ahead of time
00:27:40.080 uh reading to debug while we also doing
00:27:41.960 a little bit of adjus in time so we're
00:27:43.799 combining both those reading modes and
00:27:45.880 again my reading principles what I'm
00:27:47.200 trying to do this is to just click
00:27:48.880 things I'm just clicking on the rich
00:27:50.440 text thing because I see that there and
00:27:52.039 then I want to see the next thing where
00:27:53.200 is the content using those keywords is
00:27:55.440 jumping off point so the next thing are
00:27:56.840 just clicking around seeing what's going
00:27:58.000 on on uh and we're remaining neutral I'm
00:28:00.320 not judging myself as we're doing it
00:28:01.960 we're just sort of flying by the seat of
00:28:04.000 our pants in a way and trying to figure
00:28:05.279 out what the next little bit is and we
00:28:07.080 keep coming back where when I'm reading
00:28:09.559 ahead of time is just oh we just had an
00:28:11.440 issue with action text now I want to
00:28:12.640 jump back in a little bit later and see
00:28:13.919 what the rest of it is doing because now
00:28:15.519 I see a little bit of this part so I
00:28:17.080 don't have to read that part again now I
00:28:19.240 can do the next little bit and
00:28:20.440 understand a little bit more so that's
00:28:22.159 kind of that's kind of the talk in a way
00:28:24.679 um if you want to work with me uh this
00:28:26.919 is my GitHub profile there's an email
00:28:28.600 there I'm an independent consultant do
00:28:30.159 this kind of debuging work as well um
00:28:33.120 and a bunch of other stuff let's see uh
00:28:35.440 I just want to give a special thanks to
00:28:36.559 people help with the talk here both to
00:28:38.480 you Kim you're really helpful also with
00:28:40.200 the sticks as you saw we came in Sam as
00:28:42.919 well and Thomas helped so thanks so much
00:28:45.039 that's uh that's it just in time just in
00:28:47.600 time oh I
Explore all talks recorded at EuRuKo 2024
+39