2

In Ruby, I'm creating a small game development framework. Just some personal project - a very small group of friends helping.

Now I am in need of handling geometric concepts. Rectangles, Circles, Polygons, Vectors, Lines, etc. So I made a class for each of these.

I'm stuck deciding whether I should package such classes in a module, such as Geometry. So I'd access them like Geometry::Rectangle, or just Rectangle if I include the module.

Now then, my question isn't about this specific scenario. I'd like to know, when is it suitable to package similar classes into one module in Ruby? What factors should I consider? Amount of classes? Usage frequency? Complexity?

1

Semantics.

That's the deciding factor you should consider. Your packages must be semantic. If they're all about game logic, regroup them under the GameLogic package. If they're all about geometry, regroup them under the Geometry package.

It's kind of related to the amount of classes/complexity, because if a package becomes too big, it means it's doing too much. So it's time to refactor it.

Nobody can tell you what packages you should make. This is an architectural design decision.

What's the maximum size of a package? Nobody can tell you either. Lot of projects have differing views about this, so just go with what you feel like is the most maintainable. Too small packages means going a lot through files to find your code, too big packages means maintenance headache.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.