Slide 1

Slide 1 text

DRY Don’t Repeat Yourself

Slide 2

Slide 2 text

The 4 Rules of Simple Design • Runs all the tests • No duplication • Expresses developer intent • Minimizes the number of classes and methods

Slide 3

Slide 3 text

The 4 Rules of Simple Design • No duplication = DRY

Slide 4

Slide 4 text

Easiest way to boost your coding skills

Slide 5

Slide 5 text

Don’t take my word

Slide 6

Slide 6 text

Spot the Duplication

Slide 7

Slide 7 text

Plain Old Duplication if @unparsed_geminstaller_output_flags flags = @unparsed_geminstaller_output_flags.split(',') flags.delete_if {|flag| flag == nil or flag == ''} flags.map! {|flag| flag.downcase} flags.sort! flags.uniq! flags.map! {|flag| flag.to_sym} geminstaller_output_valid = true flags.each do |flag| unless VALID_GEMINSTALLER_OUTPUT_FLAGS.include?(flag) @output = "Invalid geminstaller-output flag: #{flag}\n" geminstaller_output_valid = false end end @options[:geminstaller_output] = flags if geminstaller_output_valid end if @unparsed_rubygems_output_flags flags = @unparsed_rubygems_output_flags.split(',') flags.delete_if {|flag| flag == nil or flag == ''} flags.map! {|flag| flag.downcase} flags.sort! flags.uniq! flags.map! {|flag| flag.to_sym} rubygems_output_valid = true flags.each do |flag| unless VALID_RUBYGEMS_OUTPUT_FLAGS.include?(flag) @output = "Invalid rubygems-output flag: #{flag}\n" rubygems_output_valid = false end end @options[:rubygems_output] = flags if rubygems_output_valid end

Slide 8

Slide 8 text

Intention Duplication if (list.isEmpty()) { .... } .... if (list.size() == 0) { .... }

Slide 9

Slide 9 text

Name Duplication TestRunner.runTests() def handle_web_response(web_response) ProductSales productSales = new ProductSales()

Slide 10

Slide 10 text

Comment Duplication // Restart the process process.restart()

Slide 11

Slide 11 text

Structure Duplication if isinstance(StringHandler, o): o.updateString(context) elif isinstance(IntHandler, o): o.updateInt(context)

Slide 12

Slide 12 text

Let’s get it on! • The Serializer Kata http://bit.ly/KataDRY • Do not move to next step until code duplication ≤ 0