On 10/8/07, Austin Ziegler <halostatue / gmail.com> wrote: > > Wrong. Look VERY CAREFULLY at your code, Trans. How many of your modules > are used in more than one place? > > If the answer is few, then you're doing it wrong and you're introducing > negative consequences in terms of maintainability, while not actually > increasing reuse. Most methods are specific behaviour for a given state. > Pretending that by extracting that into modules that youre increasing > reuse is nonsense. Unless you're actually reusing the code, you're not > increasing reuse. Here I have to disagree. This is from some actual code I've written: --------------------------------------------------------------------------- monitor.rb: class Monitor .... .... end --------------------------------------------------------------------------- win_monitor.rb: require 'monitor' require 'win_metrics' class Monitor include WindowsMetrics end Monitor.new.start --------------------------------------------------------------------------- lin_monitor.rb: require 'monitor' require 'lin_metrics' class Monitor include LinuxMetrics end Monitor.new.start --------------------------------------------------------------------------- Now WindowsMetrics and LinuxMetrics are modules that exist solely for the purpose of being included in Monitor, and you could argue that instead I could have simply made win_metrics and lin_metrics reopen the class and add the methods when required. The benefit I've gained here is that for the cost of an extra layer of indirection and a few extra lines of code, I've got a huge increase in readability for someone who looks through my code, since the natural entry points are win_monitor.rb and lin_monitor.rb. Also, should I ever wish to make a program that is deployed on multiple platforms and dispatches at runtime, I can trivially require both metrics files and not have to worry that they'll stomp on each other by the mere act of requiring the. I may not be promoting reuse, but I'm definitely increasing maintainability. martin