Archive for May, 2004

Runaway Meme's

Wednesday, May 19th, 2004

Memetics is the subject of a book that I am reading. The basic idea is that like genes there are ideas or thoughts that are replicated and selected for fitness. These memes spread by human imitation and communication. Memes are selected for their ability to capture our attention in the face of other competing memes, and for their ability to induce in us the need to spread these ideas. A meme is that catchy tune that you can’t stop humming and everybody around you humming it now too. The hard part about accepting this is the fact that we don’t control these memes, in fact the good memes control us. You didn’t mean to hum that tune in a meeting and get it stuck in everybody else’s head. It robs you of a little bit of your free will.

So I was sitting in the dentists office today and that hygienist says don’t worry this won’t hurt. I thought to myself of course it won’t, you don’t need to tell me that. When has it ever really been painful to get your teeth cleaned, but then it happened I got scared and winced as she started. Of course it didn’t really hurt. The painful dentist meme was taking control, in the face of a professional reassurance, my collective experience, and my rationalization I still winced. That’s pretty powerful for just an idea. It makes you wonder what’s really running the show up in your head.

equalsIgnoreCase() is faster than equals()

Wednesday, May 19th, 2004

My intuition would tell me that String.equalsIgnoreCase() would be a more expensive operation than String.equals(). If you think about it you have a lot more combinations that you have to test. This is where reality diverges from intuition.

The first things that both String.equalsIgnoreCase() and String.equals() check is length, and I’m willing to bet that most strings aren’t the same length, so you’re done. The reality is that String.equalsIgnoreCase() may be faster in a lot of instances because its parameter is a String so it doesn’t need to check instance and cast before the length comparison like String.equals() who’s parameter is Object.

So don’t handicap your string comparison just because you’re worried about performance. With String.equalsIgnoreCase() you can be fast and flexible.

Exploding Car Tires

Wednesday, May 19th, 2004

I think that somebody should invent car tires that were hooked to your turn signal switch so that if you change lanes without your signal your tires would explode. Sure there would be a few accidents at first but people would learn fast.

Java Syntax I've never seen

Wednesday, May 19th, 2004

While reading an inner classes article I discovered some Java syntax totally new to me..
Say you write a public inner class like so.


public class Foo {
  public class Bar {}
}

If I wanted to create a new instance of Bar I would have to do it like so..


Foo foo = new Foo( );
Foo.Bar bar = foo.new Bar();

The foo.new is something that I have never seen before but it is refreshing to see something new like this in a language that you know so well. I suppose it fits with my understanding of the language since all constructors are compiled into static <init>() methods, and Bar’s constructor is in Foo’s namespace. After all new Bar() is just syntactic sugar for the static Bar.<init>() method in compiled code.

Jython in Action - John Carnell

Wednesday, May 19th, 2004

I attended an interesting speaking session last night at the Madison JUG. The talk was on Jython given by John Carnell.

My overall impression was favorable. I liked the functionality in Jython for executing scripts dynamically in Java code, the application that he suggested was business rules that change. You extract the rule logic out to a Jython script and then you can modify the application with out redeploy/restart/recompile. Another cool thing that John didn’t mention was that Websphere server administration tasks can be scripted in Jython which open possibilities for automated server configuration at deployment time, and easily managing your server configuration alongside your code.

I’m still left wondering what Jython adds to the mix that isn’t already addressed in Groovy. I know squat about python, but I though that Groovy (being modeled on Ruby) would have a few more tricks in it’s bag.

Long and short Jython looks cool and I’m planning on downloading it for a little playing around. John thanks for coming to the MadJUG. Ohh and check out John Carnell’s new publisher aPress John was raving about them and it looks like they have some gook books up-and-coming.

CLIE PEG-TH55

Wednesday, May 19th, 2004

I just got a PDA a CLIE PEG-TH55. I have been standing on the PDA sidelines for quite a few years. I’m sure that may of you are in the same position, can’t really justify the cost against the benefits. I finally just broke down and got one. I’m really surprised at the use that I’m getting out of the thing. I was pretty skeptical, thinking that it would just be a fun toy few days and they I would put it down. I have been using it everyday for three weeks now. I love keeping lists but I always manage to lose my list, having a $350 list you are not as apt to lose it. lol

The thing plays MP3’s you might guess that it is no IPOD but it does well for what I need. It also has a built in digital camera, which is excellent for its purpose taking quick pictures for display on a palm top device. The planner application is nice, but more than anything I play solitaire.

If any of you have suggestions on a good PalmOS Java VM to use. I’m still a little murky on the whole J2ME ecosystem. So many different mobile profiles and different specs. I could definitely use help in that area. I did however get a fun little Scheme implementation, and I have been playing around with that.

Disk Golf

Wednesday, May 12th, 2004

If you enjoy the outdoors and you haven't tried disk golf yet you're missing out. I'm from Madison Wisconsin and at least in my area we have a lot of courses springing up. If you aren't familiar with the sport it's golf with a frisbee. Instead of a hole there is a basket. The courses are usually in wooded areas with elevation changes. The disks you use are smaller than frisbees, and are chosen based of aerodynamics (glide, speed, and fade). Glide is hang time, more glide is more precise and longer throwing but more affected by wind. Speed goes hand and hand with glide but faster disks can drive farther and are less affected by the wind, but they are harder to throw accurately. Fade is the tendency of the disk to go left of right at the end of its flight path.

Basically it's a walk in the woods throwing a frisbee, but I never realized how fun it was until I tried it. If you enjoy the outdoors you should give it a try.

A Hindu Mondo, Retold

Monday, May 10th, 2004

A Hindu Mondo
Once, a yogi meditating on the bank of the Ganges who noticed a scorpion fall into the water. The yogi scooped it out, and for his kindness was bitten. Soon the scorpion fell again into the river. Once more the yogi scooped it out. Once more the scorpion bit him. When the sequence was repeated twice more, a bystander demanded, “Why do you keep rescuing that scorpion when its only gratitude is to bite you?”

“It is the nature of scorpions to bite.”, replied the yogi. “And it is the nature of yogis to help others when they can.”

Retold
Once, a developer was working on a large software system and noticed an improvement that could be made to the UI. The developer tweaked the UI, and for lack of strict adherence to the requirements was bitten. Soon the usability of the system could be improved again. Once more the developer made a correction. Once more the clients bit him. When the sequence was repeated twice more, a bystander demanded, “Why do you keep fixing issues when the clients only gratitude is to bite you?”

“It is the nature of clients to bite.”, replied the developer. “And it is the nature of developers to produce quality software whenever they can.”

How to do OO on a stack machine.

Monday, May 10th, 2004

I’m no expert on the Java internals, nor do I do any kind of language design. I do find some of the lower level internals of the Java language runtime very interesting. Take a simple class with implementation and visibility modifiers omitted.


public class Foo {
static int j = 0;
Foo()
Foo(Foo aFoo)
int getI()
void setI(int i)
static void somethingStatic()
}

When this class is compiled to byte code it becomes semantically closer to this.


public class Foo {
<clinit>()
LFoo <init>()
LFoo <init>(LFoo)
I getI(LFoo)
V setI(LFoo, I)
V somethingStatic()
}

There are two new method names here that we didn’t specify <clinit> and <init> there are initialization methods that are written into the class by the compiler. <init> is a method that returns a new instance of the object AKA. constructor. <clinit> is the static initializer, it sets j to 0, and would perform any other static initialization logic.

A few other quick notes:

  • L in LFoo means that we are dealing in language references.
  • I means primitive integer.
  • V is void return type.

You will also notice that any distinction between instance and static invocation had disappeared. Really isn’t expressed declarative at the byte code level. All instance methods assume that their first parameter will be the reference to their instance, whereas static methods are invoked without a parameter reference to their instance. Note, the instance reference is not an actual part of the method descriptor as I indicated above, it is simply implied. All distinction between static and nonstatic is at invocation, by using the appropriate bytecode instruction:

  • invokeinterface - Invoke interface method
  • invokespecial - Invoke instance method; special handling for superclass, private, and instance initialization method invocations
  • invokestatic - Invoke a class (static) method
  • invokevirtual - Invoke instance method; dispatch based on class

The beauty at the byte code level is its simplicity. There is no magic, to me it just makes sense, and if you didn’t know before now you know what it means when you see a <clinit> or a <init> in a stack trace..

Favorite poem

Monday, May 10th, 2004

Restless man’s mind is,
So strongly shaken
In the grip of the senses;

Gross and grown hard
With stubborn desire
For what is worldly.

How shall I tame it?
Truly, I think
The wind is no wilder.

-Arjuna to Krishna