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

Harry Potter and The Legacy Code Base (Ruby On ...

Harry Potter and The Legacy Code Base (Ruby On Ales)

It's your first day at Hogwarts.com, and everything is wonderful and thrilling. You dig in to classes, and soon find a dusty book with a cryptic warning:

"Do NOT on any circumstances make ANY change to this magic incantation without talking to Doug first!!!"

Sound familiar? Approaching a legacy code base can feel like unraveling a mystery, not just about the code, but about the personalities who wrote it. What tools and techniques can help you solve the maze of twisty code? Let's explore how to get a handle on legacy code, how to negotiate joining an existing team of developers, and how we can get a summa cum laude at graduation.

Kerri Miller

March 08, 2014
Tweet

More Decks by Kerri Miller

Other Decks in Programming

Transcript

  1. WHY YOU’RE HERE • House New Hire -- You’re a

    new developer joining an established team • House Reorg -- Hogwarts-Online reorg assigned this to you • House Feddup -- You’ve decided you’ve had enough and volunteered Saturday, March 8, 14
  2. IDEAL HABITAT • Software that has been superseded but is

    difficult to replace because everyone and everything relies on it • Code without tests • Code that you didn’t write • Code written before today Saturday, March 8, 14
  3. CODE ARCHEOLOGY 101 • Achieve a better understanding of the

    overall architecture • Discover the root cause of a critical bug • Determine the best way to extend the functionality of a vestigial class • Investigate a previous approach to solving a current problem In this class you will learn how to... Saturday, March 8, 14
  4. class PoisonBarrel < ActiveRecord::Base def self.first_free_barrel(liters_needed) free = DEFAULT_CAPACITY -

    liters_needed PoisonBarrel.where("liters < ?", free) end def self.with_free_space(liters_needed) if self.first_free_barrel(liters_needed) return barrels.first else return PoisonBarrel.create! end end end Saturday, March 8, 14
  5. class Basilisk < ActiveRecord::Base def remove_poison barrel = PoisonBarrel. with_free_space(poison_quantity)

    barrel.liters += poison_quantity barrel.save! update!(poison_quantity: 0) end end Saturday, March 8, 14
  6. class Basilisk < ActiveRecord::Base def remove_poison warn "#remove_poison has been

    deprecated. “ + “Use #harvest_poison instead." harvest_poison end def harvest_poison store_poison_in(poison_container, poison_quantity) update!(poison_quantity: 0) end private def store_poison_in(container, poison_quantity) container.first_with_free_space(poison_quantity). update!(liters: poison_quantity) end end Saturday, March 8, 14
  7. ★ glass artist ★ Vespa mechanic ★ lighting designer ★

    author & teacher ★ player of games ★ software developer @kerrizor KERRI MILLER Saturday, March 8, 14