Skip to main content
GameDev.net gamedev.net
🔒 Locked

Code reuse

Started by The C modest god Sep 17, 2005 at 10:57 AM 2 replies 500+ views
Original Post
The C modest god
The C modest god
How much does it happen to you that you reuse code you wrote in an old program with a newer program? Are there design methods that allow better code reuse? or does each time you write a new program you have new ideas and therfore write from scratch the new program?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
twanvl
twanvl
It does happen, but it is mostly utility functions. The design method that allows for good reuse is simple: "make it as general as possible". If you have a general function/class it will more often apply to other problems.
JohnBolton
JohnBolton
Reduce dependencies (especially dependencies on non-reusable code). Modularity is key.

Quote:
Original post by twanvl
The design method that allows for good reuse is simple: "make it as general as possible".

Frequently, "general as possible" means writing code that will not be used and that is counter-productive. A better strategy is to design with the general solution in mind but only implement the specific solution.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Verg
Verg
In general, the smaller the class, the more reusable it is.

That's more of an indicator than of a design method... IOW, don't just set out to write small classes so they can be re-used. The most general of the classes would be the most re-usable, of course... and generally, those classes are small.

Classes with a lot of responsibilities couple more different types of logic and different algorithms, so it's less likely that these larger classes would be re-usable.

The word for this type of design philosophy is "granularity".

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.