Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  IoC/Dependency Injection  (Read 4388 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Wizard


Medals: 49
Projects: 4


I always win!


« Posted 2007-11-01 10:43:46 »

Hi,

I've been experimenting with this technique lately with Spring, mainly web based systems, and I like it.

I wonder, has anyone used dependency injection for games? I'd be happy to read someones experience with this.

Note, I don't really know how I would use this for games, but it might be well worth taking a look at.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline cylab

JGO Knight


Medals: 34



« Reply #1 - Posted 2007-11-01 15:20:04 »

IoC is made for application composition of more or less independ components or services. If you would write a modular game engine, IoC could be valueable. I would say it depends on the size and overall architecture of the software system you want to create, if using IoC can help you.

Mathias - I Know What [you] Did Last Summer!
Offline thiagosc2

Senior Newbie





« Reply #2 - Posted 2007-11-01 21:40:01 »

IoC is nonsense.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cylab

JGO Knight


Medals: 34



« Reply #3 - Posted 2007-11-01 21:57:52 »

Quite successful nonsense. Smiley What backs your statement?

Mathias - I Know What [you] Did Last Summer!
Offline thiagosc2

Senior Newbie





« Reply #4 - Posted 2007-11-01 22:51:52 »

Quite successful nonsense. Smiley What backs your statement?

Framework-itis. Java developers tend to over-engineer everything. If I need A, B and C why in the name of God would I need to "inject" things so I can put the whole alphabet there? If you have any experience in projects then you realize things don't change that often, and if they change it might cheaper/faster just to add a new letter there instead of abstracting the whole world. Spring is just a hack for enabling Java to do things that in other languages would be possible.

Athough I dislike Ruby and, above of all, the mystical-amazement-and-full-of-emotions way that Rubyists and their sect of zealots describe programming, I have to agree that Java may be painful sometimes not because of Java, but because of monstruosities like Spring that will force you to go through reams of XML in order to do the simplest things.

Conclusion: Spring is a non-solution for a non-problem.
Offline Martin Strand

Junior Member





« Reply #5 - Posted 2007-11-01 23:38:19 »

IoC is nonsense.
For any kind of software with a plugin-like architecture, a good IoC container that supports distributed configuration (not Spring I believe) is absolutely invaluable. Perhaps you're only writing small Tetris and Pong clones so you've never had the need for IoC, but I'm afraid that doesn't make it nonsense in general.
Offline thiagosc2

Senior Newbie





« Reply #6 - Posted 2007-11-02 00:18:43 »

For any kind of software with a plugin-like architecture, a good IoC container that supports distributed configuration (not Spring I believe) is absolutely invaluable.

I disagree. You can't get rid of dependencies, you only move them from Java code to XML making everyone's lives a hell.
Offline Martin Strand

Junior Member





« Reply #7 - Posted 2007-11-02 01:20:46 »

Perhaps you're just confusing the IoC concept with a particular container (Spring)? XML has nothing whatsoever to do with IoC. Spring uses it for configuration, but other containers such as Guice, picocontainer or tapestry-ioc don't.
Offline princec

JGO Kernel


Medals: 284
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #8 - Posted 2007-11-02 02:33:49 »

What's all this IoC rubbish then?

Cas Smiley

Offline appel

JGO Wizard


Medals: 49
Projects: 4


I always win!


« Reply #9 - Posted 2007-11-02 09:28:10 »

Oh, I totally agree that XML can be the leading cause of headaches!

But, I wonder how you could practically use IoC in game programming. I've often wondered how I could design my games better.

Instead of hacking into the java code the level creation, creating instances of monsters, what kind of weapons those monsters have, what AI level, and the enviroment, you could do it in XML.
- just a quick thought of it's practical uses, I might be wrong about this approach.

edit:
On second thought, this should probably belong to a external configuration file, not framework specific issues.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cylab

JGO Knight


Medals: 34



« Reply #10 - Posted 2007-11-02 10:18:11 »

IoC is about three things:

- Support the composition of modular systems using POJOs.
- Make your POJOs framework agnostic by reducing the dependency to the used services, not how to get them.
- Increase testability of your software system by externalizing the application composition to allow for Mock Objects.

If you don't need/like this, then IoC is not for you.

And it might be personal taste, but I like spring Wink

Mathias - I Know What [you] Did Last Summer!
Offline princec

JGO Kernel


Medals: 284
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #11 - Posted 2007-11-02 13:11:56 »

Still clueless Smiley What's it stand for? Is there an example of a real world problem it solves?

Cas Smiley

Offline Mr_Light

Senior Member




shiny.


« Reply #12 - Posted 2007-11-02 13:43:50 »

IoC is about three things:

- Support the composition of modular systems using POJOs.
- Make your POJOs framework agnostic by reducing the dependency to the used services, not how to get them.
- Increase testability of your software system by externalizing the application composition to allow for Mock Objects.

If you don't need/like this, then IoC is not for you.

And it might be personal taste, but I like spring Wink

euh, no. you above definition is very concrete and bound to programming, spring and mostly limited to Depenency Injection.
Depenency Injection is a pattern. It's about not making it the objects responsibily get it dependencies thefor creating/improving loosing coupling. principle of separating configuration from use.

http://en.wikipedia.org/wiki/Dependency_inversion_principle sums up DI quite nicely.
http://martinfowler.com/bliki/InversionOfControl.html
http://martinfowler.com/articles/injection.html#InversionOfControl

IoC / DI was coined and bound to programming but IoC really has a much wider scope, it's about controll flow. It's intesting in any system social, logic, etc.

Anyways IoC is relevant to games, as games are not stand alone and written in assembly anymore; they use frameworks. As far as DI goes it certainly has it's uses. And programming against interfaces was always a good idea. Nothing changing? what you don't profile apps? you only target one platform? You don't need to improve the game balance? besides nothing forces you to externalise everything, I mean I like consistency but no one is forcing you.

Also since 2.0 spring allows you to do everything with annotations if you really wanted too. also I don't understand the beef ppl have with xml, are you all still using notepath/vim to do your bisness? "I is is designed to be relatively human-legible" legible from Late Latin legibilis "that can be read", note how that doesn't include write persé you can always sausce that stuff with a fancy looking form or wizzard. Or perhaps ppl hate it with respect to quantity; ppl also introduced the concept of convention over configuration.

I found that the that whole part of of what spring introduces is far less intersting then using Aop to solve crosscutting concerns.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline cylab

JGO Knight


Medals: 34



« Reply #13 - Posted 2007-11-02 13:55:01 »

Quote
euh, no. you above definition is very concrete and bound to programming, spring and mostly limited to Depenency Injection.

Ok, I should have been written: "IoC is useful in programming for at least three things:" Wink

Quote
Nothing changing? what you don't profile apps? you only target one platform? You don't need to improve the game balance? besides nothing forces you to externalise everything, I mean I like consistency but no one is forcing you.

I don't get the point here

Quote
Also since 2.0 spring allows you to do everything with annotations if you really wanted too.

Which pretty much distroys the "separationg configuration from use" principle (at least pragmatically, since you have to recompile your app to change it's configuration)

Mathias - I Know What [you] Did Last Summer!
Offline kevglass

JGO Kernel


Medals: 85
Projects: 22


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #14 - Posted 2007-11-02 14:07:08 »

Quote
Still clueless Smiley What's it stand for? Is there an example of a real world problem it solves?

IoC stands for Inversion of Control, and as you'd expect it does what it says on the tin. You invert who has control (normally over the source of some data or entity). The classic example of IoC is synchronous vs event driven programming, you give control to your components and they notify you via events, rather than keeping control and blocking on result. The software example is normally related to using a TextField (which fires an event when the input is read) rather than calling readLine().

DI, or Dependency Injection is a form a IoC that gives control of your depedencies over to some external entity (the injector). The injector framework (there are quire alot now) is responsible for configuring your depdencies based on some meta data, which up to recently has mostly been a stack of XML but now seems to be moving towards annotations (at least in Java). A poor but apt example may be the implementation of the data driver you're using. Your code, as always, is only dependent on the data driver interface and holds an uninitialised reference to the driver it's going to use. The XML defined which driver implementation you want to use, and the injection framework is responsible at startup for creating the instance of the driver and linking up the reference to it.

There are several places in games development where injection could be useful above and beyond the normal software engineering use cases, resource injection for instance.

I'm not sure what parallel you're drawing with AOP though. Dependency injection is really an augmentation of existing OOM, AOP is a different way of looking at it. They don't solve the same problem afaik.

I'm also of the opinion that DI is total junk tbh, it's popular like many things in the enterprise world - because it ticks a technology box for architects everywhere. It's technical merit seems pretty limited to me. The concept IoC is perfectly sound though, just the DI frameworks in existence seem to be a bit pointless.

Long live AOP! Smiley

Offline Mr_Light

Senior Member




shiny.


« Reply #15 - Posted 2007-11-02 14:22:08 »

Ok, I should have been written: "IoC is useful in programming for at least three things:" Wink
  Tongue

I don't get the point here
was mostly in response to the "why should I do all that crap, I almost never changes" Was trying to point out that there are other uses that reimplementing your bisnesslogic or rewriting the UI or any other layer. there are more 'fine grained'/suble cases. Tis hard to explain and I can't think of a simple example of the top of my head.

Which pretty much distroys the "separationg configuration from use" principle (at least pragmatically, since you have to recompile your app to change it's configuration)
"..if you wanted too"  Wink

Also haven't looked into it but I hope XML overrides inline.
    
The following error or errors occurred while posting this message:
Warning - while you were typing a new reply has been posted. You may wish to review your post.


Oi kevin "bring's clairity" glass to the rescue.

Quote
I'm not sure what parallel you're drawing with AOP though.

Spring has populalised a number of techniques, DI beeing one of them AOP an other. Along the lines of "I'm working with spring now.....  ...can this be used in games" I was trying to point out that if you want to use/bring in a 'Spring' technique; then I would shift focus from DI to AOP.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline kevglass

JGO Kernel


Medals: 85
Projects: 22


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #16 - Posted 2007-11-02 14:31:55 »

Quote
Spring has populalised a number of techniques, DI beeing one of them AOP an other. Along the lines of "I'm working with spring now.....  ...can this be used in games" I was trying to point out that if you want to use/bring in a 'Spring' technique. Then I would shift focus from DI to AOP.

Ah, in that case I'm totally with you. I'm only recently getting into AOP, but it's changing my views on lots of things - it's a real eye opener Smiley

Kev

Offline cylab

JGO Knight


Medals: 34



« Reply #17 - Posted 2007-11-02 14:39:42 »

Sceptics say, AOP will introduce more trouble than vantages, since it not only hides controll flow (like DI) but large chunks of actual work from the programmer... but there are naysayers with everything Wink

Mathias - I Know What [you] Did Last Summer!
Offline Orangy Tang

JGO Kernel


Medals: 51
Projects: 11


Monkey for a head


« Reply #18 - Posted 2007-11-02 14:41:22 »

Ah, in that case I'm totally with you. I'm only recently getting into AOP, but it's changing my views on lots of things - it's a real eye opener Smiley
Kev
I keep meaning to look into AOP. What are you using, AspectJ? Whats the situation on IDE intergration/tools?

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline kevglass

JGO Kernel


Medals: 85
Projects: 22


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #19 - Posted 2007-11-02 14:47:37 »

I'm using the JBoss AOP, and mostly I'm not having engineer any, just understand how they've used it in the AS. So, I'm just ploughing through their AOP configuration and understanding what the hell is going on Smiley

Quote
Sceptics say, AOP will introduce more trouble than vantages, since it not only hides controll flow (like DI) but large chunks of actual work from the programmer... but there are naysayers with everything Wink

I think thats sort of right tbh, both AOP and DI seperate bits of the implementation in unexpected ways, making code harder to understand and maintain unless you really get the techs involved. However, the difference for me is that DI does this in a facet where you *have* to understand it no matter what you're doing and the pay off isn't very good, i.e. it allows you to configure your coupling elsewhere - something we've all be used to with factory methods for years. In the case of AOP unless you're interested in the advice being applied you should be able to ignore it - and the pay off is beautiful, applying cross cutting changes globally and being able to tweak at a moments notice without having to have made provision before hand - thats wonderful Smiley

Thought, my experience of AOP is much less than IoC/DI so I may yet to be experience the extreme downsides Smiley

Kev

Offline princec

JGO Kernel


Medals: 284
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #20 - Posted 2007-11-02 15:02:35 »

Ah right so IoC and DI is basically something we've all been doing anyway for years without even thinking about it (being programmers it's just a natural way to do things) and now it's got its own buzzword/TLA/acronym. Woopee.

I've been turned off by AOP because of the increasingly nasty syntax (on top of generics, it's all beginning to look like C++ to me) and because it effectively obscures the meaning of code as written. I like to see what something is going to do written in front of me. I'd rather type more code than something unexpected happen due to some other bit of code written elsewhere by someone else.

Cas Smiley

Offline kevglass

JGO Kernel


Medals: 85
Projects: 22


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #21 - Posted 2007-11-02 15:30:27 »

Quote
Ah right so IoC and DI is basically something we've all been doing anyway for years without even thinking about it (being programmers it's just a natural way to do things) and now it's got its own buzzword/TLA/acronym. Woopee.

Essentially, cept there are frameworks to make us all do it the same way now.

Quote
I've been turned off by AOP because of the increasingly nasty syntax (on top of generics, it's all beginning to look like C++ to me) and because it effectively obscures the meaning of code as written. I like to see what something is going to do written in front of me. I'd rather type more code than something unexpected happen due to some other bit of code written elsewhere by someone else.

Halt naysayer! Smiley

Kev

Offline princec

JGO Kernel


Medals: 284
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #22 - Posted 2007-11-02 15:34:42 »

Seeing as I don't have any problems AOP will solve I'll manage without for the time being, until my contracts depend on it, which they never will, because I'll be old and jaded before a language with built-in AOP becomes mainstream Wink

Cas Smiley

Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #23 - Posted 2007-11-02 15:58:39 »

So which language is already here?, seeing as the other criteria are already met Smiley

Offline noblemaster

JGO Ninja


Medals: 20
Projects: 9


Age of Conquest makes your day!


« Reply #24 - Posted 2007-11-02 19:17:00 »

Quote
Ah right so IoC and DI is basically something we've all been doing anyway for years without even thinking about it (being programmers it's just a natural way to do things) and now it's got its own buzzword/TLA/acronym. Woopee.
yes, but IoC and DI makes you sound cooler  Cool Cool Cool

Offline thiagosc2

Senior Newbie





« Reply #25 - Posted 2007-11-04 07:27:18 »

I've been turned off by AOP because of the increasingly nasty syntax (on top of generics, it's all beginning to look like C++ to me) and because it effectively obscures the meaning of code as written.

AOP is a kind of "goto". You can't tell what is going to happen just by looking at the code. Now that OOP is mainstream they need to come up with other cool sounding acronyms that end with " - Oriented Programming".  Blaaargh.

Thiago
Offline thiagosc2

Senior Newbie





« Reply #26 - Posted 2007-11-04 07:54:05 »

Also since 2.0 spring allows you to do everything with annotations if you really wanted too. also I don't understand the beef ppl have with xml, are you all still using notepath/vim to do your bisness? "I is is designed to be relatively human-legible" legible from Late Latin legibilis "that can be read", note how that doesn't include write persé you can always sausce that stuff with a fancy looking form or wizzard. Or perhaps ppl hate it with respect to quantity; ppl also introduced the concept of convention over configuration.

I will try enumerate some reasons:

- Separation between code and data: XML is only necessary because Java is not Lisp. In Lisp the structures for such "readable" things would the code itself, because in Lisp the code is data and you would have much more flexibility to work with it;

- Excess of code to handle the XML: choose your API, it will always suck. The data from the XML need to be read into some object. So that gives you the following manual work: create the schema, write the XML, read the XML into some object, use the object. Have we become assembly line workers? Have we become manual laborers? This mindless kind of work shouldn't be performed by humans. My time would be better spent by creating actual products;

- Dependence on version 0.0.1 pre-alpha plug-ins: This is the only way to make your life tolerable;

- XML abuse, or, XML because XML sounds cool: for example, in web applications the XML have absolutely no utility whatsoever. Won't you need to recreate the EAR and redeploy the app in the application server whenever you change anything anyway?

I have always wondered, why instead of using XML people just don't store that information in Java code? XML would only make sense for exchanging data between different systems, i.e., regardless of the platform the data would still be readable. XML is an exchange format and just that. Configuring anything with XML is just nonsense.
Offline Mr_Light

Senior Member




shiny.


« Reply #27 - Posted 2007-11-05 01:47:35 »

xml is lie sql handling of it shouldn't be all across your codebase

I'm gonna limit myself to spring a bit. and with reguard to that I can't say I've written a single line to handle actual xml.

not sure how "Dependence on version 0.0.1 pre-alpha plug-ins" factors in this discussion point on a very remotely related note I can see where that came from but thats hardly the case anymore.

theres no need to overuse xml but thats hardly xml's fault.

As far as why configure a spring app in xml because the xml was tailored to configuring beans it's much more powerfull then using plain java to do the same job. I gues most arguments for scripting langues can be insert.
With a few simplistic 'tricks' xml lines can be cut back alot. When I was still developing webapps and alike when comparing to the competitions setup I could easely cut it down to a 1/10 of what they had.

also systems administrators generally don't know how to compile program X, editing a few text files littered with tags is less of a problem. Why not use plain text over xml well xml can be validated outside the ap by using a schema.

Anyways Spring is a big wood; easy to get lost in, because of the hype most ppl ran in without a guide.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline cylab

JGO Knight


Medals: 34



« Reply #28 - Posted 2007-11-05 10:27:37 »

Anyways Spring is a big wood; easy to get lost in, because of the hype most ppl ran in without a guide.

Math.pow(above,10) for hibernate Wink

Mathias - I Know What [you] Did Last Summer!
Offline Breakfast

Senior Member




for great justice!


« Reply #29 - Posted 2007-11-05 13:41:51 »

I read half this thread seeing "LoC" instead of "IoC".

LoC is what Java has above most other languages- I can guarantee pretty much any Java app I write will end up with at least twice as many LoC as it's equivalent in another language, maybe four or five times relative to Ruby (and yes, Ruby is the easiest language to develop with- not my fault, I'm only a user )  - but in it's favour it's genuinely cross platform ( I've run into problems between Ruby runtimes between windows and Linux and don't even get me started on CPAN ) and this place is the best of it's kind - and of course, if I'm writing games I want a complied language, which java is, and I want one that means I don't have to do my own memory management, which java is.

I hate all this XML-powered nonsense though. It makes it look like as Java programmers we're going "Oh, we have a language that takes 10 lines to accomplish what most others can do in one, but that's just not verbose enough" so we have to put everything we can into an even more verbose and complicated format. The more I use things that aren't XML ( YAML, anyone? ) the less I see a need for it.

I mean, I'm sure it's great for the Enterprise. But then Enterprise got canned after a couple of seasons. I think we can all learn from that.

</rant> ;p
Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (72 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (79 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (80 views)
2014-04-14 15:48:38

tom_mai78101 (104 views)
2014-04-10 04:04:31

BurntPizza (164 views)
2014-04-08 23:06:04

tom_mai78101 (260 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!