Friday, May 11, 2012

Java Rant

I've been a PC software programmer since my first job as an engineer back in 1984.  At the time, PC's ran MS-DOS, the only real available language was Basic, and I wrote business applications in the now-defunct database languages of dBase and Clipper.  When Borland's Turbo Pascal came out I immediately got a copy and read the manual from cover to cover.  It was very easy to use, extremely fast, and beat the pants off of anything Microsoft put out.  Which is why Bill Gates worked so hard to put the company out of business and establish Visual C as the dominant product on the market.  Visual C was a dog - horrible to write with and taking up to 15 minutes to compile a simple "Hello World" program.  At this point, though, I moved to Japan and started working as a technical writer, so programming took a back seat for several years.  However, I became a business major, and was able to get Adobe Flash at student prices, and I focused on making my own animations in Javascript.  I liked JS, but it was a very sloppy language, and really hard to debug if the code was not extremely-well documented.

At the end of the 1990's, I got a job as a customer trainer for a company that used a Fortran-based language for writing test programs, and they were just switching over to a new system built on Visual C++.  So, I was back to learning a Microsoft product, which was, mercifully faster, at any rate.  To support writing test programs, I also picked up Visual Basic Script (VBScript) and Perl.  VBS was ok for writing simple personal projects, but doesn't support reading binary files, which I really needed for my Japanino projects, and Perl doesn't draw graphics.  A couple of years ago my laptop crashed and I lost my copy of Flash, and it's now too prohibitively expensive to buy at MSRP.  This means that since I'm back in Japan and writing code for myself, I didn't have an easy way to make animation anymore.

So, last Fall, I bought a copy of the Head First Java book, and downloaded Java from the Sun website.  The nice thing about Java is that it's free, and it's designed for handling web-based media like images, videos and sound.  The bad thing is that a lot of the money made on supporting Java as a language comes from training classes so the documentation is really hard to navigate and the online examples are painfully trivial.

Head First is 700+ pages and took about 4 days to read cover to cover. I'd thought that once I had enough background I'd be able to start copying the examples from the book and make my own test game just to get a better handle on the principles.  That's when I found that following the guidance in the book and writing code directly in notepad makes GUI layout almost impossible.  So, I downloaded Netbeans, and learned that the examples in the Head First book don't translate to Netbeans.

Further, the more I tried to learn how to simply draw one image over another, the more frustrated I got with the online documentation. There's no simple search function, and the table of contents doesn't take me directly to the list of classes needed to do what I want.  I haven't used the Sun Microsystems official documentation since I started using Netbeans. Instead, I've chosen only to reference example code written by people on the net.  And this is where I hit another stumbling point - most of the other examples are also painfully trivial and not intended to be used as a part of a Netbeans project.  This means that the examples don't work for me unless I drastically rewrite them and completely change the syntax; and finding the correct syntax is what I was looking at the examples for to begin with. But, I've been lucky. In some cases I've been able to stumble across examples written by real programmers that do what I want to do. In most other cases, I've had to wade through the syntax-sensitive help within Netbeans to track down the classes I need for certain specific tasks.  It's still too time-consuming, though.

What prompted this rant is that I wanted to write a simple applet for handling the birth and death dates that I post occasionally on Mondays. Initially I started out by putting them in an Excel spreadsheet, but that was going to get hard to work with for finding dates within a specific range, or determining if someone was already in the database, especially if I got much over the 80 people I'd already entered. (I didn't want to resort to Microsoft Access, because I think it looks ugly.)  I'd thought that the Java applet would take no more than 2-3 hours. Then I got tripped up on some "string array index out-of-bounds" errors, and that took several hours to resolve and figure out how to implement the error handling code.  What really killed me was that I wanted to sort objects alphabetically, and ALL of the examples I found, including those on the Java site, were for sorting simple strings or numbers. And the documentation specifically states that the the built-in routines WON'T work for objects.  It took another hour to find a practical working real-world example. What I thought would be 2-3 hours took 10 hours to finish.

Another thing I'm still coming to grips with is exception handling.  When a Netbeans app is running, the standard error window is practically minimized. If an exception is thrown, I can't see it happening, and then I waste time trying to figure out why the program is still running but there's no output being displayed.  Try-throw-catch blocks are usually only for one or two specific exceptions, and any others that do get thrown don't get caught inside the app.  So, I'm just now figuring out which exceptions are the most common and how to trap them to keep them from messing up the behavior of the rest of the program.  (Specifically, ill-formed strings used for file saving/reading, and formatting for dates.)  I want the program to display the ill-formed string and let me correct it, instead of crashing because "01/12/2011" was mis-entered as "01/122011".  Naturally, the ideal would be to validate the strings at data entry, and I can't find examples for date validation online.  Sigh.

There are tons of Java applets on the net now, so I have to assume that other people have gotten past the stage I'm at, and actually do think of Java as a decent programming language, and Netbeans as a useful development environment. I'm close to halfway in my Kagoshima-based adventure game, so I'm not going to give up on Java.  But, it just unnecessarily takes too much of my time trying to get stuff to work right.

No comments: