How to Log and stay Modular

Started by
55 comments, last by ApochPiQ 12 years, 7 months ago
I agree with the general sentiment that you are over-engineering, or that you are forcibly applying the principle of EVERYTHING MUST BE AN OBJECT which you may have picked up at college / uni. OOP is a methodology of programming, not an ideology.

When it comes to logging, you have a finite number of options.

1) Create a new logger and then throw it away every time you want to log something
2) have a single global logger. (no, I didn't say singleton, I said single global instance, the terms are not synonymous)
3) use a free function, or depending on the language, a static function.
4) pass a logger to every single constructor of every single object your game uses.

It should be obvious from these choices what the correct course of action is. Let the academics continue to think inside their little boxes up there in that ivory tower while you like, get some work done.
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!
Advertisement
Okay thank you to all of you for your replies! I think I finally have a grasp on what I should do.

Thanks,
Brent
Some say, 73% of GTA4's 100 million dollar budget went into the logging system alone.
On 9/3/2011 at 7:02 AM, Katie said:

" but globals are bad right?"

No, they're not. They're bad if you're an academic computer scientist. Academic computer scientists never actually have to ship code. Globals work, use what works, ship code.

The only reason academics are even aware of the troubles of global variables is because professionals, who were trying to ship products, discovered that global variables were one of the culprits keeping them from doing so, by making their code-bases unstable and unpredictable.

The biggest problem with the idea that "glabals are bad" is that it's so basic and so easy to remember and file away, that sometimes when it comes to implementing something and that old concept pops up a red flag, we might forget to take a moment to ponder the issue again, think about what exactly the problem was, and how exactly it applies to our current situation, if at all.

It would have been bad to let the concept back a code-base into the corner of passing a log object to every single function call. But as it happens, that doesn't mean the concept is wrong, just a little too easy to under-think.


I agree with the general sentiment that you are over-engineering, or that you are forcibly applying the principle of EVERYTHING MUST BE AN OBJECT which you may have picked up at college / uni. OOP is a methodology of programming, not an ideology.

When it comes to logging, you have a finite number of options.

1) Create a new logger and then throw it away every time you want to log something
2) have a single global logger. (no, I didn't say singleton, I said single global instance, the terms are not synonymous)
3) use a free function, or depending on the language, a static function.
4) pass a logger to every single constructor of every single object your game uses.

It should be obvious from these choices what the correct course of action is. Let the academics continue to think inside their little boxes up there in that ivory tower while you like, get some work done.


Option 4 with IoC wiring app/domain services is best.

" but globals are bad right?"

No, they're not. They're bad if you're an academic computer scientist. Academic computer scientists never actually have to ship code. Globals work, use what works, ship code.

"really messes up my goal of keeping things modular."

Don't have a goal of being modular. Have a goal of "shipping code". What value to you is "being modular"? None. It's an **ideal**. It's not a goal. Your goal is to ship code. That means you get to sacrifice ideals sometimes. This could be one of those times.

You're over-thinking this problem. Everyone always does. Everyone thinks there's a problem with "logging" because it's always either too verbose or not verbose enough and it's never quite right and everyone thinks the way to fix it is to somehow make the logging production more complication.

The problem isn't with the logging. It's with the tool on the other end. Make your program be either "verbose" or "succinct" based on a flag. That's all you need on that front.

Then just output strings but have smarter tools looking at the output.

The UNIX world manages to handle tons and tons of logging using "syslog" which is hardly sophisticated. "syslogd", the program on the other end, that has versions which'll do everything up to handling global networks with millions of servers...

Don't try and solve your logging analysis problems during your log generation.


While of course shipping code is the ultimate goal, it shouldn't be the principle you use to override other design considerations either. Modularity isn't just a valueless ideal, it helps in both designing the infrastructure of the system and in maintaining the system when bugs start to creep in. If your design isn't modular, then when you want to fix issues with rendering, for example, you need to be aware of how your collision detection works, and what game logic is affected and a hundred other things that you might have linked there because it 'worked', at the time, and it meant you got to ship that much faster. The result of ignoring modularity to ship code is that your code base gets spaghettified, which accrues ever increasing costs for maintenance and reuse later on.

You can go overboard, of course, with the issue of logging for example, but you shouldn't rail against programming ideals just because in the trenches you can't always see the value to spending more time in the design.

The biggest problem with the idea that "glabals are bad" is that it's so basic and so easy to remember and file away, that sometimes when it comes to implementing something and that old concept pops up a red flag, we might forget to take a moment to ponder the issue again, think about what exactly the problem was, and how exactly it applies to our current situation, if at all.


You need to fill a balloon or a blimp. Do you use hydrogen or helium? Helium.
Air cooled or water cooled engine? Water cooled.
4 stroke or 2 stroke engine? 4 stroke.

But, but, but... Each of the alternatives has advantages and tech has advanced and we can make it work and we've learned a lot and .....

This falls under engineering. You can always find an exception, there are always people who actually do know better (not just think they do), there might be a better choice. But it's rare to be working on a project that can benefit from those with people who are even interested into dealing with such tasks or where such gambles will have positive outcome.

Use the proven approach using methodology that was learned on hard failures on actual real world circumstances. Across thousands of projects, some methods are marginally better. And while 2% advantage on one single concept won't matter, combining different "better" ways will: 0.48*0.48*0.48*...* and the chance of failure is drastically affected.

Simple example - why do people claim globals/singletons are bad, then insist on using IoC/DI framework which commonly starts with singletons, yet doesn't exhibit any of mentioned problems? Because it's not globals/singletons, but most people involved in such discussions haven't been able to understand the true issues caused. So just don't use them.

But nothing.

This isn't a case of finding the exception to the rule, at all. It's a case of bothering to remember what that rule actually was in the first place.

"Money is the root of all evil", right? No. "The love of money is the root of all kinds of evil." Misquotes that are missing important nuance render reasonable ideas ridiculous.

It's easy enough to remember "gloabls are bad", but is there really much value in misremembering a principle and applying it incorrectly? Global variables cause problems. And they cause problems for a reason. Maybe remembering the 'misquote' is better than forgetting the issue altogether, but better yet is to take a second to understand the issue, so we can think about how the reasons apply to our situation.

"Just don't use 'em" is exactly the sort of thing that will have you trying to pass a log object to every function call in your codebase.

Yeah, there will be a lot of people who want to question various practices, and who might do so poorly because they don't understand the underlying reasoning (myself not excluded). But that's why we have colleagues and technical forums.

When discussing global variables, few people ever mention the security risks involved in using them.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

How is a global any more of a security risk than any other data in resident memory?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement