Monday, May 3, 2010

How Good Is Java?

I wrote Forge using Java for mainly one reason: I know Java very well. I've worked with Java for a number of years and I enjoy it. Using Java has resulted in a few positive consequences such as Forge being portable and able to run on Linux and Mac which probably accounts for roughly 5-10% of the downloads. People from both communities seem excited to play Magic. Magic knows no boundaries, not even operating systems, ha.

I was worried that people might not have Java installed on their computer. While this may be a problem a small percentage of the time, most people seem to already have Java. Part of me really hates requiring users to download extra libraries like Java. I honestly thought about programming Forge in C++ because it wouldn't require any extra libraries.

(I personally see Java as a cleaner C++. Java seems to be at the same level of abstraction as C++ since both languages make it hard to pass a function to a function, so called higher order functions. And technically yes you can do it in C++, Java, and even in C if you want to but it is very messy.)

Java isn't perfect. It is a little slow and the default user interface will always look fake compared to normal Windows components. (Yes I know that this can be solved by using libraries like SWT which let you use native gui components. I already knew Java's Swing so I used it.) Other than that I can't think of any real weaknesses. Forge is a relatively straightforward program and I always knew that I could coerce Java to do my biding given enough time.

Java seems to be one of the more popular languages, at least according to langpop.com, which uses a variety of sources in order to calculate the popularity of computer languages. Language popularity is important because people might submit code if they know the language. Forge has around 3 active coders and two of them learned Java just so they could help out, "Hi Rob and Chris." (I'll say hi to Dennis, the current lead developer, so he won't feel left out.)

Other Magic programs that I know of have used languages other than Java. Incantus uses Python which lets you easily create higher order functions and has other properties of a dynamic language. Wagic is designed to work on a PSP uses C++ and has to deal with limited memory issues. (Just thinking about memory issues scares me half to death.) MagicWars uses Java and is based on Forge's code. And Firemox uses Java also.

For a quick summary of the above programs:
Player versus player over the Internet: Incantus, MagicWars, Firemox
Player versus the computer: Wagic, which also runs on Windows, Linux, Mac

Make sure to come back on Wednesday, I'll be posting a new version of Forge.

p.s.
On a side note, I have also taken Sun's Java Programmer's test. The test really helped me understand Java because it went over some obscure details. I would recommend taking a certification test for whatever language that you use the most because it would challenge you to learn the "nooks and crannies" that you normally overlook.

p.p.s.
And the most green mana symbols on a card goes to....Khalni Hydra with an outstanding 8. How many years will this record last? Who knows?

p.p.p.s.
I can’t seem to get done, too many postcripts. “C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, it blows away your whole leg” from Bjarne Stroustrup, creator of C++. I got that quote from the oustanding book “Expert C Programming” by Peter van der Linden. The book is mostly about C and answers obscure questions about C and dives in the mysterious world of pointers.

The book also answers the question of why this code snippet doesn’t compile. “Since the types char ** and const char ** are both pointers to unqualified types that are not the same type, they are not compatible types.

foo (const char **p) {}

main(int arg, char **argv)
{
foo(argv);
}

12 comments:

Anonymous said...

I'm your big fans in China.

Thank you for this great work, I love it.

I met a little promblem when using the program that I cannot see the pictures. I use the 0101 edition. And I cannot download the lastest one due to the internet issue, can you send to me? Thank you

Could you reply me to this email: andywang01cn@yahoo.com.cn

BrettW said...

You forget that in C++ (and perhaps Java) you can pass Functor objects that act like functions and are as difficult to pass as any object. It's clean and more able than simple function pointers. All it requires is overriding the operator ().

Silly Freak said...

java has no operator overriding, but this is a really cool idea! I guess this wouldn't work with parameters, right?

the ideal language for me would have
-closures (a lot like function pointers)
-strong typing (NOT like php... it's a mess)
-object orientation
-garbage collection

seems like I won't get that, right?^^

Ben said...

Silly Freak, I started researching a fairly new language again. It has some interesting concepts and meets your requirements pretty well. Although I would say it is a mix of functional and object oriented. F#.

And on a related point, I'm trying to figure out if the first class functions would make sense for a trading card game.

Silly Freak said...

nice find, except it's microsoft... ;)

Ben said...

Yeah, I know it is popular to insult Microsoft. Even if you're joking. For those who want something like F# but not run by Microsoft, check out OCaml.

Silly Freak said...

*partially* i am joking. except maybe vista, microsoft is probably doing a good job, and .NET, Active Directory and other things are definitely great for enterprises

but being an open source programmer at heart, coding in proprietary languages just feels wrong ;)

so just let me say, even though it's popular to insult Microsoft, i think my reasons are... reasonable. would you write a free program in a nonfree language?

Anonymous said...

Java = as fun as mowing the law :-(

mildly amusing, but less than stimulating.

nice program though.

Forge said...

Silly Freak,

I agree, closures are great and PHP is a mess. I've read some about Groovy which runs on the Java platform and it supports closures.

Forge said...

No one programming language is perfect but I think you can write beautiful code in any language.

Well...probably not Cobol, ha. And yes I've done my stint and written actual Cobol programs in college.

Forge said...

For awhile Java was proprietary but it seemed like open source since Sun was giving it away. I think now an open consortium now "owns" Java and proposes new features.

And does anybody remember the j++ fiasco, link. Microsoft licensed Java from Sun and then implemented their own extensions. Sun won and Microsoft went on to create C#.

Anonymous said...

On JVM you have Scala which has all that you have listed:
- functional (you get closures and other goodies)
- strong typing
- object oriented
- garbage collection
- Java compatible as it runs on JVM you can invoke your old Java code