camelCase
The Case of the Mysterious Camel.
- Reaction score
- 362
So, I'm in school now where I can't access Facebook or Stack Overflow so I can't ask anyone else. There was a dispute between my lecturer and I regarding code architecture and design when developing apps for resource constrained environments (like mobile phones).
My game has 112 classes. 70 for the game engine and 42 for the actual game (the answer to life!). The lecturer slammed me and told me that it was "bad design" because the overhead would kill mobile phones. I didn't get it because my phone's 1GHz CPU and 256MB RAM runs the game at 62FPS.
She said that this project will never encounter the issue but if I was maintaining the code for WoW, such "over-engineering", as she called it, would kill the game's performance because 112 is really too many classes.
I still didn't understand (and still don't). For something like, WoW, I would expect that a clean design be even more important and that the overhead (if any, is there even overhead from having too many classes? I thought stuff compiled into assembly strips every notion of a class?) would be negligible.
My game has 9 state classes (excluding the base class):
StateClouds
StateCredits
StateGameover
StateGameplay
StateLoadAssets (preloader)
StateMainMenu
StatePause
StateScreenFade
StateSplashScreen
She said that they should all be thrown into one gigantic monolithic class. Which would result in a total of 127+47+152+202+124+160+84+121+92 = Whatever the fuck, it's a huge number anyway.
That's excluding the resource manager class I have for each state (like, each state has some resources like sound, music and bitmaps that it allocs and deallocs and whatnot; AssetsClouds, AssetsCredits, etc.).
So, my argument was that I'm not particularly smart and that each class should have ONE SINGLE responsibility, if possible (I understand how hard it can be to achieve that with the pressure of deadlines in the real world). This separation of responsibilities makes it easier to deal with code (maintain, extend, debug, etc.) because a lot of the other stuff it is abstracted away and can be assumed to magically work when you're not dealing with them.
She says that 112 classes is still too much and it was akin to splitting up the Android "Canvas" class to "CanvasCircleDrawer", "CanvasRectDrawer", etc. Basically, she was going to the extreme end of converting every function into a class, which I felt was particularly dumb.
I told her that if, somehow, overhead for the classes ever got too high, the profiler would alert me and I'd optimize it away, then because my classes, nicely separated as they are, can easily be copy-pasted into one monolithic class and made to work with minimal changes. WHICH IS THE WHOLE DAMN BEAUTY AND POINT OF SPLITTING CLASSES UP BY RESPONSIBILITY!
But she turned it away and said that it was "dumb" because I should "foresee" that "classes introduce a lot of overhead" and would kill the CPU or w/e. And I should be as reserved as possible when splitting classes up.
She gave up in the end and said it was her two cents for having worked in the industry for many years. I don't want to believe she's being a fucktard because someone who's worked for so long and is qualified enough to be a lecturer should have an inkling of what she's talking about.
Could someone shed some light on all this? Especially the overhead regarding classes? Like, I always felt it was a non-issue.
I told her that if I ever had to optimize anything, it would be the graphics because it's taking up 70% of the CPU time.
Looking for valuable insights. Like, your experiences with "real-world projects" and how finely split your classes are and whatnot. I duno'.
My game has 112 classes. 70 for the game engine and 42 for the actual game (the answer to life!). The lecturer slammed me and told me that it was "bad design" because the overhead would kill mobile phones. I didn't get it because my phone's 1GHz CPU and 256MB RAM runs the game at 62FPS.
She said that this project will never encounter the issue but if I was maintaining the code for WoW, such "over-engineering", as she called it, would kill the game's performance because 112 is really too many classes.
I still didn't understand (and still don't). For something like, WoW, I would expect that a clean design be even more important and that the overhead (if any, is there even overhead from having too many classes? I thought stuff compiled into assembly strips every notion of a class?) would be negligible.
My game has 9 state classes (excluding the base class):
StateClouds
StateCredits
StateGameover
StateGameplay
StateLoadAssets (preloader)
StateMainMenu
StatePause
StateScreenFade
StateSplashScreen
She said that they should all be thrown into one gigantic monolithic class. Which would result in a total of 127+47+152+202+124+160+84+121+92 = Whatever the fuck, it's a huge number anyway.
That's excluding the resource manager class I have for each state (like, each state has some resources like sound, music and bitmaps that it allocs and deallocs and whatnot; AssetsClouds, AssetsCredits, etc.).
So, my argument was that I'm not particularly smart and that each class should have ONE SINGLE responsibility, if possible (I understand how hard it can be to achieve that with the pressure of deadlines in the real world). This separation of responsibilities makes it easier to deal with code (maintain, extend, debug, etc.) because a lot of the other stuff it is abstracted away and can be assumed to magically work when you're not dealing with them.
She says that 112 classes is still too much and it was akin to splitting up the Android "Canvas" class to "CanvasCircleDrawer", "CanvasRectDrawer", etc. Basically, she was going to the extreme end of converting every function into a class, which I felt was particularly dumb.
I told her that if, somehow, overhead for the classes ever got too high, the profiler would alert me and I'd optimize it away, then because my classes, nicely separated as they are, can easily be copy-pasted into one monolithic class and made to work with minimal changes. WHICH IS THE WHOLE DAMN BEAUTY AND POINT OF SPLITTING CLASSES UP BY RESPONSIBILITY!
But she turned it away and said that it was "dumb" because I should "foresee" that "classes introduce a lot of overhead" and would kill the CPU or w/e. And I should be as reserved as possible when splitting classes up.
She gave up in the end and said it was her two cents for having worked in the industry for many years. I don't want to believe she's being a fucktard because someone who's worked for so long and is qualified enough to be a lecturer should have an inkling of what she's talking about.
Could someone shed some light on all this? Especially the overhead regarding classes? Like, I always felt it was a non-issue.
I told her that if I ever had to optimize anything, it would be the graphics because it's taking up 70% of the CPU time.
Looking for valuable insights. Like, your experiences with "real-world projects" and how finely split your classes are and whatnot. I duno'.