Conversation started Aug 8, 2012 at 11:32.
Aug 8, 2012 11:32
Guys, I'm developing resource manager for my game. It should load resource, cache them and return pointer by passed key. I'm using a few maps which handles different resources types and a few functions for each stored type. How bad is that? In other words, I have ~3 functions which do the same but with different types.
What does a "resource manager" do?
What "managing" does your resources need?
What you're describing is a cache, not a "manager". So name it ResourceCache, not ResourceManager
MagicCachingResourceLoader
@jalf allocated memory or other resource.. please use patterns in your design
@jalf For example, in level file of the game resources are described in a way: "SomeTitle" => "Media/img.png"
In code there is: ResourceManager::Fetch<Texture>("SomeTitle");
@Damian huh?
Aug 8, 2012 11:35
@Ockonal Is that a factory pattern you are trying to implement?
Please don't use patterns in your design.
@Damian Are you serious? You are everything that's wrong with the "patterns" movement".
@CatPlusPlus Why not?
Especially "I don't even know what my class does so I call it 'manager'" pattern.
4
Design patterns are fine to use when they match what you need. But what you are suggesting is "you must have patterns*, you must find some patterns to inject into your code, you must find a use for these patterns"
Aug 8, 2012 11:36
Why is it in the class if it's static anyway?
that is insane
@Damian Hm, let me read about factory
@jalf or for a cache use a small map and see if you called it before then give bacj the result if is is in the map
Xeo
Xeo
@Ockonal You don't want a factory, you want a resource cache
Ell
Ell
@CatPlusPlus you mean as opposed to a free function?
Aug 8, 2012 11:37
Yes.
@Ockonal: my point is that "Manager" classes never ever make sense. It's a sloppy "I haven't really thought about what this class should do, so I'll name it a manager" kind of thing
@Xeo Yeah, maybe you know some example realization?
Any time you consider making a "manager" class, ask youself "but what does it actually do?" and when you have the answer to that, rename the class
@Ockonal in a factory you have an abstract class as interface (or API) and then you implement the different types.. when you add or remove types your api does not need to change
your code will get much healthier
Aug 8, 2012 11:38
@jalf I always heard this, that 'manager' is a bad idea to call the class. But I don't agree
@jalf yes, I agree manager is a to generic name
When you change your wonderful abstract class you break the ABI.
@jalf LogManager, the title doesn't say what class work with?
This isn't Java. Don't write Java in C++.
@CatPlusPlus yes, so you need to think hard about the abstract class.
Aug 8, 2012 11:39
Are all of your classes managers?
@Ockonal It says that it works with the log. It doesn't say what "managing" involves
Xeo
Xeo
@Ockonal So, what do you "manage" on the log, with that class?
I have absolutely no fucking clue what your logmanager does
Just do EverythingManager and be done with it.
@jalf ABCManager, ABCController, ABCHandler, etc...
Aug 8, 2012 11:39
which means it's a terrible name
@CatPlusPlus Not all, but I have something like: LogManager, ConfigManager, DisplayManager
@Damian No, what you need to do is not use abstract class unless you need it.
@Ockonal and you are unable to describe to us what their "management" duties involve
Hint: you don't need it.
Xeo
Xeo
@Ockonal What does the DisplayManager do? What does your ConfigManager do?
Aug 8, 2012 11:41
I know someone who named all his classes Handler. A class that extracts documentation from an XML file? XMLHandler.
Manages, duh.
@Xeo They handles all staff needed to make single config interface work
ConfigHandlerManager.
@CatPlusPlus Lol :)
Xeo
Xeo
Does you DisplayManager put stuff on the screen? Call it Renderer. Does your ConfigManager allow you to access configuration options? Call it that, a "Configuration".
Aug 8, 2012 11:41
Poco libraries have a class named TaskManager.
Lemme guess, all of those managers are singletons.
All managers are simpletons
2
@Ockonal What is "all stuff needed to make single config interface work"?
Your class name tells the reader of the code nothing. Which means that it is a bad, useless name
Xeo
Xeo
If I ever write a style guide, manager is to be forbidden in the name unless they have a really convincing argument.
@jalf Handler to window, parameters for the window, handlers to opengl
Aug 8, 2012 11:42
What you need to do is learn Haskell and then come back to OOP.
it's also a crutch for bad design. You wrote a class with no clearly designed responsibility
@CatPlusPlus KISS principle
Go back to drawing board.
@Damian What about it?
Xeo
Xeo
@Damian Oh, so "thinking hard about your abstract class that overcomplicates things" is now "Simple"?
If DisplayManager has methods like getCurrentDisplay, getNumberOfDisplays etc then perhaps it isn't a bad name. You need to give it a name after all.
Aug 8, 2012 11:43
@Xeo Maybe we should. The Glorious Lounge Style Guide.
@CatPlusPlus avoid abstract classes before you need it.. so that must be the KISS principle
In Which You Suck At Writing Code.
@StackedCrooked Yeah, it does what you described
I don't know, I'm not the one who feels the need to name common sense applications.
@StackedCrooked You could just name it Displays, for example. The class represents your displays.
Aug 8, 2012 11:45
@Damian Isn't that the YAGNI principle?
@jalf If the class does
@StackedCrooked ;-)
does'nt represent only displays?
@Ockonal If it does more than that, you mean?
Then it should be split into multiple classes
Go back to the drawing board
Aug 8, 2012 11:47
What's drawing board?
each class should have one responsibility. And that is why manager classes are bad. They're where you put all the responsibilities you havent' really thought about
and then you end up with messy, bloated classes which mix 8 different areas of responsibility
@Ockonal it's an expression meaning basically "start over". Redesign the class
@jalf Okay, thanks. I understood the problem
To tell the truth, not all of my manager classes know much about different parts of logic. But they are still called managers
I've tried to call managers only some base workers
Something like 'core'
8 mins ago, by sehe
All managers are simpletons
a client of my father once called him a "simpleton"
did not go down well
Ell
Ell
when are singletons okay?
Aug 8, 2012 11:51
NEVER
 
Conversation ended Aug 8, 2012 at 11:51.