Friday, October 30, 2009

Artificial Stupidity

Artificial Stupidity (AS - pronounced rudely as you would expect) is an important discipline and I believe a growth area in computer science.

Look at the things we can do with AS:

  • Dumb monsters in games
  • Automating the news reporting at Fox News
  • Anticipating typos or mistakes
  • Turning off computers in the cockpits of airplanes that are overshooting airports
  • Politicians
  • Testing of artificial intelligence
  • Thesis committees for AI doctoral candidates
  • Better ways to annoy MS Word users with silly assumptions about spelling or formatting automation

Actually there are endless applications for AS. You could do a Turing Test that if the human agreed with the AS, we could confirm the human is a politician, mid level manager, or works for Fox News.

There are many places to learn about AS. For example, NASA. Not the space flight NASA, but the National Artificial Stupidity Association at the University of New Mexico.


Unfortunately this is sot something you can get a degree in. You have to specialize, maybe write a book or make it part of your doctoral thesis (writing one book is the equivalent of 300 blogs or a doctoral degree).

The funny thing is that there are already a lot of AS professionals (or is that AS pirates?). There are a lot of smart folks out there, but some are just plain bad. So, write bas AI, you automatically become an expert in AS.

AS's are everywhere! We have been awaiting self aware machine intelligence, but I think we see AS emerging right now all around us. Look at MS Word and its auto-formatting for wonderful example. Even though a lot of software was designed with traditional techniques and no AI or expert system code. Airline sites that pick only pricey tickets, shopping carts that forget what you bought, most applications have become 'self stupid'.

Monday, October 19, 2009

JRuby Trick: Saving time instrumenting Java classes

Ever with you could teach a class a new trick without wrapping or extending capabikities in a new class?

One of the issues I initially had issues with was extending Java to do cool things with Ruby.
First the Java class:

public BoringPig{
public String getName(){
return "name"
}
}

Being a Java guy, my first attempt at adding Ruby to Java looked like this:

class FlyingPig
def initialize(boringJavaObject)
@boringJavaObject = boringJavaObject
end
def flyPiggyFly
# ..... exciting stuff,
puts @boringJavaObject.getName+ " is flying!!!!"
end
end

But this meant I had to create a new Ruby instance. If I have a lot of objects, I ned to visit each one and create my Ruby version.

Instead, here is a cheaper way that simply adds the new method to the existing class

class BoringPig
# adds this method to any existing BoringPig objects or new instances of BoringPig
def flyPiggyFly
# ..... exciting stuff,
puts getName + " is flying!!!!"
end
end

Note that I don't need to fiddle with the initialize anymore. I also don't have a pointer to the object because the instance is the same. the "getName" could have been written as "self.getName", but self is implied.

To summarize, I have made a pig fly without creating a flying pig class.

Essentially I am extending the class rather than wrapping. Because Ruby is much more dynamic about when you add a method to a class definition, I can do this at any time for any reason. This could also mean that I could extend the class depending on the context and what I need to do. This is sort of like adding a visitor method directly to a class definition.

Why else would I do this? Basically I have a ton of Java in a very wordy API. I would like to reduce the churn of code to do things with these classes. For example, I have a class that has a very deep relationship that changes the classes use and context. Rather than create a wrapper for the new use and context, I can simply bubble this up to the methods of the root object. For you UML guys, I am adding stereotype info at the class rather than digging for it deep in the association of the stereotype tags.

Fun trick.

Pretty cool! This also meant my software runs a lot faster and takes a lot less memory.


Saturday, October 10, 2009

Like a Ruby in a Goat's A@@

I have been programmed in Java forever. Of course, there is nothing wrong with that.

Now I am learning and writing Ruby and specifically JRuby. The reason for JRuby is that I am calling the API in MagicDraw to get some things done that I have always wanted to do, but didn't have time to set up NetBeans or 'gasp' Eclipse every few months (I am Chief Architect of MagicDraw, so always working on the latest version).

I am sure that I could be writing Java, but I just don't have the time to do the setup. That's the key. You just run the scripts. No compile, no install, no waiting. There is a lot of pull.

I am also strangely attracted to Ruby (not in that way, the platonic language loving way). A few years ago I saw a lecture by Dave Thomas (of Pragmatic Programmer fame, not the founder of Wendy's), and thought that Ruby seemed compact and a rather useful language. But alas, every attempt to learn Ruby was thwarted by the chaos which is inherent in most languages... Drifting language, few standard libraries, and poor support. This has changed with the introduction of JRuby and the inevitable tread that comes with popularity of a language... sloth.

Now Ruby's pace as a syntax has slowed. Gone are the days that you can't test the latest article or book on your latest version of Ruby. Gone are the days of trying to match the right version of Ruby with some arcane GUI library. Gone are the constant changes to the language because when something is popular, change is discouraged.

There is still change, but it is additive. The GUI can now be based on Swing and I have that one in the bag. The implementation of JRuby runs on any Java JVM, so it works on any platform. Oh joy!

Things are not all good... Ruby is an interpreted language. There is no strict typing. Errors are at best cryptic for the new user. Learning Ruby is simply cool and like torture best left behind in the Bush administration because you'll never get a proper confession from a Ruby error message.

Well, with a presentation looming, I am forcing myself. I need to talk about PRR. PRR... well it is about rules as in expert systems as in artificial (pickled) intelligence and representing said rules in UML. All well and good, but what good are rules if you can't run them? So, comes Ruby to extract the rules and run them in Drools.

Well, very quickly between myself and the great aid of Gerald Meazell, up comes working JRuby extracting UML and spitting Drools! But, then came trying to get Drools to work... I panicked... Then I looked for a rule engine written in Ruby and found Ruleby!

Ruleby is based on the great work of one of my buddies, Dr Charles L. Forgy of Carnegie Mellon University. Dr Forgy invented the Rete algorithm which is simply the reason why expert systems work because it optimized the execution of rules. I'll get into Rete someday, but take my word for it, Rete is cool.

Long story short, it is all working and I am ready for my presentation at the October Rules Fest in Dallas (except for writing the presentation... the easy part). I am using JRuby, Ruleby, and Tenjin for my template language. I can even generate a Drools DRL file!

Ruby is still treating me like a reb head stepchild, but I am learning and Gerald, who is a bonafide and card carrying red headed stepchild, is helping a lot. More to come, even some code. Got great ideas and now I can find the time to script a few.