4 ms·
> Ruby has modules too but for some reason customers really like to create classes for everything, even two method ones like [...] Encapsulation and extraction
by Tainnor 4y ago
> Ruby has modules too but for some reason customers really like to create classes for everything, even two method ones like [...]
Encapsulation and extraction of complex functionality (yes, you should not do it for trivial one-liners).
In Ruby, classes get used a lot for this because, uh, why not, but you might as well just have a module method - it's just that the way modules are used in Ruby makes this slightly awkward because Ruby is after all biased towards "everything is an object".
But in, say, Haskell I might write instead:
module Command
run :: [String] -> IO ()
run = ...
-- some other file
import qualified Command
...
Command.run args
(not that "Command.run" looks like super idiomatic code in Haskell or anything like that, probably you'd structure your code differently, but it's the general principle)