Page 1 of 2

java?

Posted: 09 Feb 2007 02:36
by Vano2000
i was wondering if it would be possible to translate the current code into java.
I know it would be a lot of work so it's not a request, just a question.
how different is the current syntax from java syntax and is it possible at all to translate it to java.
i'm currently studying java, getting my degree, so i will soo start looking for ways to translate this code into java. but before i even start thinking about it i just want to know if it's possible?

Posted: 09 Feb 2007 04:26
by DaleStan
Possible? Of course. Everything's possible.

The real question is whether or not it would run with anything vaguely resembling a framerate.

Posted: 09 Feb 2007 04:50
by Vano2000
yeah i have heard that java is somewhat slower, but will it really have a huge impact on the speed and performance

Posted: 09 Feb 2007 07:48
by Sleepie
I think the real question is Why you would do it? As Dalestan said, everything is possible, but what would be the benefit of doing it?

Posted: 09 Feb 2007 08:40
by Born Acorn
The only reason I can think of is that a lot of people learn java in schools and colleges, so a lot more people know it.

Posted: 09 Feb 2007 11:37
by Vloris
That sounds to me more like another reason not to convert it to java: with that many people understanding (or at least thinking they do understand) java it's much harder to guide the development in a controlled way :)

Posted: 09 Feb 2007 14:23
by charlieg
Development is controlled by the project leaders through savvy SVN commit priveleges, so that's a complete misdirection to suggest more potential contributors is a bad thing.

Also Java GFX performance these days is pretty good; it's a bit of a myth that it's so bad, a myth perpetuated by people who don't know how to do GFX programming in Java properly.

Still, the notion of moving to Java for OTTD is fantasy at best. The work involved is astronomical; you are talking basically a ground up redesign and rewrite of the code because the current OTTD codebase does not lend itself at all to the programming concepts fundamental to Java.

The only [barely] realistic path would be for a move to C++ but even then I don't know if that would bring any tangible benefits.

I would give up on this. You are better off starting your own version / own game if you want to use Java.

Posted: 09 Feb 2007 14:57
by richk67
... would be a move to C++ ...

I thought we already were ;)

OK, not everything is in classes and objects etc yet, but the code is now .cpp and .hpp, and some parts (YAPF) are already C++ anyway.

Posted: 09 Feb 2007 16:02
by Bjarni
Java is not happening. The only real benefit would be to be able to use it on several platforms where C(++) code needs porting. Since we already did the porting part, we will not benefit from Java at all. It's slower to use the byte code than the CPU specific code nomatter how well you optimise it, so it will always have a speed impact to use Java instead.

A lot of people want to use Java because they think it's easier, but I'm not so sure. If the time spend on learning Java were spent on C instead, that person would become a C coder and will be able to do a lot of nice C code. If not, then that person spent too little time with Java to make nice Java code.

Posted: 09 Feb 2007 18:15
by Ailure
While Java is good, have a future it's... well. Java have A LOT of flaws that would make a game originally programmed in assembly a bit slower. ;) There's no good generics, things like enums is ugh. Simple Enums as they work in C++ is non-existant.

Performance isn't as bad as people want to make it though, as while Java is slower than C++, it's just is slightly slower than C++ in certain cases. Java tends to have extra overhead, and it's VM likes to take reserve a quite bit memory. Besides I suspect openTTD is programmed in a such way that wouldn't work well with Java. :P

Besides C++ is flexible enough, while I like Java for it's flaws I tend to prefer C++ for stuff such as openTTD.

Java and C++ is very similar code-wise anyway. I don't really see a reason porting over. If you feel comfortable, you should be able to handle c++ after a few hours, biggest difference is mostly stuff like pointers, memory managment and some generic programming.

Posted: 09 Feb 2007 20:24
by Vano2000
so what is the code used now in ottd? C, C++ ???

Posted: 09 Feb 2007 20:41
by DaleStan
Mostly, it's C compiled with a C++ compiler.

Posted: 09 Feb 2007 22:57
by Sacro
Ailure wrote:as while Java is slower than Java
Please don't make my brain hurt...

Posted: 10 Feb 2007 00:12
by Mchl
The main benefit I see in such enterprise, is that the fully object oriented Java code could be then converted back to C++.
But would it do any good?

As one of my colleagues put it:' Java. Yeah. User friendly etc. Everything's an object. Even things that shouldn't be or by definition cannot be objects.' :wink:

Vano2000: You'd probably spend your time better by writing JavaTTD from scratch... Or by learning these few (ok, I know there are many, but most common syntax is almost the same) differences between C, C++ and Java and start contributing here :)

Posted: 10 Feb 2007 00:37
by KeeperOfTheSoul
You really should be studying how do program as opposed to a specific language. A language can only really be considered useful as a working example. A language really is the easy bit, the difficult bit is understanding how the application works and fits together. By the time you've read through enough of the code to work that out you'd have most likly picked up C by then from just reading through enough code.

I myself havn't done much with C/C++ and currently wouldn't be able to write an app from scratch in this language. This doesn't really hinder me too much though, I just take slightly longer to work things out as I learn new things about the language. As I've said, the hard bit is working out how things fit together.

So really if your interested in the project your time would probaly best be spent getting a broader range of languages so you can understand some of the basic differences between them.

It isn't too difficult to create some of the simpler patches to fix small anoyances (such as I didn't like the way changing the window size would affect the fullscreen size). So I'd advise you just jump right in and learn something new, you'll get enough time with Java on the course.

Posted: 10 Feb 2007 00:44
by Ailure
Sacro wrote:
Ailure wrote:as while Java is slower than Java
Please don't make my brain hurt...
Grr, I wish I stop making those stupid typos.

Fixed for clarity.

Posted: 10 Feb 2007 08:30
by KUDr
In C++ you can make the same constructs like in Java plus much more (low level things). What would be different when doing such game in Java?

● You can still do dirty hacks in Java that will break original design, you can still use hard-to-read constructs in Java, etc..
● What you can't do in Java are low level optimizations to minimize memory and CPU load.
● Object arrays are arrays of managed pointers, local variables of type class are managed pointers as well and objects are always allocated from gc managed heap. They are destroyed later (in unpredicable way). Such non-deterministic core behavior would not help us to make the code better or faster.
● Most powerfull features of Java (synchronization, dynamic bindings, reflection package, etc.) would not help us a lot as they are slow. Maybe for the future processors (8 and more cores) it would make sense (if we find a way how to use more threads in this game).

Posted: 10 Feb 2007 15:48
by Vano2000
so what you guys are saying is
Java = bad,
C++ = good.
Got it. I was learning C++ before i started java so i gues i'll just continue C++
thx

Posted: 10 Feb 2007 15:52
by KUDr
No, Java is not bad (i like Java). Just not the best one for such game working with tons of low level data in real time with limited CPU/memory (in order to run on old HW).

Posted: 10 Feb 2007 16:44
by Bjarni
Actually I would say that the most important reason not to change the programming language is that it would take ages to do so. Even changing to C++ took a while and those two are so similar that C++ can compile most C code.
Now that we have C++ (with the option of adding C code if we like as long as we link it in C++ mode), we should do rather nicely. No need to change anything.

Note: even though the game is now written in C++, it's still the same code (more or less) as when it was written in C, so it's basically C with a few C++ additions. It's not really an objective design as we don't use classes and inheritage (yet?). Any C coder without knowing C++ can still work on it.