include FooCafe author = Presenter.new(:buren) slides = MigratingLegacy::Slides.new wait until author.ready? author.present(slides) do |slide| print slide any_questions? if slide.last? end
Who wants pizza?
Yes Yes, veg Yes, vegan Naa, I'm goodWho here have worked with a legacy code base?
Legacy Beginner Legacy-ish Naa Legacy what???Where did/do you have the most "legacy"?
Backend <-> Frontend Backend FrontendHow do you battle legacy?
Rewrite More code Refactor I don'tLegacy code has many definitions:
"... A large part of the task of a software engineer is to continually alter code to prevent this."
"The functional core and the imperative shell"
Remember the code from the first slide?
include FooCafe author = Presenter.new(:buren) slides = MigratingLegacy::Slides.new wait until author.ready? author.present(slides) do |slide| print slide any_questions? if slide.last? end
DEADLINE = Time.new(2015, 10, 14, 18, 0, 0).freeze module FooCafe;end module FooCafe::MigratingLegacy;end String.class_eval { define_method(:last?) { false } } NilClass.class_eval { define_method(:last?) { true } } define_method(:wait) { puts 'Still not ready..';sleep 3 } define_method(:any_questions?) { puts 'Any questions?' } define_method(:feedback) { puts 'Feedback?' } class FooCafe::Presenter < Struct.new(:name) define_method(:ready?) { Time.now >= DEADLINE } def present(slides); slides.to_a.each { |slide| yield(slide) };end end class FooCafe::MigratingLegacy::Slides define_method(:initialize) { @slides = File.read('slides.md').split('---') } define_method(:to_a) { @slides + [nil] } end
This actually makes the previous code work