07 Jul '13, 4am
Oh, the programs you’ll DRY!
Someone just told you your code isn’t DRY, and you have no idea what they’re talking about. You’re fresh out of college, and you’re starting to fear that your Computer Science degree left you woefully unprepared for the challenge of real-world software engineering. “Look, it’s basically the same code in all of these methods,” your coworker tells you. Your coworker has been out of college for 9 months, so you take another look at your code. You’re writing an application to create widgets, and you’ve just finished a feature that made it possible to create a new type of widget. class WidgetFactory def foo_widget Foo.new('widget') end def bar_widget Bar.new('widget') end def baz_widget Baz.new('widget') end def fuz_widget Fuz.new(‘widget’) end end On closer inspection, you agree with your coworker that there’s a definite pattern, but you can’t imagine what you could do about i...