Slide 1

Slide 1 text

@kwugirl Wow Code, Such Read! KWu Ruby Agent Engineer amaze understand so power

Slide 2

Slide 2 text

@kwugirl the goal: get better at reading code

Slide 3

Slide 3 text

be fearless in diving into code you don’t know Edmond Lau theeffectiveengineer.com

Slide 4

Slide 4 text

@kwugirl

Slide 5

Slide 5 text

@kwugirl 10.000 hours

Slide 6

Slide 6 text

@kwugirl 10.000 hours 250 weeks

Slide 7

Slide 7 text

@kwugirl 10.000 hours 250 weeks ~5 years!

Slide 8

Slide 8 text

@kwugirl productive struggling

Slide 9

Slide 9 text

@kwugirl code archaeology https://www.flickr.com/photos/22134952@N04/2850397739

Slide 10

Slide 10 text

@kwugirl 2. remember your question 3. enlist help 1. see the code

Slide 11

Slide 11 text

@kwugirl the problem

Slide 12

Slide 12 text

@kwugirl the problem connection.execute("EXPLAIN #{query}")

Slide 13

Slide 13 text

@kwugirl the problem connection.execute("EXPLAIN #{query}") SELECT "blogs".* FROM "blogs" WHERE "blogs"."id" = $1 LIMIT 1 with

Slide 14

Slide 14 text

@kwugirl the problem connection.execute("EXPLAIN #{query}") SELECT "blogs".* FROM "blogs" WHERE "blogs"."id" = $1 LIMIT 1 with

Slide 15

Slide 15 text

@kwugirl { :sql=>
 "SELECT \"blogs\".* FROM \"blogs\" WHERE \"blogs\".\"id \" = $1 LIMIT 1", … :binds=> [[#,…,42]] } ActiveSupport::Notifications.subscribe 'sql.active_record'

Slide 16

Slide 16 text

@kwugirl { :sql=>
 "SELECT \"blogs\".* FROM \"blogs\" WHERE \"blogs\".\"id \" = $1 LIMIT 1", … :binds=> [[#,…,42]] } ActiveSupport::Notifications.subscribe 'sql.active_record'

Slide 17

Slide 17 text

@kwugirl 2. remember your question 3. enlist help 1. see the code

Slide 18

Slide 18 text

@kwugirl

Slide 19

Slide 19 text

@kwugirl $ cd src/

Slide 20

Slide 20 text

@kwugirl $ cd src/ $ git clone [email protected]:rails/rails.git
 $ cd rails/

Slide 21

Slide 21 text

@kwugirl $ cd src/ $ git clone [email protected]:rails/rails.git
 $ cd rails/ $ git checkout v4.2.0

Slide 22

Slide 22 text

@kwugirl # Gemfile gem 'rails', '4.2.0'

Slide 23

Slide 23 text

@kwugirl # Gemfile # gem 'rails', '4.2.0' gem 'rails', :path => '../../src/rails'

Slide 24

Slide 24 text

@kwugirl @instrumenter.instrument( "sql.active_record", :sql => sql, :name => name, :connection_id => object_id, :statement_name => statement_name, :binds => binds) { yield } def log(sql, name = "SQL", binds = [], statement_name = nil) # active_record/connection_adapters/abstract_adapter.rb

Slide 25

Slide 25 text

@kwugirl @instrumenter.instrument( "sql.active_record", :sql => sql, :name => name, :connection_id => object_id, :statement_name => statement_name, :binds => binds) { yield } def log(sql, name = "SQL", binds = [], statement_name = nil) # active_record/connection_adapters/abstract_adapter.rb

Slide 26

Slide 26 text

@kwugirl @instrumenter.instrument( "sql.active_record", :sql => sql, :name => name, :connection_id => object_id, :statement_name => statement_name, :binds => binds) { yield } def log(sql, name = "SQL", binds = [], statement_name = nil) # active_record/connection_adapters/abstract_adapter.rb

Slide 27

Slide 27 text

@kwugirl def log(sql, name = "SQL", binds = [], statement_name = nil) @instrumenter.instrument( "sql.active_record", :sql => sql, :name => name, :connection_id => object_id, :statement_name => statement_name, :binds => binds) { yield } puts "====== HELLO IS IT ME YOU'RE LOOKING FOR?!!?? ======" # active_record/connection_adapters/abstract_adapter.rb

Slide 28

Slide 28 text

@kwugirl git blame (can be) your friend

Slide 29

Slide 29 text

@kwugirl 2. remember your question 3. enlist help 1. see the code

Slide 30

Slide 30 text

@kwugirl don’t get lost

Slide 31

Slide 31 text

@kwugirl don’t get lost learn one thing at a time

Slide 32

Slide 32 text

@kwugirl don’t get lost learn one thing at a time what are your unknowns?

Slide 33

Slide 33 text

@kwugirl the problem connection.execute("EXPLAIN #{query}") SELECT "blogs".* FROM "blogs" WHERE "blogs"."id" = $1 LIMIT 1 with

Slide 34

Slide 34 text

@kwugirl the problem connection.execute("EXPLAIN #{query}") SELECT "blogs".* FROM "blogs" WHERE "blogs"."id" = $1 LIMIT 1 with

Slide 35

Slide 35 text

@kwugirl the problem connection.execute("EXPLAIN #{query}") SELECT "blogs".* FROM "blogs" WHERE "blogs"."id" = $1 LIMIT 1 with

Slide 36

Slide 36 text

@kwugirl 2. remember your question 3. enlist help 1. see the code

Slide 37

Slide 37 text

@kwugirl pair programming

Slide 38

Slide 38 text

@kwugirl pair programming ¿?¿?¿?¿?¿? ¿?¿?¿?¿?¿? ¿?¿?¿?¿?¿?

Slide 39

Slide 39 text

@kwugirl

Slide 40

Slide 40 text

@kwugirl What are you looking for?

Slide 41

Slide 41 text

@kwugirl What are you looking for? Why?

Slide 42

Slide 42 text

@kwugirl What are you looking for? Why? How did you know to look there?

Slide 43

Slide 43 text

@kwugirl Kernel#caller

Slide 44

Slide 44 text

@kwugirl active_record/connection_adapters/postgresql_adapter.rb:601:in `exec_cache' active_record/connection_adapters/postgresql_adapter.rb:585:in `execute_and_clear' active_record/connection_adapters/postgresql/database_statements.rb:161:in `exec_query' active_record/connection_adapters/abstract/database_statements.rb:341:in `select' active_record/connection_adapters/abstract/database_statements.rb:37:in `select_all' active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all' active_record/querying.rb:39:in `find_by_sql' active_record/relation.rb:639:in `exec_queries' active_record/relation.rb:514:in `load' active_record/relation.rb:243:in `to_a' active_record/relation.rb:617:in `pretty_print' Kernel#caller

Slide 45

Slide 45 text

@kwugirl Method#source_location

Slide 46

Slide 46 text

@kwugirl Method#source_location $ bundle exec rails console

Slide 47

Slide 47 text

@kwugirl Method#source_location $ bundle exec rails console irb(main):001:0> method(:try).source_location

Slide 48

Slide 48 text

@kwugirl Method#source_location $ bundle exec rails console irb(main):001:0> method(:try).source_location => ["/…/active_support/core_ext/object/try.rb", 62]

Slide 49

Slide 49 text

@kwugirl method_defined? RubyTapas #439 “Method Search”

Slide 50

Slide 50 text

@kwugirl method_defined? $ ObjectSpace.each_object(Class).select{|c| c.singleton_class.method_defined?(:try_convert) } => [File, IO, Regexp, Hash, Array, String] RubyTapas #439 “Method Search”

Slide 51

Slide 51 text

@kwugirl method_defined? $ ObjectSpace.each_object(Class).select{|c| c.singleton_class.method_defined?(:try_convert) } => [File, IO, Regexp, Hash, Array, String] RubyTapas #439 “Method Search”

Slide 52

Slide 52 text

@kwugirl method_defined? $ ObjectSpace.each_object(Class).select{|c| c.singleton_class.method_defined?(:try_convert) } => [File, IO, Regexp, Hash, Array, String] RubyTapas #439 “Method Search”

Slide 53

Slide 53 text

@kwugirl method_defined? $ ObjectSpace.each_object(Class).select{|c| c.singleton_class.method_defined?(:try_convert) } => [File, IO, Regexp, Hash, Array, String] RubyTapas #439 “Method Search”

Slide 54

Slide 54 text

@kwugirl method_defined? $ ObjectSpace.each_object(Class).select{|c| c.singleton_class.method_defined?(:try_convert) } => [File, IO, Regexp, Hash, Array, String] RubyTapas #439 “Method Search”

Slide 55

Slide 55 text

@kwugirl the solution connection.exec_query("EXPLAIN #{statement.sql}", "Explain #{statement.name}", statement.binds) wow beauty wonder

Slide 56

Slide 56 text

@kwugirl the solution connection.exec_query("EXPLAIN #{statement.sql}", "Explain #{statement.name}", statement.binds) wow beauty wonder

Slide 57

Slide 57 text

@kwugirl the solution connection.exec_query("EXPLAIN #{statement.sql}", "Explain #{statement.name}", statement.binds) wow beauty wonder

Slide 58

Slide 58 text

@kwugirl success!!1!one!!

Slide 59

Slide 59 text

@kwugirl success!!1!one!! $1

Slide 60

Slide 60 text

@kwugirl success!!1!one!! $1 }Explain plan

Slide 61

Slide 61 text

@kwugirl success!!1!one!! released in 3.15.2 $1 }Explain plan

Slide 62

Slide 62 text

@kwugirl 2. remember your question 3. enlist help 1. see the code

Slide 63

Slide 63 text

@kwugirl reading ruby source

Slide 64

Slide 64 text

@kwugirl gentle intro

Slide 65

Slide 65 text

@kwugirl gentle intro

Slide 66

Slide 66 text

@kwugirl which files?

Slide 67

Slide 67 text

@kwugirl which files?

Slide 68

Slide 68 text

@kwugirl github.com/ruby/ruby

Slide 69

Slide 69 text

@kwugirl github.com/ruby/ruby “trunk” not “master”

Slide 70

Slide 70 text

@kwugirl pretty flat directory

Slide 71

Slide 71 text

@kwugirl pretty flat directory

Slide 72

Slide 72 text

@kwugirl std library in lib/

Slide 73

Slide 73 text

@kwugirl extension.rdoc

Slide 74

Slide 74 text

@kwugirl parse.y

Slide 75

Slide 75 text

@kwugirl other helpful points

Slide 76

Slide 76 text

@kwugirl other helpful points rb_

Slide 77

Slide 77 text

@kwugirl other helpful points rb_ regex search with ^ to find method definition

Slide 78

Slide 78 text

@kwugirl other helpful points rb_ regex search with ^ to find method definition comments

Slide 79

Slide 79 text

@kwugirl bugs.ruby-lang.org

Slide 80

Slide 80 text

@kwugirl resources

Slide 81

Slide 81 text

@kwugirl resources readingcodegood.com

Slide 82

Slide 82 text

@kwugirl resources readingcodegood.com schneems' talk “Dissecting Ruby with Ruby”

Slide 83

Slide 83 text

@kwugirl resources readingcodegood.com schneems' talk “Dissecting Ruby with Ruby” schneems.com/2016/01/25/ruby-debugging-magic- cheat-sheet.html
 tenderlovemaking.com/2016/02/05/i-am-a-puts- debuggerer.html

Slide 84

Slide 84 text

@kwugirl resources

Slide 85

Slide 85 text

@kwugirl resources Jason Clark’s talk “GDB: A Gentle Intro”

Slide 86

Slide 86 text

@kwugirl resources Jason Clark’s talk “GDB: A Gentle Intro” Hsing-Hui Hsu’s talk “Time flies like an arrow, fruit flies like a banana”

Slide 87

Slide 87 text

@kwugirl resources Jason Clark’s talk “GDB: A Gentle Intro” Hsing-Hui Hsu’s talk “Time flies like an arrow, fruit flies like a banana” Ruby Under A Microscope

Slide 88

Slide 88 text

@kwugirl resources Jason Clark’s talk “GDB: A Gentle Intro” Hsing-Hui Hsu’s talk “Time flies like an arrow, fruit flies like a banana” Ruby Under A Microscope Definitive Guide to Ruby’s C API: 
 https://silverhammermba.github.io/emberb/c/

Slide 89

Slide 89 text

@kwugirl Julia Evans jvns.ca

Slide 90

Slide 90 text

@kwugirl Net::HTTP is maybe 2000 lines of code, not including comments. Julia Evans jvns.ca

Slide 91

Slide 91 text

@kwugirl Net::HTTP is maybe 2000 lines of code, not including comments. It has ~1000 lines of comments… Julia Evans jvns.ca

Slide 92

Slide 92 text

@kwugirl Net::HTTP is maybe 2000 lines of code, not including comments. It has ~1000 lines of comments… I can read 2000 lines of code, Julia Evans jvns.ca

Slide 93

Slide 93 text

@kwugirl Net::HTTP is maybe 2000 lines of code, not including comments. It has ~1000 lines of comments… I can read 2000 lines of code, mostly! Julia Evans jvns.ca

Slide 94

Slide 94 text

@kwugirl ¿?s

Slide 95

Slide 95 text

@kwugirl appendix

Slide 96

Slide 96 text

@kwugirl doge The White Rabbit, Alice in Wonderland sad Keanu pear/pair programming Lionel Richie + Where’s Waldo !!1!one!! the “!1” phenomenon breadfish Slurms MacKenzie, Futurama

Slide 97

Slide 97 text

@kwugirl This document and the information herein (including any information that may be incorporated by reference) is provided for informational purposes only and should not be construed as an offer, commitment, promise or obligation on behalf of New Relic, Inc. (“New Relic”) to sell securities or deliver any product, material, code, functionality, or other feature. Any information provided hereby is proprietary to New Relic and may not be replicated or disclosed without New Relic’s express written permission. Such information may contain forward-looking statements within the meaning of federal securities laws. Any statement that is not a historical fact or refers to expectations, projections, future plans, objectives, estimates, goals, or other characterizations of future events is a forward-looking statement. These forward-looking statements can often be identified as such because the context of the statement will include words such as “believes,” “anticipates,” “expects” or words of similar import. Actual results may differ materially from those expressed in these forward-looking statements, which speak only as of the date hereof, and are subject to change at any time without notice. Existing and prospective investors, customers and other third parties transacting business with New Relic are cautioned not to place undue reliance on this forward-looking information. The achievement or success of the matters covered by such forward-looking statements are based on New Relic’s current assumptions, expectations, and beliefs and are subject to substantial risks, uncertainties, assumptions, and changes in circumstances that may cause the actual results, performance, or achievements to differ materially from those expressed or implied in any forward-looking statement. Further information on factors that could affect such forward-looking statements is included in the filings we make with the SEC from time to time. Copies of these documents may be obtained by visiting New Relic’s Investor Relations website at ir.newrelic.com or the SEC’s website at www.sec.gov. New Relic assumes no obligation and does not intend to update these forward-looking statements, except as required by law. New Relic makes no warranties, expressed or implied, in this document or otherwise, with respect to the information provided.