Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to read code

How to read code

A lightning talk in the office

3e809b3e856f5eed33e279cf93657d3c?s=128

Shimpei Makimoto

September 24, 2014
Tweet

Transcript

  1. How to read code Shimpei Makimoto! 2014-09-24

  2. Shimpei Makimoto! Software Engineer photo by r7kamura @makimoto @makimoto

  3. Today's talk w )PXUPSFBEDPEF w &YBNQMFJNBHFQOHJOHPMBOHMJCT w 8IZHP  w

    TFMGDPOUBJOFE w TJNQMFMBOHVBHFTQFD w OFX w 8IZJNBHFQOH
  4. None
  5. άϦονɾΞʔτΛ८ͬͯަΘ͞ΕΔٞ࿦ͷதʹ͸ɼάϦον͕ΘΕΘΕʹ༩͑Δ৺৅ͦ͜ຊ࣭ͩͱ͢Δཱ৔͕͋Γ·͢ɽͦͷཱ৔ ʹཱͭਓʑ͸ਅͷάϦον͸࠶ݱͰ͖ͳ͍ͱݴ͍ɼͦΕΒ͸ҰॠͰফ͑ڈΔͱݴ͍·͢ɽ࠶ݱͰ͖ͳ͍ͱओு͢ΔҎ্ɼ൴Β͸άϦο νɾΞʔτΛάϦονൈ͖Ͱߏ੒͠ͳͯ͘͸ͳΒͳ͍Ͱ͠ΐ͏ɽҰํͰɼϐΫηϧΛዞҙతʹฒͼସ͑ͨΓมܗͤͨ͞Γͨ͠ਤ૾Λ ΋ͬͯάϦονɾΞʔτͱ͢Δཱ৔͕͋Γ·͢ɽͦͷཱ৔͔ΒݟΔͱɼάϦονɾΞʔτͱ͸άϦονͷࢹ֮ޮՌΛϞνʔϑͱͨ͠ ਓ޻తͳΞʔτ࡞඼ͱ͍͏͜ͱʹͳΓ·͢ɽ ! ͜ͷɼ৺৅ͱͯ͠ͷάϦονͱϞνʔϑͱͯ͠ͷάϦον͸ɼάϦονͱ͍͏ݱ৅Λத৺ʹɼೋۃ΁ဃ཭͠ͳ͕ΒɼάϦονɾΞʔ τΛݻఆ͠͸͡Ί͍ͯ·͢ɽ͓ͦΒ͘কདྷతʹ͸ɼલऀͷओு͸άϦον࿦΍ඒֶͷจ຺΁ྲྀΕͯΏ͘Ͱ͠ΐ͏ɽޙऀ͸ΑΓҰൠత ͳҙຯͰάϦονɾΞʔτͷ໊Λ֫ಘͯ͠Ώ͘ʹҧ͍͋Γ·ͤΜɽάϦονɾϛϡʔδοΫͷઌྫʹؑΈͯ΋ɼͦΕ͸ࣗ͘͝વͳ੒ Γߦ͖ͩͱࢥΘΕ·͢ɽ

    VDOW   IUUQXXXOUUJDDPSKQ"SDIJWF0QFOTQBDF8PSLTUFYU@5BC@(MJUDI@KIUNM
  6. Step 0: Read the spec (roughly) w IUUQXXXXPSH531/( w 3FBEJUSPVHIMZ

    w *OPVSDBTF l$IVOL4QFDJpDBUJPOTzNBZ CFVTFGVM
  7. Step 1: Find files

  8. Step 2: Understand data structure (1) http://golang.org/src/pkg/image/png/reader.go

  9. Step 2: Understand data structure (2) http://golang.org/src/pkg/image/png/reader.go http://golang.org/pkg/image/

  10. Step 3: Specify important public methods http://golang.org/src/pkg/image/png/reader.go http://golang.org/pkg/image/png/

  11. Step 4: Reading w GVOD%FDPEF SJP3FBEFS  JNBHF*NBHF FSSPS 

    w GVOD E EFDPEFS DIFDL)FBEFS FSSPS w GVOD E EFDPEFS QBSTF$IVOL FSSPS w GVOD E EFDPEFS QBSTF*)%3 MFOHUIVJOU FSSPS w GVOD E EFDPEFS QBSTF1-5& MFOHUIVJOU FSSPS w GVOD E EFDPEFS QBSTFU3/4 MFOHUIVJOU FSSPS w GVOD E EFDPEFS QBSTF*%"5 MFOHUIVJOU  FSSFSSPS  w GVOD E EFDPEFS EFDPEF  JNBHF*NBHF FSSPS  w GVOD E EFDPEFS QBSTF*&/% MFOHUIVJOU FSSPS w GVOD E EFDPEFS WFSJGZ$IFDLTVN FSSPS
  12. None
  13. None
  14. None
  15. None
  16. func (d *decoder) decode() (image.Image, error) w TSDQLHJNBHFQOHHP w IUUQTHJTUHJUIVCDPNNBLJNPUP

    DGDGF
  17. wrap up w *OUSPEVDFEIPX*SFBEDPEF w 5PVOEFSTUBOEQPQVMBSBMHPSJUIN SFBEJOHMJCTJOHPMBOHJT WFSZIFMQGVM w *UPPLJNBHFQOHGPSBOFYBNQMF

    BOEUIFSF`SFNBOZ JNQMFNFOUTGPSQPQVMBSBMHPSJUINJOHPMBOH`TMJCT w *GZPVXBOUUPLOPX([JQDPNQSFTTJPO ZPVNBZSFBE DPNQSFTTH[JQ w *GZPVXBOUUPLOPX*1MPPLVQT ZPVNBZSFBEOFUMPPLVQ