Friday, March 26, 2010

More Java good and bad

Netbeans 6.8 is awesome. Tomcat is awesome. Tomcat and Netbeans together are even better.

Sometimes tools are so good that even bad programming languages become easy and fun to work with. Nearly all of Microsoft's stuff is like that.

Maybe it's Java's object-oriented nature that lends itself to fantastic tools, or maybe it's the hype and money that have attracted the talent to produce these tools. I don't know. But Netbeans is a joy to use.

Java is getting better too, and if your problem lies in the domain where objects and easily pieced-together libraries are good solutions, then it's hard to beat. I thought I had one of those problems, but I'm starting to miss features from Lisp and Javascript, and even C.

I'm writing a software CPU for an educational game I'm working on in which you program robots to move around a game board. The CPU is similar to a 386; there are variable length instructions and instructions can operate on a byte, word, or double-word.

So here we are in the decode phase of the virtual CPU, and I've decoded the opcode, size, and source and destination. Here's where the fun starts. Most instructions do something to both operands and store the result in the destination operand. The problem is, the destination isn't always a register. Sometimes it's a memory address.

So I'd love to be able to pass a function that will store the result of the method that performs the CPU operation (ADD, SUB, AND, etc.) so that function could call that method when it has the result, should it need it. For other instructions (JMP, CMP, etc.) it could just ignore the function.

Failing that, it would be nice to at least be able to pass a reference to one of my registers or one of my memory addresses so the method could store the result directly. No such luck.

There's a very high-level way to solve this problem and a very low-level way (pointers), but Java has neither. That sucks.

0 comments: