Thursday, March 27, 2008

Vista Annoyance #432

A few weeks ago, I watched Guy Kawasaki's interview of Steve Ballmer at MIX. Kawasaki gave Ballmer a hard time about Vista. It made me think of some of the problems I have had with Vista. I started thinking "well things seem better now.' Then this morning I try to log on to my home system and get an error message saying that Windows could not load my user profile. In the event viewer it says:

Windows cannot load the locally stored profile. Possible causes of this error include insufficient security rights or a corrupt local profile.

DETAIL - The process cannot access the file because it is being used by another process.

Luckily I rebooted and everything was ok. Yep, rebooting is still the best way to fix most Windows problems. Things haven't changed much in the last fifteen years.

Actually I still have other problems with Vista. I still get problems caused by Windows Firewall. Vista was so unstable on my MacBook under Parallels that I replaced it with XP. In December, my Vista install was completely corrupted. After several minutes of use, its network and memory consumption would go ballistic making the system unusable. I thought at first it was a virus or malware of some sort, but I never found any evidence of either. I wound up re-installing Vista to fix the problem.

Now Vista SP1 is out. I don't know if I should be hopeful that it will be a remedy for all of my pains ... or if it will just be fuel for the fire and cause me to "upgrade" Vista to XP.

Wednesday, March 19, 2008

eBay on developerWorks

I have written a lot of articles for IBM over the last couple of years. Most recently I got a chance to write about "my day job" if you will: eBay. I wrote two articles on how we use Eclipse at eBay to tackle a lot of interesting problems. When I first came up with the idea for the two articles, it seemed really cool but I was a little worried about it being complicated. When you think of a large company (and with 15,000 employees and a $36B market cap, eBay certainly qualifies) you think of all kinds of red tape, armies of lawyers, etc. I was pleasantly surprised to have almost none of that to deal with for these two articles. The articles definitely show some of what's "under the hood" at eBay, but its just enough to explain some of eBay's unique needs and how we have used Eclipse to help with these needs.

Monday, March 17, 2008

Go Disney?

A friend of mine got the following email:
Dear Parent of Chris,
We're pleased to inform you that your teenager has registered with us
and will now have access to the Internet sites of the
Walt Disney Internet Group ("WDIG") including Disney.com, ABCNEWS.com,
ABC.com, ESPN.com, FamilyFun.com and many more!

As a result, we want to make you aware of all of the information below:

1. Participation in WDIG Site Features. Now that your teenager is
registered with us, he/she can participate in all of the features we
make available on our sites to registered guests under the age of 18,
including games, sweepstakes, contests and interactive features on our
sites through which personal information can be made public to the
Internet and shared with users of all ages (i.e., "Public Forums").
// Random B.S. omitted

2. Terms of Use. Use of all WDIG Sites is governed by the
"Terms of Use" posted at the bottom of each WDIG Site.

The Terms of Use contain important provisions governing your, your
teen's and our rights including acceptable conduct on the WDIG Sites,
intellectual property rights (for example, our right to use
information, content and materials submitted to us by your teen) and
other rights available to you, your teen and us. We ask that you
read the Terms of Use and ensure that you understand them. If you
do not want you and your teen to be bound by these terms, you must
revoke your teen's registration. If you revoke your teen's
registration, your teen will not be able to access any portions of
the WDIG Sites that are made available only to registered guests.

Click below to view the Terms of Use:

http://disney.go.com/corporate/legal/terms.html

By not revoking your teen's registration, you agree that you and your
teen will be bound by the Terms of Use in connection with his/her use
of WDIG Sites and you agree to personally ensure that your teen
complies with the Terms of Use. (emphasis added)

If you want us to revoke your teen's registration, click below:

// link removed
How awesome is Disney! Under-age? No problem. Go ahead and register on their site. Then your parents will receive an email and have to read it and click on something to revoke your registration. Or better yet, just use a bogus email for your parents to remove the off chance of them actually reading the email and being responsible.

That is clearly the case here in fact. My friend has no children, so clearly some child picked a random email address that happened to be my friend's. Now if that child will start publishing plans to blow up buildings on a Disney forum page, my friend can be held responsible (per the Terms of Use.) Lovely!

Thursday, March 13, 2008

Silverlight Stocks

Ever since details of Silverlight 2.0 came out, I planned on re-doing my stocks app using it. This is an app that I first wrote for a GWT tutorial I did for IBM, and then re-wrote when I learned Flex last year. I wanted to write it in Silverlight last year, but Silverlight was not ready then. Now it is. Here's a picture of it.


This look-and-feel is all defaults. It looks like a web page! It's usually easy to spot Flex apps, but that is not as true with Silverlight. Everything works the same as with the Flex or GWT versions, except the color-coding for stocks that are up or down. I figured out how to define styles with Silverlight (more on that) but could programmatically set the style. Let's take a look at the code. First the UI code.


<UserControl x:Class="SilverStocks.Page"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Enter Symbol "/>
<TextBox x:Name="symbol" Width="100" KeyDown="symbol_KeyDown"/>
<Button Click="Button_Click" Content="Get Info" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Company Name: "/>
<TextBlock x:Name="company"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Price: "/>
<TextBlock x:Name="price" Text="$"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Change: "/>
<TextBlock x:Name="change" Text=""/>
</StackPanel>
</StackPanel>
</UserControl>


Pretty similar to MXML, but distinctive. As with ASP.NET pages, Silverlight puts all code in a code-behind file:


public partial class Page : UserControl
{
const string url = "http://localhost:8080/Stocks/Stocks?symbol=";
public Page()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
invokeStockService();
}

private void invokeStockService()
{
string symbol = this.symbol.Text;
WebClient service = new WebClient();
service.DownloadStringCompleted += new DownloadStringCompletedEventHandler(handler);
service.DownloadStringAsync(new Uri(url + symbol));
}

private void handler(object sender, DownloadStringCompletedEventArgs args)
{
if (args.Error == null)
{
this.showInfo(args.Result);
}
}

private void showInfo(string xmlContent)
{
XDocument root = XDocument.Parse(xmlContent);
var stocks = from xml in root.Descendants("stock")
select new Stock
{
Symbol = (string) xml.Element("symbol"),
Company = (string) xml.Element("companyName"),
Price = Decimal.Parse((string)xml.Element("price")),
Change = Decimal.Parse((string)xml.Element("change"))
};
foreach (Stock stock in stocks)
{
this.company.Text = stock.Company;
this.price.Text = stock.Price.ToString();
this.change.Text = stock.Change.ToString();
}
}

private void symbol_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
this.invokeStockService();
}
}
}


Notice that I used the LINQ-XML cleverness, as advocated by Scott Gu. Most dynamic language folks will probably favor ActionScript's E4X over using this lambda-ish query language and a statically defined class. Actually I'm sure I could refactor this to not use the class at all, and just set the text fields during the query.

Finally, the other major difference between the two is the Flex framework's mx:HttpService. This component encapsulates the call to the back-end and provides dynamic binding. There is no handler code in the Flex version because of the binding. Will data source bindings and components like mx:HttpService find their way in to Silverlight?

Wednesday, March 12, 2008

JsonViewer Updated

Some folks pointed out that the JsonViewer installer was complaining about being on the wrong version of AIR. That was because I wrote it before AIR went 1.0. So I thought "no problem, just re-compile it." Well sort of.

I updated Flex Builder 3 to the GA version and updated AIR to 1.0. I imported the old project. It picked up my Subversion settings and what not, very nice. I did a new "export release version" and it worked just fine. I tried to execute the .air file and it bombed. It told me that my AIR file was damaged.

WTF!? I tried to run the app directly from Flex Builder. It did nothing. No errors, just nothing. So I tried debugging. Then I finally got an error message about using the wrong version of AIR. I opened up the JsonView-app.xml. There was no "setting" in here for AIR version, but then I saw this

<application xmlns="http://ns.adobe.com/air/application/1.0.M6">

Yep the .M6 was killing me. I removed it from the XML namespace declaration, and voila! Everything worked perfectly. Show your appreciation for my pain by downloading JsonViewer.

Monday, March 10, 2008

New developerWorks Article on WSAS and Eclipse

IBM published a new article I wrote last week. This one is titled WSAS and Eclipse simplify creating Web services. It is about the WSO2's Eclipse plugin that comes with their Web Services Application Server. The article shows how the plugin let's you take any POJO and turn it into a web service.

Sunday, March 09, 2008

Fantasy Baseball 2008

Oh yeah, it's that time of the year. Of all fantasy sports, baseball is without a doubt the best. I have had a mostly straightforward formula I have used over the years to rank players. This year's results top 30 (I did top 30 so I could squeeze in Tim Lincecum):

  1. Johan Santana 9.997069335

  2. Chase Utley 9.395566713

  3. Matt Holliday 9.28777674

  4. Alex Rodriguez 8.06973671

  5. Albert Pujols 7.362279704

  6. Jake Peavy 6.687233845

  7. Vladimir Guerrero 5.979646533

  8. Victor Martinez 5.724916421

  9. David Ortiz 5.661505849

  10. Ryan Howard 5.650694866

  11. Alfonso Soriano 5.226027058

  12. Carlos Lee 5.114022165

  13. Jonathan Papelbon 5.06406981

  14. Grady Sizemore 5.012756748

  15. Lance Berkman 4.721401161

  16. Hanley Ramirez 4.707462255

  17. Miguel Cabrera 4.202140221

  18. Jimmy Rollins 4.069476267

  19. J.J. Putz 4.013553495

  20. David Wright 4.007944434

  21. Joe Nathan 3.984203692

  22. Adam Dunn 3.907455051

  23. Mariano Rivera 3.793661698

  24. Prince Fielder 3.7901273

  25. C.C. Sabathia 3.749804343

  26. Russell Martin 3.703008847

  27. Carlos Beltran 3.629816436

  28. Ryan Braun 3.556328479

  29. Tim Lincecum 3.377436453

  30. Robinson Cano 3.376123846


The big weakness is always my source of projections. I prefer to be somewhat random about this. Sometimes I tweak based on personal bias. This year I did not. The numbers don't mean too much, unless you are in an auction league. In that case, a rating of 0 corresponds to the average price of a starting (non-bench) player. An increase of 1 point corresponds roughly to a 40% premium. So if rating(Player x) - rating(Player y) = 1.0, then $(Player X)/$(Player Y) = 1.4.

Thursday, March 06, 2008

IE-Hell Freezing Over

Even after I heard the rumors, I still never thought I'd see it with my own eyes:

My enthusiasm was quickly curbed when I tried to use IE8 to post this blog entry. Not only did the Blogger interface look crazy, but the upload image link did not work. I tried switching to "Emulate IE7". To do that, you must restart the browser. That's not very practical, and just means that most people will have to default to the IE7 emulator. Oh well, I guess Blogger just needs to fix up their non-standard JS? Maybe I will open up a debugger to figure out what is breaking. Probably some kind of browser sniffing code that picks different JS syntax depending on if it is IE or not. Maybe what is needed is an IE8 add-on that fakes the user-agent so that most sites think IE8 surfers are actually Firefox surfers.

Wednesday, March 05, 2008

More JRuby Performance

In the aftermath of my post on JRuby's performance, I exchanged some info with Mr. JRuby himself, Charles Nutter. Per his request, I opened a bug on the matter. It looks like it is a JVM issue, i.e. JRuby ran slowly on IBM's J9 JVM. I did some micro-benching on Ruby vs. JRuby on a variety of platforms and JVMs. It was only on the J9/2.3 (IBM's JDK 5.0 JVM) that JRuby was was slower than the latest "native" Ruby implementation on that platform. Everybody loves charts, so here are some fun ones.


This was on my MacBook, with both the standard HotSpot Java 5.0 and Java 6.0 preview versions. I also compared using the -J-server (just becomes -server for the JVM) option, since HotSpot on the Mac runs in client mode by default. Thus the -server made a big difference.

This was on my home desktop system, a 32-bit Windows Vista system. I only did native Ruby vs. JRuby with and without the -server option. Again JRuby with the -server option crushed native Ruby.

Finally the environment that caused all the problems, my workstation. As you can see, it did quite poor compared to native Ruby. However, JRuby with either the 5.0 or 6.0 HotSpot JVM was much faster. I was actually hoping to see a better performance advantage on the 6.0 VM vs. the 5.0 one... I don't have IBM's 6.0 VM, so I could not include it. The HotSpot VMs were both 64-bit, whereas the IBM J9 on was a 32-bit VM.

Tuesday, March 04, 2008

JRuby Performance

During my lunch today, I solved Problem 12 from Project Euler. As usual, I wrote the solution in Ruby and was surprised by just how long it took to calculate. It made me decide to try JRuby.

First, a note about the problem and my solution. The problem was to find the first triangle number (where the n_th triangle number is 1+2+3...+n) that has at least 500 divisors. My solution was pretty brute force. I took each triangle number and computed its prime factorization. For example 28 = 2^2 * 7^1. Thus the number of factors is (2+1)*(1+1) = 6. Generally if N = A^a * B^b * ... where A,B,.. are primes, then the number of factors is (a+1)*(b+1)*...

With all of that in mind, why did I think JRuby would be faster than Ruby on a problem like this? This kind of calculation is well suited for JVM optimizations: unwinding of loops, JIT'ing of the code, etc. Thus I thought this might be the kind of problem where the JVM could make JRuby run a lot faster than Ruby. Boy was I wrong!

In general, I found JRuby to take twice as long as plain ol' Ruby (or C Ruby as the JRuby folks like to call it.) This was true on Windows, where Ruby is considered to have a poor implementation by many, and on OSX.

This made me thing that my conjecture was wrong to begin with. Maybe this was not the kind of code that the JVM could do much with. I re-wrote the algorithm in Java and re-ran it. It was exponentially faster in Java than in Ruby or JRuby. Indeed, the JVM was able to optimize the runtime execution of the code and make it fly.

Is this what I should have expected? Is JRuby generally much slower than Ruby? I really thought that part of the idea behind JRuby was to leverage the JVM to make Ruby faster.

Friday, February 29, 2008

AJAX, the REST Killer

I was at a demo today that was showing off an application that was designed to be a reference implementation / blueprint app. Of course it had some AJAX based features in it. One of the AJAX calls allowed an existing object to be edited, and another would delete said object. I noticed that the AJAX was using HTTP GET. I pointed out to the developers that since this was supposed to be a blueprint app, it should get everything right and use POST for both of these. Of course it should really use a PUT for the update and DELETE for the delete, but browsers just don't support that.

After the presentation, one of my colleagues pointed out that a lot of times we are forced into GETs because of cross-domain calls. He was right, and made me realize how the hack-that-is-AJAX is always rearing its ugly head. Cross domain calls are part of life for any large, distributed site. In an AJAX world you either have to use JSONP style calls, i.e. using a Script tag to make your call, or you have to use a server proxy. Of course going directly to the appropriate domain is much more efficient, so JSONP is going to usually win. There's no way to do an HTTP POST on a Script tag, so there you go. Forget all about respecting the REST protocol.

Of course Flash and Silverlight (gotta include it now!) both allow for declarative cross domain security. No need for JSONP hacks. Now if only they both supported HTTP PUT and DELETE...

Thursday, February 28, 2008

Silverlight Slim and Fat Flex

A couple of days ago, I talked about Silverlight 2.0. One of the interesting things to me was that it was how Silverlight RIA-style apps could be a lot smaller than Flex apps. I posted a comment to Scott Guthrie and he was kind enough to post a reply to my question. His reply indicates that for Beta 1, a relatively complex application will be slightly smaller than the same thing in Flex. However, much more of the framework is going to be included with the initial Silverlight download starting in Beta 2, thus giving Siliverlight a huge advantage in terms of app size.

When Adobe announced that the Flex framework could be cached on the Flash player across domains, I wondered why the didn't just included it with the Flash player. I have even bugged Flex evangelist Ted Patrick with this question. His response to me was that they would open themselves up to "DLL hell." In other words, there could be problems with people building their app against Flex framework version X, but a user has an older version installed.

As if this doesn't already happen! Let's not forget that Adobe jumped ActionScript from version 2.0 to 3.0 and thus required Flash player 9 or higher for anything authored using 3.0. This was not just some update in framework, it was the entire programming language being overhauled. It is common to use JavaScript to detect Flash player version and require people to upgrade. It is so common and so part of Flash development, that Adobe distributes the ExpressInstall SWF for doing this as easily as possible. Heck, I usually require users to be on 9.0.28 or higher, since that is the version that fixed some bugs with ExternalInterface.

So back to the Flex framework/DLL hell issue. It would simply require people to check for a certain minimum version of the Flash player (since that would correspond to a version of the Flex framework) and prompt for an upgrade if needed. In other words, it would require something that most folks already do today.

To me the real reason is that it is more economical for Adobe to not include the Flex framework. Ted has a widget he wrote showing over 3.9 billion downloads of Flash player 9. Add an extra 200K to that and you get over 726 TB. That's a lot of bandwidth to pay for. That's a price Microsoft wants to pay, because it would indicate lots of folks with Silverlight installed. Perhaps once that happens, Adobe will reconsider.

Wednesday, February 27, 2008

Project Euler

A friend of mine pointed me to Project Euler. Being a mathematician and a programmer, he knew I would love it. It is a lot of fun. It reminds me of these computer competitions I used to participate in when I was in high school. You would get some list of problems on sheet of paper, have to code a solution, and a judge would come by to test your program. Anyways, I am a 4% genius having completed seven problems so far. I am mikeg on the message boards on there, if you want to check out my solutions. So far I have done everything in Ruby. I picked Ruby for two reasons. First, I like its syntax and want to use it more often. Second, it is slow. So I figured it would force me to come up with good algorithms. Here is a sample of one of my solutions. The problem was to find the largest palindrome that is the product of two 3-digit integers.

def isPal(num)
if num % 11 == 0
return num.to_s == num.to_s.reverse
end
return false

end
 
max = 0
999.downto(100){ |i|
i.downto(100){|j|
val = i*j
if val > max
if isPal(val)
max = val
end
else
break
end
}
}
puts max

Monday, February 25, 2008

Silverlight 2.0

We all knew this would happen at some point. Even when it seemed like it would not, you just had to know in the back of your mind that it would happen. Microsoft has given a preview at Silverlight 2.0. This time it is not about media, it is about RIAs. They even use the term correctly now... You should really check out that link and especially the tutorials it links to. They are very high quality.

Like I said, we knew this had to happen. Silverlight 1.0 was really just a streaming media platform. Silverlight 1.1 was only a little better (and isn't it still in beta?) It gave the first real clue though. It included a stripped down CLR, allowing C# to run inside Silverlight. This was a clear indication that Silverlight was going to take aim at developers and thus become Microsoft's answer to Flex.

Now this has finally happened. I spent the last hour reading through the tutorials. There were several things that really made me raise my eyebrows:
  • A 4KB Hello World : It looks like either the controls (and the framework code that lets them get wired up, etc.) are either really small or the compiler is very smart at stripping things down (or both.) Hello World in Flex is 140KB because all of the Flex framework is included. I don't think all of the Silverlight controls/app framework is included with the base runtime, as it clocks in at 4 MB, i.e. about the same size as the Flash player.
  • Crossdomain Silverlight: MSFT wisely just re-uses the Flash crossdomain.xml policy file system to get the same kind of declarative security. Very nice of MSFT to just tip their cap and say Flash got this right, let's not reinvent the wheel on this one.
  • Silverlight Styles: Their style syntax is ... different. Well different from CSS certainly. Adobe has tried to leverage CSS in Flex. The Silverlight style syntax is probably much more powerful than CSS, but you have to wonder if it is really worth it. It is still a declarative XML syntax on top of the selector paradigm used in CSS.
  • Silverlight for the Desktop: Ok not really. But MSFT is going out of their way to point out how easy it is to take a Silverlight app and turn it into a desktop app. This is clearly in response to the attention that Adobe AIR has received.
So I find myself eagerly awaiting the release of Silverlight 2.0 along with the tooling for it in Visual Studio 2008. I will definitely have to (finally) create a Silverlight Stocks Quote app.

Sunday, February 24, 2008

TDD Gone Wrong

Last time I wrote about TDD. I read this article from some guy at Spring about doing TDD with the Google Web Toolkit. I have to say this is a good example of how TDD zeal can lead to some twisted thinking.

The article starts by point out how GWT enables RIA development in pure Java. That's a good thing. He then talks about some of the difficulties he's experienced trying to write unit tests for GWT widgets and concludes:

views are usually very hard to test, therefore they should know and do as little as possible ... Most of the GWT code has pretty much all the logic in widgets, so most developers using GWT extend a widget and just add some more logic. My advice is simple: don't go there.

RIAs are all about putting lots of logic in your view. Now it's not just any logic, but view logic. You see there is logic involved in creating a rich user interface and the place for that logic is the user interface. So this guy's obsession with testing has led him to the conclusion that you should dumb down your view code so you can test it. This completely defeats the purpose of using GWT. Very sad.

I think the author does bring up some valid points on unit testing GWT. If you place a huge importance on unit test coverage, then the more logical conclusion is that you should not use GWT. Don't try to dumb down the technology so that you can sleep better at night. Just pick a different technology.

Thursday, February 21, 2008

Test Driven Development

Terry wrote a great post about "pragmatic" programming. It brings up the usefulness of test driven development(TDD). It is good that this is debated. It seems like it is almost accepted as fact that TDD is good. Period. Whenever people start accepting something without questioning, it leads to very bad things.

So I am glad that Terry questions TDD. Many folks I work with question it, too. Their arguments are different than Terry's. For example they point out that much what you code in a test has to be duplicated by QA. Of course that's not an issue for some folks, because they don't have QA, but it is an issue in larger organizations. Terry uses the example of Facebook as a large organization that uses no hard rules, i.e. TDD, for development. Also, folks I work with point out that TDD is a recurring tax. You not only spend time coding the test to start with, but you spend more time re-writing the tests every time you make changes to your code. The cost of TDD must be weighed against its benefits, you should not just accept it blindly.

To me, the value of tests greatly depends on the clients of your code. Let's say you have code whose only client is the end user, i.e. "application" code. Generally what matters for that code is that it is accepted by the end user. If it does what they want, that is all that matters as that is the only purpose for the code. I can definitely see how writing tests may not have as much value for this kind of code, though I think there is still some value to it.

Now compare this to code whose clients are other pieces of code. To make it simple imagine application code that calls infrastructure code. In this case it's harder to argue that if the end users of the application are happy, then the infrastructure code is good. Imagine if the infrastructure code has an API that is supposed to produce a formatted date. The infrastructure code could produce the wrong formatting, but the application code could work-around this to keep the end user happy. Maybe that is ok, but things get uglier when somebody "fixes" the infrastructure code, particularly if a second application uses the same infrastructure code. Having fine-grained tests for the infrastructure code becomes more valuable.

For me personally, I like using TDD, though I am not religious about it. There are times that I write a test first, then I write the code. There are other times I write the code, then a test, run the test, tweak the test, fix the code, etc. In general, I like to write tests just because I like to test my code to be sure that it works. I figure if I am going to go through the effort of doing that anyways, I might as well do it in an organized way that could be useful to others. Also, writing test code is at least as useful as writing inline documentation in your code, maybe more useful. A unit test is sample code, or darn close to it.

Sunday, February 17, 2008

Clemens v. Congress

The big story in sports this past week was the testimony of Roger Clemens before Congress. Now obviously this was a huge waste of time and (more importantly) tax payer money. It is classic pandering by Congress. We all know this, right?

There was something else that bothered me even more about the Congressional hearings. That was the obvious division along party lines. Republicans clearly supported Clemens and tried to discredit his accuser, Brian McNamee. Democrats clearly wanted to prove Clemens had taken steroids and HGH. I don't have a problem with folks having an agenda (though if everyone has their mind made up already, why a hearing? Oh never mind.) No what bothers me is that this division was along party lines.

Why does the Republican Party need to support Clemens? How is his innocence somehow a priority for the Party? One can only conjecture. Is Clemens a significant contributor to Republicans and the Party?

Similarly, why does the Democratic Party need to prove that Clemens is guilty? Is it just to spite the Republicans? Do they want to bring greater government regulation and involvement to Major League Baseball or sports in general?

These questions just lead us back to the beginning of this post. The government has no business doing hearings on Roger Clemens. Not only is it wasteful, but inevitably the issue itself becomes meaningless thanks to partisan politics.

Oh, and for what it's worth, I think Clemens is lying and that he used steroids and HGH. I don't care if he did or not, but clearly the evidence points against him.

Thursday, February 14, 2008

Metaprogramming in Grails

Groovy is a swing-and-a-miss. It will go down like OS/2 did. People will say "man that Groovy language was so good, I don't know why it didn't catch on." Here's an example of why it is a fail.

I was reading this article on developerWorks about GORM, the OR framework in Grails. Like everything else in Grails, it is "inspired" by Ruby on Rails. In this case GORM was inspired by ActiveRecord. In GORM here is an association:

class Airline {
static hasMany = [trip:Trip]

String name
String url
String frequentFlyer
String notes
}

Compare this to the same thing in Rails

class Airline < ActiveRecord::Base
has_many :trips
end

Forget the explicit listing of fields for a minute, concentrate on the has-many notation used by both frameworks. In Grails, you have a static field that has a special name. In ActiveRecord you use a meta-API or macro (or whatever you want to call it) to dynamically add methods to each instance of Airline. Grails accomplishes the same thing, but it is much more of a hack. You just happen to have a static field that has a special name.

It just feels like "wow that feature is cool, we can't do it the same way ... but we can hack something together that is pretty close!" Just seems like Groovy comes up short.

Tuesday, February 12, 2008

New Version of JsonViewer: Now Open Source!

I updated the JsonView AIR app I wrote a couple of months ago. It has wound up being pretty useful for some of the folks I work with, hence there have been some bug fixes new features requested. I have also had some folks email me about the source code. So as a result of these two things, not only did I update the app, but I released it as open source via Google Code.

So you can get the latest version here, or you can check out the source code for yourself. I was almost embarrassed to show the source because it so trivial!

Saturday, February 09, 2008

NFL Rumors

From an this article on Y! Sports:
"Cowboys owner/GM Jerry Jones will feel compelled to make a big splash this offseason. The most popular speculation is he'll trade his two first-round picks and running back Marion Barber (a restricted free agent) to the Miami Dolphins for the No. 1-overall selection in the NFL Draft. Jones then could select Arkansas running back Darren McFadden."

Whoa! I like that rumor. I know Miami needs D, but I think Glen Dorsey is way-overrated. He is the logical #1 pick for Miami, so I would love to see them deal the pick. Getting two #1's would be great. I love Marion Barber as well, even though Ronnie Brown looked like the best back in football last year before he got hurt. Seriously the guy would put 100 yards on the ground in the first half of games. Then in the second half, with Miami down by double digits (because they had no defense to speak of) he would rack up another 100 yards receiving. If nothing else, Marion Barber is an awesome insurance policy, and he has ties with new Dolphins head coach Tony Sparano.

The Dolphins offense looked ok before injuries killed them. Oh and before trading Chris Chambers. QB continues to be a problem, but from that same article..."
"Eagles could trade McNabb"

How Much for that Moss?

This article on ESPN rightly wonders how New England should be willing to pay to keep Moss. They make some good points, namely that it will cost the Pats a lot to sign him to a multi-year deal and that he might be disgruntled and play poorly if they resort to using the Franchise tag on him for all of next year. Then they make some stupid points.

Like why expect New England to re-sign Moss when they didn't re-sign Deion Branch who played big in two Super Bowls. After all, New England lost the Super Bowl with Moss. They also try to claim that New England's all-pass attack was foolish because they lost to New York. They even try to use statistics to justify this by pointing that starting late in the third quarter, New England only average 3.8 yards per pass.

Ah, but when dumb people start quoting statistics, they get themselves in trouble. They don't mention that New England only average 2.8 yards per rush. I mean, if passing the ball is not working, then you should run the ball more, right? Oh if that stinks too ... well I guess you could just punt on first down?

Back to Moss, he was the key to New England becoming the most productive offense in the history of the game. They would be above average without him, but they are the best in the league with him. I am no expert on NFL economics, so I can't say what he is worth. All I know is that as a Dolphins fan, I can just dream that New England lets him go.

Finally, one last parting shot on the Super Bowl. It would be dumb for such a successful team to try to "fix" non-existent problems based on the outcome of one game. New York did what many team tried to do against New England: get pressure on Brady. That is the only way to neutralize a great passing game. This has been common knowledge for decades. It's the Lawrence Taylor effect. So if for some reason New England wanted to "fix" something, then they should look at their O-line and in particular Matt Light. I think Light is fine. He is undersized slightly for an LT. He is going to the Pro Bowl this year for the first time, but that is largely because of New England's success. That's the place to look for "fixes" though, not at WR.

Friday, February 08, 2008

99 Bottles of Beer

First off, if you like programming, you should check out this hilarious site on the venerable song 99 Bottles of Beer.

Ok, now I am assuming that you just spent the last hour or so at that website, but you are back. If you are into Java, one of the most interesting solutions is one that eschews typical control structures (for/while/do loops) and instead uses Java's exception system to sing the song. Actually the way that I came across the site was from an email sent by one of my colleagues. He was amused by the exception based solution. I was amused, too. Obviously such code will perform exceptionally bad (pun intended.)

One of my friends was inspired to do a Python variant that used the same technique:


#! /usr/bin/env python

class BottleException(Exception):
def __init__(self, i, c):
self.cause = c
self.cnt = i
try:
a = 1/(99-i)
raise BottleException(i+1, self)
except ZeroDivisionError:
pass

def getCause(self):
return self.cause

def printStackTrace(self):
print("%d Bottle(s) of beer on the wall, %d Bottle(s) of beer" % (self.cnt, self.cnt))
print("Take one down and pass it around,")
print("%d Bottle(s) of beer on the wall" % (self.cnt - 1))
try:
self.getCause().printStackTrace()
except AttributeError:
pass

try:
raise BottleException(1, None)
except Exception, e:
e.printStackTrace()


He and I are both pure hackers when it comes to Python, so there are probably numerous improvements that can be done to that code.

Update: I submitted the Python code to the 99 Bottles of Beer site and they accepted it. You can view it here.

Wednesday, February 06, 2008

Setting Custom HTTP Headers in Flash

I needed to set a custom HTTP header in Flash. ActionScript 3 makes this easy, or so I thought. Here was my original prototype code:

import flash.net.navigateToURL;
private function href(url:String):void
{
var req:URLRequest = new URLRequest(url);
var header:URLRequestHeader = new URLRequestHeader("Koostoom", "tmttos");
req.requestHeaders.push(header);
navigateToURL(req);
}

Like I said, this is easy. To verify it was working, I wrote a quick prototype using PHP:

$headers = getallheaders();
foreach ($headers as $name => $value) {
echo "[$name] = $value<br/>\n";
}

I think I copied this out of the PHP manual pretty much. So I tested the above code and everything worked, right? I wouldn't be writing this post if that was the case!

I tried the above in Firefox and Safari. My usual test plan is to make sure it works in those two browsers first, and then deal with IE. In this case it didn't work in either browser. I knew that some HTTP headers were off-limits in Flash, so just for just kicks I tried changing Koostom to Referrer. This should have caused an exception, but of course it didn't. It did nothing.

Finally, I found the answer through experimentation. You have to do an HTTP POST with form data in order to get the custom header sent:

import flash.net.navigateToURL;
private function href(url:String):void
{
var req:URLRequest = new URLRequest(url);
// begin stupid hack
req.method = "POST";
var formVars:URLVariables = new URLVariables();
formVars.blah = "blue";
req.data = formVars;
// end stupid hack
var header:URLRequestHeader = new URLRequestHeader("Koostoom", "tmttos");
req.requestHeaders.push(header);
navigateToURL(req);
}

Now the PHP script showed my Koostoom header...

I don't know if this is a bug with the Flash player, or the browsers. I don't think it is part of the HTTP spec, i.e. I think custom headers are just as valid in an HTTP GET as in an HTTP POST.

Monday, February 04, 2008

Super Tuesday

Obviously I'm voting for Ron Paul. I really thought that the Republican race would still be clouded. Oh well, I was wrong. It does mean I will get to vote against McCain twice this year! More on that in another blog... Let's talk about the more interesting stuff on the ballot in California tomorrow: The Propositions!

Prop 91 -- Places restrictions on tax money earmarked for transportation infrastructure. Definitely a yes.

Prop 92 -- The key here is that this freezes community college fees. Wait, so I "own" (pay taxes) a business (state government) that produces a product (community college education) and I want to fix what my business charges for that product, even if I have to pay more (pay professors more, etc.) for it? That is stupid. It will only cause community college education to suffer just like all other forms of public education... No.

Prop 93 -- Reduce term limits from 14 to 12 years ... I am against term limits. Let people vote for who they want to, so No.

Props 94-97 -- Ah, the new Indian gaming "compacts". First off, Indian casinos are state backed monopolies. They get special privileges from the state, and in turn pay the state a percentage of profits. Personally I have nothing against Indian tribes having casinos, I just have something against laws that prevent non-Indian tribes from having casinos. So I have to vote against these measures. No.

Sunday, February 03, 2008

Super Bowl Prediction

New York 27, New England 23

I have to root for New York. I have a good friend from Jersey who is a huge Giants fan. Using the same logic, I have rooted for Pittsburgh the last two times they were in the Super Bowl. So I have to root for New York.

That being said ... If New England wins, they will have completed the most impressive season by any (American) professional sports team. They will not be the best football team ever. That's because of parity. You just can't assemble talent like you could just 10-15 years ago. Of course that is part of why their season will be the most impressive ever. They don't have overwhelming talent across the board, like say the 49ers and Cowboys of the early-mid 90's. They may have the best offense ever. I can't remember a team that could stretch the field horizontally and vertically like they do.

Anyways ... go New York!

Thursday, January 31, 2008

Flash Hacks: Call Arbitrary JavaScript!

In the past I've been annoyed by the lack of HTTP header access in Flash. Turns out there are some hacks you can do to get around it. Let's say you want the URL of the web page that loaded the SWF. This would be the referrer of the HTTP request that loaded the SWF. Flash should provide access to that, but it doesn't because some browsers don't provide it this info. That's ok, you can get to it:
var hostPageUrl:String = ExternalInterface.call("window.location.href.toString");

That's right, you can "call" a JavaScript expression, not just a function defined on the page. Of course the key is that everything in JavaScript (and in ActionScript too) is a function. So any JavaScript expression is a function and thus invokable via ExternalInterface. You can see where this is going! Let's say you want the query string of the host page's URL:
var queryString:String = ExternalInterface.call("window.location.search.toString");

This will give you something like "?param=value&foo=bar..." What about the referrer of that page? 2EZ:
var referrer:String = ExternalInterface.call("document.referrer");
This is a classic case of Too Much Information, really. You are able to execute arbitrary JavaScript, ExternalInterface acts like an eval(). So you can do arbitrary badness like modify the DOM. You can also access cookies (document.cookie).

Of course the key to all of this is script access. The SWF needs to have it. If the SWF is from the same domain as the web page, it gets this by default. If not, then you need to set allowScriptAccess="always". That gives the SWF the keys to the kingdom, if you will. Of course you could use an IFrame for the SWF and sandbox it in.

Dumb Baseball Analysis

The world is full of dumb baseball analysis. The popularity of fantasy sports has only lead to greater proliferation of this strain of stupidity. Here is some from a fantasy baseball newsletter I got this morning:

Question: Which players' new addresses have affected their Fantasy value the most?
Answer: Dontrelle Willis -- Only the Yankees scored more runs in the AL than the Tigers last year, and Willis brought Cabrera (who led the Marlins in batting average, homers, RBI and walks last year). Willis will also have an established closer (Todd Jones, whom he pitched with three seasons ago) and he won't be asked to lead the pitching staff anymore. He had some personal problems that might have attributed to his down season, but now, with less responsibility deeper back in the rotation, he can just pitch.

This nugget of wisdom is from David Gonos who holds the highly regarded title of "Senior Fantasy Writer" for CBS Sports. Now I will give him one thing, Willis will be playing for a team that scores more runs, so this should help his win total. That will increase his fantasy value. But what is this garbage about an established closer, ahem Todd Jones? Mr. Jones will be 40 in April. His ERA over the last three years is 2.10, 3.94, 4.26. His K/BB: 4.43, 2.55, 1.44. His GB/FB: 2.04, 1.85, 1.51. This guy is a disaster about to happen. Now the Marlins have the 29 year old Kevin Gregg who had a 3.54 ERA and 87 K in 84 IP last year. I'm not saying he's great, but compared to Todd Jones...

The Todd Jones stats raise another issue. Look at that 2.10 ERA he had three years ago. That was when he was pitching for Florida. His numbers have obviously declined since. Some of this can be attributed to age, but some of it must be attributed to switching to the AL. Guess what, Willis is making the same move. Would it really be shocking if his ERA went up from its already not-fit-for-fantasy-baseball 5.17?

Finally, you gotta love the last bit of logic from Mr. Gonos. Dontrelle won't have as much pressure on him because he will be at the back of the rotation. Maybe Mr. Gonos should get a new title "Senior Fantasy Psychiatrist."

Ok, now all of that being said, I would expect Dontrelle to post better stats then he did last year. This has very little to do with switching teams (though the extra run support should mean wins, as mentioned earlier.) He had bad luck last year. His BIPA was .311. In other words, of all the balls put in play (not strikeouts, walks, or home runs) there was a .311 probability the ball was a hist. This is very high for a pitcher, but pitchers have very little control over this. It is mostly a matter of luck. You can control strikeouts, walks, and home runs, but it's hard to control singles vs. ground ball outs, or a double vs. a fly-out. Of the 42 NL pitchers who pitched enough innings to "qualify" statistically, that is the third worst BIPA, behind only Matt Belisle and Scott Olsen. So if he just gets a little better luck, i.e. less balls in play are hits, then he will see significant improvement. Whether that is enough to overcome the move to the AL remains to be seen.

Sunday, January 27, 2008

Blogging for Obama

Barack Obama certainly had an impressive victory yesterday in South Carolina. I am definitely rooting for him over Hillary Clinton. Now I voted for Bill Clinton twice. I turned 18 and in 1992 and so it was the first time I could vote. However, I cannot support Hillary because she voted for the war. Obama correctly says that many Democrats supported the war initially because they were afraid to look weak. Is that really a quality you want in a president? Of course the alternative is that she really agreed with the President or that she was stupid enough to be fooled. Whatever, so soup for Hillary. I don't care who your husband is.

And speaking of her husband, what the heck is going on with their campaign against Obama? Bills saying that Obama winning South Carolina was not a big deal because Jesse Jackson won South Carolina 20 yeas ago is an obviously racist statement. It's saying "any black candidate can win South Carolina." It makes me ashamed that I once voted for Bill Clinton.

Running 2008

You might have noticed my Nike+ widget has disappeared from the blog. That's because my Nike+ has disappeared from me when I run. It started getting very unreliable when I was running. After three or four 9-10 minute miles, it would suddenly say I was popping off 7 minute miles. I have no idea if it is a problem with the transmitter or the iPod unit. Either way, there was no point in using it if it was giving me wildly inaccurate statistics.

I am definitely still running. I took a bit of a break after the half-marathon in October. I never stopped, but I dialed things back to around 10 miles or so per week. I will probably run the same races I ran last year, so a 10K in May and a half-marathon in October. I would really like to do another half-marathon in July at the San Francisco marathon, but that's always a challenge from a logistical standpoint.

Friday, January 25, 2008

Cute EcmaScript

The following is a nifty trick that works in JavaScript, but you should be able to tweak it slightly to work in ActionScript as it leverages EcmaScript features.


function Train(){
this.name = "Choo Choo";
this.show = function(){
return this.name;
};
};
var engine = new Train;
engine.name = "Orient Express";
function go(){
alert(engine["show"].call(engine));
}


What is cool is that you can access a function just like any other property of the object. So the go function could take a parameter that would be the name of the function to call on the engine object. It's like reflection, only better.

Thursday, January 24, 2008

Some Love for Microsoft

I got Office 2008 for my MacBook, and I have to say, I love it so far. Actually, I should say that I love PowerPoint and Entourage, as those are the two programs I have used a lot so far.

PowerPoint -- This is mostly a case of lowered expectations... A lot of the older bugs I used to experience with PowerPoint have been fixed. It works better (perfectly) with some of the templates I use from work, especially those that involve integration with Excel. This should have been the case with Excel 2004, but it was not (the templates were made with Excel 2003 on Windows of course.) This fact alone gives PowerPoint 2008 a huge edge (for me) over Keynote or NeoOffice. I might still use Keynote if I was making a presentation for a conference or the like, but when doing "work", PowerPoint wins easily.

Entourage -- This is the really big winner. This beast works flawlessly with Exchange. I put in my email address and said "use Exchange". It prompted me for my domain and password, and everything just worked. All of the features of Outlook that I use work fine. Many of the features are much better on Entourage. Case in point, auto-complete on addresses. Our Exchange server stores names like Galpin, Michael. So if you start to type "Michael" then "Galpin, Michael" will be a hit on the "M" but not on "Mi" etc. Entourage 2008 is definitely smarter than Outlook 2003 (haven't used Outlook 2007 enough to say about it.)

I generally use Word and Excel more than PowerPoint and Entourage/Outlook, so I will definitely be giving them a workout soon. Finally, as for the UI... I like the switch to the metal look that is the de facto on OSX now. I actually like the ribbon in Office 2007, so I was a little disappointed that it was not used. However, there is very nice consistency between Office 2008 and Office 2004.

So kudos to Microsoft for making a great product for the Mac.

The Economics of Dr. Paul

My biggest reason for supporting Ron Paul is because I am sure he will get us out of Iraq. The war in Iraq is the most important issue of the day. It is the first time in America's history that we have attacked another country without provocation, conquered the country, and the installed a government there backed by our military. Everything else pales in comparison to Iraq.

However, Dr. Paul is also well known for his economic principles. I don't always agree with all of these, so I thought I would dissect his new plan for economic revitalization.

Also, I would like to openly challenge my "collectivist" friend to give his own thoughts on Dr. Paul's plans.

Tax Reform -- This is the biggest part of his plan, clearly. Now several of his tax cuts sound a lot like typical Republican "Reaganomics". For example, eliminate taxes on dividends and savings, eliminate capital gains tax, accelerate depreciation on investment, repeal the estate tax. All of these would benefit wealthy individuals and corporations much more than middle class Americans. The idea is that they would encourage economic growth.
In principle, I favor the first two issues. Taxes on dividends, savings and capital gains are all cases of double taxation. You pay taxes on your income. You take some of that income and invest it, and then get taxed again on that investment. Yes, this will favor the rich, but so what? Do we support something that is logically unfair just because the unfairness is concentrated on a minority group (rich folks) ?
I am more neutral on the other two issues. Reducing corporate tax rates seems like a more direct way to encourage growth, but I would probably put much lower priority on this. The estate tax is "unfair" in the sense that it only taxes estates worth over $2M. It is also a case of double taxation. Again, this would benefit the rich (folks with estates worth over $2M) more than anybody else, but so what? Also, hard coded numbers like $2M are always dubious. You could live where I live and have an estate worth over $2M without being very rich at all.
Spending Reform -- I definitely favor reducing overseas commitments. Well in particular, just get us out of Iraq and stop spending $800M/day there. Freezing non-defense and non-entitlement seems a little too cut n' dry. I would favor freezing or cutting many of those things, but maybe not all. It's hard to know, and hence my reservation from using a simplistic qualifier like "non-defense and non-entitlement."
Monetary Policy Reform -- Yes please! People should know what the heck is going with the Fed (or any other powerful agency.) How can you oppose this? As for allowing precious metals to be used as money ... it would be an interesting experiment to say the least.

Regulatory Reform -- I definitely favor repealing Sarbanes/Oxley. I can tell you first hand that this has a hugely negative effect on companies big and small. It was a classic case of knee-jerk legislation. Now for "Remove Costly and Unnecessary Federal Regulations"... sounds good on paper! More details should be given. I do favor HR 1869, though.

IE Flash Bug

Take a look at this page, and view its source. The key is this little bit o' JavaScript:

function loadSwf(){
window.location.hash ="mark";
var str="<embed src='http://gglabs.com/~clg/flash/YouTube.swf'
type='application/x-shockwave-flash' wmode='transparent' height='800'
width='800'></embed>";
document.getElementById("container").innerHTML = str;
}


What does this do? If you are on IE, then it changes your URL to http://whatever#mark, if http://whatever was your original URL. It then drops a chunk of HTML into the page that embeds a Flash movie. What makes this interesting is if you look at the title. It is not "Test Page" as it should be. Instead it is "Test Page#mark".

This only happens on IE, but on both IE6 and IE7. I'm certain this must be documented somewhere...

Why does this matter? Well it is very common to use hashes to keep track of page history in Ajax apps. For example, in the above app let's say that I write some page initialization code that looks for #mark in the URL. If it finds it, then it goes ahead and loads the SWF. This allows the page to bookmarked and enables browser history (there's actually more you have to do for browser history on IE, but that is another topic.) In this example, we are just loading a page element dynamically, but you can imagine how useful this is for Ajax apps.

So if you are using this technique for managing history/bookmarks and happen to have a SWF on the page, you get crazy page titles. If you think this is a cooked up example, there is actually an example of this "bug" right now on a beta version of a certain high traffic page on the web...

Tuesday, January 22, 2008

Galpin on Rails on IBM

A couple of pieces that I wrote on Rails appeared on IBM at the end of last year. I didn't even realize it until today when somebody emailed me about one of the articles.

The first article is part one of a four part series on using Rails, XForms, and DB2's PUREXML tables together. I also wrote part two, but another writer wrote parts three and four. Only part one is up so far.

The second article is the third tutorial I wrote on using Eclipse as a web development platform. Part one was about using Eclipse for Java web development, and part two was on using it for PHP development. The last tutorial is on using Eclispe (via RadRails) for Rails development. Note, the link for part two shows the intro page to part one. If you login, it correctly gives you part two. Clearly some kind of technical glitch for IBM!

Crossing Lines

Today I did something that I never thought I would do. I registered Republican. Is this because I have suddenly decided to oppose gay marriage? Or maybe I am favoring tough immigration laws? Oh it's gotta be that I am suddenly in favor of the war in Iraq! Maybe I have finally realized the value of the Patriot Act!

Obviously it is none of those. Nope, I am a Republican for a few weeks just so I can vote for Ron Paul. I do not consider myself a Paul fanatic (of which there are quite a few) by a longshot. I like Paul primarily because he is the candidate most likely to end the war in Iraq, and I think that is the most important issue.

It was difficult for me to re-register just to vote for Paul. I don't like his chances of winning the Republican nomination at this point. He is obviously a huge longshot. However, the Republican party is in disarray, so I think there is a small chance. With no clear front runner, a surprise showing by Paul on Super Tuesday (California is part of that craziness now) would make a big difference.

The other factor that weighed heavily on me is that I would really like to vote for Barack Obama against Hillary Clinton. Again the issue is the war. Obama is so clearly more opposed to the war than Clinton is, that I really want him to win against her. On one hand he is a better chance of winning the Democratic nomination than Paul does of winning the Republican nomination, but I thought it was time to take a chance on a longshot.

Thursday, January 17, 2008

NFL Playoffs

I was listening to sports radio (stupid me) and heard the following:

Caller: "Everyone wants San Diego to beat New England this weekend."

Host: "That is ridiculous. That is like saying that everyone wants Tiger Woods to miss the cut at the Masters. No. Everybody wants Tiger Woods to lose by double-bogeying the 18th hole in the final round of The Masters. Tom Brady is the Tiger Woods of the NFL."

Huh? First off, people hate Tiger? That is news to me. I didn't think anybody rooted against Tiger. Maybe some folks have a different favorite golfer, and root for that golfer over Tiger. I have always liked Phil Mickelson because he's a lefty, and I golf left handed. I like Mike Weir for the same reason! But who hates Tiger Woods? Fuzzy Zoeller maybe?

Next, Tom Brady is the Tiger Woods of the NFL? Now this is just stupid. Tiger is the most talented golfer out there, and nobody could claim that Tom Brady is the most talented quarterback, and certainly not the most talented football player.

Quick question... What is the difference between last year's Patriots and this year's Patriots? Is it A.) Tom Brady B.) Bill Bellichick C.) Randy Moss D.) Electronic Surveillance ... Alright I know, trick question. Anyways, it is obviously Randy Moss. Oh, and a whole lot of points and wins to go along with Randy Moss. If I would have had a vote for NFL MVP it would have gone to Moss.

Don't get me wrong, I wish the Dolphins had Tom Brady at QB! But I just don't see him as Tiger Woods. Then again I was never a big Joe Montana fan either, and Montana is clearly the QB that Brady is most similar to.

I was disappointed that Indianapolis and Dallas both lost. They were clearly the two teams with the best chance of beating New England. I don't know how anyone can see an extremely wounded San Diego can go into Foxboro and come out with a win... Green Bay and New York could actually be a pretty close game, but San Diego would be favored against either of them. Remember, the NFC has been a lot weaker than the AFC for many years now, kind of like the AL vs. the NL in MLB or the Western conference vs. the Eastern conference in the NBA...

Monday, January 14, 2008

Language Wars 2008

Two interesting blogs inspired this post. First, there is the amazing analysis of the great Neal Gafter. And then there is the insightful rant of Rick Hightower.

I have to admit that I am getting on the Scala bandwagon. Here is why I think Scala is important. Note, most of this is just me ripping off Neal Gafter :-)

There is great potential in languages with control abstraction. Scala is just such a language. It is possible to implement the actor model, a shared nothing, message based design for parallel computing, in Scala. This is not possible in Java. You can do it in Groovy, sort of, but it can be awkward. The reason for this is simple. If you have a object call method call closure (for example) the closure can return control back to the object in Scala, but only to the method in Groovy. The extra control structure coupling in Groovy makes some aspects of control abstraction awkward at best.

And then there are pattern matching (no not regexp) and case classes... The point is that there are syntactical advantages in Scala that make it possible to handle concurrent programming in a completely different, more scalable way. So it is not just about lines of code and what not, it is about being to do practical things in a better way.

Now Rick's main point in his rant, is why invest in JRuby and Scala when there is Groovy. Hopefully I've given at least one reason why Scala has potential that Groovy does not. When it comes to Ruby, the answer is less technical and more social.

On the technical side, it is very conceivable that by the end of the 2008, the absolute best way to deploy a Rails application will be to use JRuby. That is partially because of the current state of native Ruby interpreters, but also just because of how powerful the JVM has become. Sun really wants this to be the case, and here is why.

Sun knows what it takes to introduce a new language and platform and make it the de facto standard in the industry. It is very hard and expensive. They have done it once, and it cost them dearly. Java cannot stay at the top forever. They do not want to fight this battle again. However, if they can get the Rails on JRuby scenario described above to exist, then they could "stay on top" without having the fight all of the battles this time. They let the Rails community do it for them. They let guys like DHH and Martin Fowler win over the hearts and minds, while they simply concentrate on making JRuby run screaming fast.

But wait, there's more. Sun really wanted NetBeans to be the premiere Java development platform, but IBM beat them with Eclipse. They get a second chance if Ruby becomes the new de facto standard, and this time they have a head start on IBM. Sun is imagining a future where there are armies of IT developers writing Rails apps using NetBeans and deploying them to Glassfish.

Now all of the above may be possible, maybe even easier, with Groovy. But then they have to fight the language wars all by themselves. They have to win over the hearts and minds of developers to get them to use Groovy instead of C# or PHP.

That is why it makes more sense for Sun to back JRuby than to back Groovy.

That is also why you should not expect Sun to get behind Scala until they have no choice.

Sunday, January 13, 2008

Googling MTOM

I use MyBlogLog to see the traffic stats to my blog. I noticed a lot of the referrers each day were from a Google search for MTOM. The search has one of my blog entries about an article I wrote on MTOM. I found it funny that my very short blog entry about the article shows up higher in Google than the actual article itself. The article has a lot more about MTOM and is linked to by my blog. Shouldn't that make it rank higher? The cynic in me thinks that my blog ranks higher because it is on the Google owned Blogger...

Thursday, January 10, 2008

Scala

There is a lot of hype this year about Scala....

0E75B649-4C2E-411D-AFE3-ED1D90C2E19D.jpg

Heck, even al3x is talking about it. As someone who has no problem being called a Java guy, but has been doing a lot of work in ActionScript and Ruby recently, I am intrigued at Scala. However, I was also intrigued by Groovy a couple of years ago, and was mostly let down by it. Still, I have a strong feeling that I will wind up either writing about Scala this year or use it for a small project of some sort.

Flash and HTTP Headers Redux

A few months ago I wrote about the lack of access to HTTP headers in Flash. I recently came across some other people talking about this. This has caused debate about Flex being able to support REST.

The opinion seems to be that Adobe does not allow this because not all browsers will provide this information to the Flash player. I have not seen a list of what browsers have this limitation, though I will speculate it must be older versions of popular browsers... Some of the evidence of this is that this is provided in AIR. In AIR, it is the runtime itself that makes HTTP requests. In a SWF running in a browser, the runtime relies on the browser. So restrictive browsers could be an issue on a SWF, but never for an AIR app.

Could another reason be security? In particular, cookies are passed back-and-forth via HTTP headers. There are numerous cases of cookies being stolen by malicious JavaScript, which has total access to HTTP headers. Adobe made a lot of significant security improvements between Flash Player 8 and 9. In a world of mashups, are they better off continuing to deny access to HTTP headers?

All of that being said, I recently ran across another case where this causes problems. I had a SWF that could be loaded by two different pages. It needed to show slightly different features depending and have a different look and feel depending on what page it was on. The easiest thing to do would have been for it to "know" what page was loading it by looking at the referrer on the HTTP request that loaded the SWF. This is a header of course, and thus not available. Instead a FlashVar could be passed in to tell the SWF what to show. That's a better way to do it, but required changing the code of the page hosting the SWF, which was not an option. The hack that had to be used was to have to logical copies of the same SWF, foo_A.swf an foo_B.swf. The SWF could then look at its this.loaderInfo.URL to figure out what to show.

Wednesday, January 09, 2008

Wii Games

I got a Wii as an early Christmas gift. I have to say that after being away from gaming for almost four years, I am really impressed where things have gone. I have had as much fun playing the Wii with my family as I did playing Street Fighter on the Nintendo with my friends back in college. That is saying a lot! Here are my games so far:

Wii Sports -- Everyone has this one, and everyone has been praising it since it came out. All I can do is echo the praise you have to give Nintendo for not only coming up with this beauty, but also for packaging it with the Wii.

PBA Bowling -- My wife liked bowling so much that we picked up this game when we got the Wii. It is a harder bowling game, but not really much more fun than the bowling that came with Wii Sports. The graphics are nice though and funny characters.

Guitar Hero III -- I had never played Guitar Hero before this, and I can see why it has been such a huge success. Unlike a lot of Wii games, it is not really a great game to play with friends. That's alright, it is incredibly addictive and fun. I got so into the songs on here, that I had to buy several of them off of iTunes.

Lego Star Wars -- This game is a lot of fun. It's simply the Star Wars saga with Lego graphics. Very simple, but still cool. The best thing is getting to use the Wiimote as a light saber. I told my wife "I've been waiting for a game like this for 30 years!"

Madden 2008 -- I haven't played this much yet, as my wife bought it for me the day we were flying back from Florida. She had wanted to buy it for me for Christmas, but it was very hard to find in Florida. I have only played one game, but the controls rock! There are a lot of things you can do, but they are (surprisingly) very intuitive. I can't wait to play a Franchise or a Superstar.

Iowa and New Hampshire

It's a new year, and an election year. So time for some politics.

The Iowa Caucus and New Hampshire Primary were both mildly interesting. Iowa was interesting because of Mike Huckabee. It's amazing to think about just how diverse the Republican Party is. In many ways it is much more diverse than the Democratic Party (of which I am a registered member of.) I don't think anyone really thinks Huckabee could be win the Republican Party nomination, yet he won pretty easily in Iowa. And he won because of "evangelical/born again" vote. Will future generations look back and marvel at how the religious right and big business were allied together to dominate politics in America. And face it folks, the Republican Party has dominated for a long time now. One could argue that if it wasn't for the divisiveness of Ross Perot, the Republican Party would now be in its 28th consecutive year in the White House.

Anyways, the New Hampshire Primary was interesting because of Hillary Clinton. You have to wonder if her "moment of vulnerability" was simply a brilliant political move. It certainly seemed to give her a victory, and one could argue that a victory for Barack Obama in New Hampshire would have given him an unsurmountable advantage.

Finally, both elections were interesting because of Rudy Giuliani. He may prove to be a brilliant strategist by just punting on the early races and betting that there will be no clear front runner. This only works if he can win Florida and many of the Super Tuesday states. The whole thing reminds me of some kind of game theory problem I had to solve in college. Speaking of which, I once wrote a paper on the absurdity of Iowa and New Hampshire playing such important roles in American politics. If Giuliani winds up being the Republican candidate, he will make my position paper obsolete.

One last thing to note ... Ron Paul. As an understated supporter of Dr. Paul, I was sad to see him only register around 10% in both Iowa and New Hampshire. You would think that such fervent supporters and the money they have raised for him would be able to turn into enough publicity to get his word out, and in turn gain some votes. He actually did quite well among younger Republicans in New Hampshire, but this just once again proves that the "young vote" is irrelevant. It's hard for me to see Paul endorsing another candidate and thus using his followers to give somebody else a decisive advantage, so in the end all of the electronic buoyed hyped of Ron Paul could be for naught. That's too bad.

Friday, December 28, 2007

Holiday Travel

  • Changing four airline tickets on Delta: $75/ticket = $300
  • Adding new rental reservation for 5 days = $250
  • Being able to let kids recover from pneumonia before traveling = priceless
Interesting side note... I couldn't just extend my current rental car (a minivan, Chevy Uplander) because we had made the reservation through Priceline. This completely stymied both Budget's national and local offices. So I we just made another reservation through Priceline for the same kind of vehicle, picking up on the day we were to drop off the current rental. One would think that they will simply let us keep the current vehicle, but who knows. Their inefficiency has cost them. We bid a lower rate on the new reservation, since it won't be during peak holiday season, but would have been happy to pay the old rate if we could have just extended the current reservation. That comes out to about $15/day = $75, plus whatever take Priceline is getting.

Wednesday, December 26, 2007

Favorite Music of 2007

Year Zero by Nine Inch Nails -- Favorite artist releases very good concept album. I can't ask for anything more.

Carnavas by Silversun Pickups -- This came out last year, and I put on my list last year as well. I listened to it even more this year though.

The Boxer by The National -- This is probably my favorite music to listen to while programming or writing. The only problem is that the songs can be so engrossing that it can be distracting.

Neon Bible by Arcade Fire -- If somebody told me "there's been no good music in 2007" my retort would begin with Neon Bible.

Because of the Times by Kings of Leon -- The consensus criticism of this album is that it was too fractured and all over the place. Maybe that's true, but the songs are excellent. Put this whole album on your iPod and hit shuffle. Every time one of the tracks comes up, it's an instant joy.

In Rainbows by Radiohead -- This is a great album -- also a good retort to any "2007 sucked" claims. I have a feeling that it will remain in heavy rotation for me next year.

Ga Ga Ga Ga Ga Ga by Spoon -- This is another enjoyable album by Spoon. This is one of those albums where each time I listen to it I ask myself "why don't I listen to this more often?"

Robbers & Cowards by Cold War Kids -- I think this also was a 2006 album, but I didn't hear it until this year. A very good album overall, but I especially love "Hang Me Out to Dry."

Icky Thump by The White Stripes -- This was a disappointing album to some people. To me it is a great listen, even though it is probably not as memorable as previous albums by The White Stripes.

Graduation by Kanye West -- I go through love/hate cycles with this album. I tend to listen to it way too much, get sick of it, then two weeks later start all over. This definitely has some weaknesses, but there are too many good tracks to ignore it.

Saturday, December 15, 2007

Les Miles

I find it funny that Michigan has wanted Les Miles so badly. I am terribly unimpressed with Les Miles. He has had a great team the last two years, but that's because of the tremendous talent that Nick Saban left for him three years ago. Saban is well known as one of the best recruiters in college football. Les Miles got a great team. Look at all of the great players on his team, and all of the best ones were Saban recruits. His coaching has been quite questionable this year. Personally I thought he got incredibly lucky in many games this year. He made many questionable calls. Worse, when questioned about some of these calls after the game, he often left the impression that he was not completely aware of the situation when he made the call. Some people mistook this for "gutsy" calls, but they were actually just ignorant calls. He was dumb, but got lucky. His team could have easily lost two more games because of his mistakes. They still wound up losing two games when they clearly have the best team in the country. I was amazed that he prepared a double spy defense to play against Darren McFadden, and they still gave up 200 yards on the ground to him. Yes McFadden is a great player, but if you prepare a "trick" defense for a guy and it fails, then some of that failure has to attribute to the "trick" defense. Anyways, Les Miles does not seem like a great coach despite his team's success. His team is successful despite his poor coaching. And yet, Michigan can't stop salivating over him...

Mitchell Report

I don't care about athletes using drugs. Most people would agree that I have a minority opinion on this. But who cares about my opinion? Most people think that athletes using drugs is a form of cheating. It is bad. Period. If I was one of those people, I would be very happy about the Mitchell Report.

A lot of people have pointed out that the evidence in the Mitchell Report would not hold up in court. They point to Roger Clemens in particular. It's as if the Mitchell Report was supposed to produce evidence to be presented to a grand jury or something. If that would have been the purpose, then it would not have been worth releasing.

I think the point was to justify stricter measures to prevent the use of drugs in baseball. Obviously you can only prevent future use, you cannot change the past. If that is the purpose, then I think it does a very good job. It shows that by only getting two people to cooperate, they were able to find evidence against dozens of players. There is no way the public could not come away feeling that drug use is widespread in baseball. It's not just the guys hitting 40+ home runs. It's the starting pitchers, the relief pitchers. It's the low-power, fast running infielders and outfielders, as well as the sluggers and wannabe sluggers. It's the utility bench players. It's the upcoming players and aging veterans. It's future hall-of-famers and guys struggling to get at-bats.

If the public thinks that everyone is using, then it will be hard for the player's union to stop the owners from instituting testing that is on-par with the NFL or maybe even the Olympics. Smart and/or cynical folks will say that players will still find ways to use drugs to get an advantage, but it does not matter. All that matters is that most fans feel like order has been restored. They feel like they are watching a "fair" and "clean" game. The Mitchell Report forces the players' union to accept this kind of testing, or baseball will lose fans, and players' salaries will fall. It's that simple.

Now if three years from now, Alex Rios leads the majors with 25 homers... Well that would be pretty interesting, wouldn't it? I don't think it will be the case. There will the usual fluctuations in hitting vs. pitching, but no amount of drug testing will have much affect on the general proclivity of home runs.

Wednesday, December 12, 2007

ActionScript Reflection Workarounds

ActionScript has some nice reflection features. However, if you are used to Java or C# (for example) then ActionScript can seem kind of sub-par. One of the easiest things to do in Java is to create a new instance of a class dynamically:

Class<MyAwesomeClass> clazz = MyAwesomeClass.class;
MyAwesomeClass instance = clazz.newInstance();

Clearly this assumes a default constructor, but you get the picture. The equivalent in AS is:

var x:MyGreatClass;
var clazz:Class = flash.utils.getDefinitionByName("MyGreatClass") as Class;
var instance:MyGreatClass = new clazz() as MyGreatClass;
A couple of things to notice here. First, you have to declare a variable of the given type. Otherwise the AVM2 virtual machine is not smart enough to load the class and will blow up on the second line (thanks Wikipedia!) Next the standard AS Function getDefinitionByName returns an Object, not a Class, so you have to cast it. The only nice part is that you get to use the new operator with the instance variable clazz. Ah, finally we get a job-of-dynamic-language moment. To improve on this, I add a boilerplate method to my classes:

public static get clazz():Class
{
return MyGreatClass;
}

This let's me do the following:

var clazz:Class = MyGreatClass.clazz;
var instance:MyGreatClass = new clazz() as MyGreatClass;

Not quite as nice Java still, but close! The first line causes MyGreatClass to get loaded by the VM while at the same time providing a handle on the Class in question in a very convenient manner.

Tuesday, December 11, 2007

This is the Team We Want to Move to the South Bay?



Clearly one of these guys must go.

Nolan won't go because it would "send the wrong message" to the team.

Smith won't go because it will kill them with the salary cap.

So they will both be back and the Niners will be very bad ... again.

Monday, December 10, 2007

Tebowisms

Yeah, I'm pretty happy that Tim Tebow won the Heisman. He certainly deserved it. It was kind of sweet that Colt Brennan finished a distant third place. So much for June Jones and his attempt to raise up his guy by degrading Tebow.

I was reading the newspaper in Tahoe on Saturday, anticipating the Heisman ceremony that evening. They mentioned "Tebowisms" which appear to be similar to Chuck Norris Facts. Mildly amusing.

Anyways, Tebow gets one more team to wallop on this year, and it's another Big 10 team: Michigan. If you can't beat Appalachain State... heh heh. Vegas has Florida as 10 point favorites. Only USC is a bigger favorite among New Years day (and after) bowls, at 13.5 points over in the Rose Bowl. The SEC is heavily favored this year in general. SEC teams are favored in six of the eight bowl games they are playing in.

Next year should be interesting for Florida. Tebow says he will not leave for the Pros no matter what happens next year. He's certainly not your prototypical NFL QB anyways, so this may well be the case. Percy Harvin on the other hand is definitely going to be a high NFL draft pick. He is a little short for the pros, but his speed is ridiculous and his hands are very good as well. If Ted Ginn, Jr. is a first round pick, Harvin definitely is as well. So next year becomes make-or-break for Florida.

Friday, December 07, 2007

The Heisman and System QBs

There has been a lot of talk about "system" QBs. People point out Andre Ware or Texas Tech as examples of how systems can lead to inflated numbers. Sure they can. But the real issue is level of competition, not systems. That's why Texas Tech puts up big offensive numbers. That's why Hawaii does, too. A low level of competition will always cast extra scrutiny on star players.

Nobody complained about Tommie Frazier winning the Heisman. Clearly he was in a "system" albeit one where he ran the ball much more than he threw. It didn't matter. Nebraska played and beat the best out there. It takes a great player to perform at such a high level against tough competition.

June Jones and others have also made a point about the NFL potential of players being a factor in Heisman voting. That is just ridiculous. If NFL talent was relevant at all, then Peyton Manning should have won three Heismans. There has never been a more sure-fire future Pro Bowl quarterback coming out of college, but he did not win the Heisman and for good reason.

There have been many Heisman winners to have no little or no NFL success, particularly quarterbacks: Ware, Frazier, Charlie Ward, Danny Wuerffel, Jason White just to name a few. There is nothing wrong with this. It's part of the beauty of college athletics that it's not just the most physically gifted individuals who have the most success.

So sorry June Jones. Maybe your boy will be good in the NFL, who knows? Nobody runs your "pro" offense there, so I don't know how much his experience in Hawaii will help. Whatever the case, Hawaii has not played against formidable competition at all. You can't claim to be the best without playing against at other good teams. That is why Hawaii's undefeated season will not get them a shot at a national title game, and that's why Colt Brennan could throw 100 TDs and not win the Heisman.

As a side note, there was one thing that made me really happy when I read about June Jones's disparaging comments about Tim Tebow. I learned that Hawaii opens its season next year at The Swamp. Talk about sweet justice! Hawaii is going to torn up by Georgia in a few weeks, so that will demonstrate how meaningless their perfect season is... But it will be even more demonstrated next August. And before anyone brings up Boise State from last  year, try to actually remember that game. They had every break in the world, and still had to gamble on a trick play to be able to win that game. If that game was played nine more times, how many times do you think Boise State would win? Let's be honest here, maybe once?

Rails 2.0 Released

If you are upgrading, I recommend upgrading Gems first (gem upgrade -system) and then using it to upgrade Rails (gem install rails --server http://gems.rubyonrails.org). There are some nice features. I especially like some of the Ajax security and JavaScript aggregating. The (expanded) JSON and XML support in ActiveRecord is also nice. 

Wednesday, December 05, 2007

Tuesday, December 04, 2007

Confused Microsoft


So which is it Microsoft? Is Popfly a download, or not?