Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  Using code generation in your game.  (Read 9295 times)
0 Members and 1 Guest are viewing this topic.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 842
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #30 - Posted 2012-04-02 13:47:50 »

Offtopic: regarding "over 9000", that is an internet meme, see:


Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 842
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #31 - Posted 2012-04-02 13:58:31 »

Java is verbosity. To avoid verbosity you usually go to other programming languages, for instance Python.
This is one of the worst arguments...
   "If you don't like a piece of X, abandon X and use Y instead"

The world isn't that black and white. We can workaround problems instead of completely discarding X.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Danny02
« Reply #32 - Posted 2012-04-02 14:14:03 »

Sorry, there is no way that writing out a new class is 9000x faster than updating my config file. [...]
ctrl+n, enter, "ShipArrived", enter -- created new class
"pf", tab, "f", enter, "x,y,z;", enter -- expands to public final float x, y, z;
"pf", tab, "i", enter, "entity;", enter
ctrl+space, down, enter -- creates constructor

finished
41  vs 49 keystrokes
and this only gets alot worse when you use classes, cause you have to write out the hole class path.

Besid this silly counting Smiley^^
What I wanted to explain to you is that refactoring is a big thing. And you can't do this with your approach. I also wanted to point out that you don't save any time with your code generation.

Part of the motivation for doing it in the first place is that I often find myself, adding, removing, and editing message types and this config file is an easier place to do this.
changing stuff == refactoring
which is much easier when you do it in the IDE, i.e. you change the name of a parameter
also when you change a single attribut of an message type, you have to rebuild all your messages, which is a lot of time you would waste. Editing a java class in your IDE doesn't take 10sec.

Furthermore lets look at a example
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
[In the Entity class, what I think you do]

public void processEvent(Event ev)
{
...
if(ev instanceOf AttackEvent)
{
AttackEvent tmp = (AttackEvent)ev;
  takeDamage(tmp.amount * getTypeMultiplier(tmp.type));
}
...
}

[with my code you just would "if else" over the data instead of over the event]


ps: don't get me wrong, writing such  tools by yourselfs is always a quite interesting thing to do, but in alot of cases it doesn't really is that usefull in the end. I don't want to bash your idea, but my problem with it is that you are just writing the classes in an own DSL which doesn't save you anything in the end(time, and characters to type)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline actual

JGO Coder


Medals: 24



« Reply #33 - Posted 2012-04-02 14:44:22 »

changing stuff == refactoring
which is much easier when you do it in the IDE, i.e. you change the name of a parameter
also when you change a single attribut of an message type, you have to rebuild all your messages, which is a lot of time you would waste. Editing a java class in your IDE doesn't take 10sec.

You bring up a good point. If I have an event type that is already in use in a number of places and I decide to change a parameter name (attackScore to damageDealt), make the change and  run the code gen, then change it where it is used, or I could do the refactoring in the IDE, in which case the generated class and then change the config file to match. Altering generated code is generally considered a big no-no though.
Offline Skarion

Senior Devvie


Medals: 2
Projects: 1



« Reply #34 - Posted 2012-04-02 15:07:11 »

Java is verbosity. To avoid verbosity you usually go to other programming languages, for instance Python.
This is one of the worst arguments...
   "If you don't like a piece of X, abandon X and use Y instead"

The world isn't that black and white. We can workaround problems instead of completely discarding X.

I prefer Java because of it's verbosity. Makes it easy to maintain even months after I stopped using the code, comparable to C++ or Python where you rather will gain more in rebuilding the whole thing.

Though I can't see why you would prefer Java over all other languages except as of it's verbosity. It's a nice language though it's not better than all other languages except if you consider verbosity a virtue.

I don't see how your proposed solution makes it better. The added abstraction layer of getters and enums will lead to increased code verbosity throughout the project, which is (IMHO) an even bigger problem than typing out all those classes by hand.

Maybe I'm mistaken, and you could enlighten us with a code sample.

Going from OP:

Quote
System.out.println("BOOM " + explosion.getFloat(STRENGTH));

Where the basic thing is to just do in this case enum STRENGHT instead of "strength".

You can even make it more fun with:

Quote
System.out.println("BOOM " + EXPLOSION(STRENGHT));
Offline longino

Junior Devvie


Medals: 1



« Reply #35 - Posted 2012-04-09 16:12:49 »

Quote
"Whoever does not understand LISP, he is doomed to reinvent it".

Metaprogramming makes perfect sense. Your problem is a very common problem that all developers reach at some point of their careers, because it is impossible not to notice certain repetitive tasks that could be automated somehow.

The problem is, Java is a terrible tool for that. That's why there are so many "frameworks" around. The language itself doesn't offer an easy way of generating code.

Dynamic languages like Python and Ruby are also bad, because their "metaprogramming" happens at runtime, not compilation.

Lisp has allowed developers to do what you want to do for the last 50 years. No extra libraries or frameworks needed, just the language itself.
Online Roquen
« Reply #36 - Posted 2012-04-11 09:51:15 »

I'm all for code generation, but I'm not seeing the need in this case with any of the given examples unless you're attempt some meta-uber-engine thingy.  Why not just classify types of events and use a data-driven model where the parameters are specified in a configuration file?  Do whatever works, but codegen seems like overkill without some concrete examples to show what "the problem is".

LISP is a fantastic language and very worthwhile to learn.  And I sincerely hope to never need to (directly) programming in it ever again.

Java is too verbose, but the larger problem here (IHMO) is lack of design.  Too little data-driven, too little composition over inheritance, etc.
Offline PaulReeves

Senior Newbie





« Reply #37 - Posted 2012-04-11 10:31:58 »

Sorry, there is no way that writing out a new class is 9000x faster than updating my config file. [...]
ctrl+n, enter, "ShipArrived", enter -- created new class
"pf", tab, "f", enter, "x,y,z;", enter -- expands to public final float x, y, z;
"pf", tab, "i", enter, "entity;", enter
ctrl+space, down, enter -- creates constructor

finished
41  vs 49 keystrokes
and this only gets alot worse when you use classes, cause you have to write out the hole class path.


Hi,

Not wanting to derail the thread but wanting to know more on expanding from "pf" to public final.  Is this an eclipse thing? if so which plugin do I need to install? Google search did not reveal anything to me.

Thanks
Paul
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #38 - Posted 2012-04-11 10:47:02 »

I think it's a customizable thing in the Eclipse preferences menu.

Offline PaulReeves

Senior Newbie





« Reply #39 - Posted 2012-04-11 12:40:56 »

Thanks

I will take a look when I get home.

Paul
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline longino

Junior Devvie


Medals: 1



« Reply #40 - Posted 2012-04-11 16:09:47 »

LISP is a fantastic language and very worthwhile to learn.  And I sincerely hope to never need to (directly) programming in it ever again.

http://www.paulgraham.com/avg.html

Quote
As long as our hypothetical Blub programmer is looking down the power continuum, he knows he's looking down. Languages less powerful than Blub are obviously less powerful, because they're missing some feature he's used to. But when our hypothetical Blub programmer looks in the other direction, up the power continuum, he doesn't realize he's looking up. What he sees are merely weird languages. He probably considers them about equivalent in power to Blub, but with all this other hairy stuff thrown in as well. Blub is good enough for him, because he thinks in Blub.

When we switch to the point of view of a programmer using any of the languages higher up the power continuum, however, we find that he in turn looks down upon Blub. How can you get anything done in Blub? It doesn't even have y.

By induction, the only programmers in a position to see all the differences in power between the various languages are those who understand the most powerful one. (This is probably what Eric Raymond meant about Lisp making you a better programmer.) You can't trust the opinions of the others, because of the Blub paradox: they're satisfied with whatever language they happen to use, because it dictates the way they think about programs.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #41 - Posted 2012-04-11 16:43:53 »

Lisp's an object lesson in what happens to great languages that lack great toolchains and ecosystems when combined with a community that denies either is a problem.  Clojure's nice, but it doesn't really renew Lisp any more than Ruby revolutionized Smalltalk.

Anyway, my favorite response to Paul Graham, probably one of the best put-downs in blog history: http://www.idlewords.com/2005/04/dabblers_and_blowhards.htm

Offline actual

JGO Coder


Medals: 24



« Reply #42 - Posted 2012-04-11 19:45:30 »

I see this has popped up again. Some good discussion here. I was using my Message set up as an example to ask about compile time code generation. Don't get too hung up on the particulars of this specific example and whether it is worth doing; it's of more interest for everyone to discuss it in general.

I am aware that LISP can do this but this is the Java Gaming forum so I was curious if anyone has done this in the context of Java.

Java is too verbose, but the larger problem here (IHMO) is lack of design.  Too little data-driven, too little composition over inheritance, etc.

I'm not sure how you can make this claim when what I have shown is so narrow ( essentially a list of different types of Event Messages). It is data driven, and I don't think that a bunch of Event Messages that have a common base type constitutes "too little composition over inheritance".
Online Roquen
« Reply #43 - Posted 2012-04-11 20:03:12 »

The "lack of design" was not directly targeted to this thread, but to the "verbose" problem.
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.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (29 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (98 views)
2014-12-08 04:46:31

JscottyBieshaar (58 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (76 views)
2014-11-29 21:32:03

toopeicgaming1999 (137 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (37 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!