On the bleeding edge

Case 1

We use JRuby with Mongrel and Derby, developing in Eclipse. We wrote many custom scripts to ease development, to start/stop servers, run rake scripts. We hack Mongrel because it couldn’t work with JRuby then. We patch ActiveRecord JDBC manually to make Derby behave correctly. Eclipse RadRails wouldn’t play well because we’re not using CRuby.

Few months after the release of our product, Aptana releases an Eclipse IDE with RadRails that completely supports JRuby, therefore run rake scripts, supports running the Rails app in Mongrel, and supports the Derby database.

Case 2 (today)

Deployment test of a new JRuby app on a new machine. During gem install we realize a new version of ActiveRecord 2.1 (from 2.0.2). Rake migration wouldn’t run after it because the SQL statement generated a “DEFAULT NULL NULL” in a CREATE TABLE statement.

Traced the code, found issue to be likely in activerecord-jdbc. Looked at JRuby Extras, and activerecord-jdbc-adapter had 0.8.1, release June 4, 2008 (today). Checked the SVN source, Nick Sieger checked in barely 6 hours ago at 5:19am to “Fix problem with AR 2.1 and Derby with ‘DEFAULT NULL NULL’ in column defs” (as per SVN commit comment).

Upgraded the gem from 0.8 to 0.8.1, but we got an “undefined method `true?’ for false:FalseClass” right at the line of Nick’s fix.

Filed my second JRuby (ActiveRecord) bug.

* We did force versions during gem install, but we didn’t expect the new version to screw up so much.

Intel Core

Haven’t been following up on hardware. I’ve actually read these numerous times but keep forgetting. I needed to look up some PC specs today, so its now here for my own reference.

Intel Core is the series of Intel’s 32-bit dual-core processors. Intel Core Duo is the one with the dual core, and the Intel Core Solo is the one with dual core, but only one active. According to Wikipedia, it’s so that Intel can sell those with manufacturing defects on one core but not the other. Sounds logical to me, but can’t find supporting information elsewhere.

Intel Core 2 is the 64-bit series. So Intel Core 2 Duo means a 64-bit dual core processor, and Intel Core 2 Quad are the 64-bit quad cores.

On the other side, there was this (old) HyperThreading technology by Intel, which also have a “dual-core” impression because it shows up as 2 processors on XP. However its actually just one processor that simulates an additional one for doing useful work during otherwise idle cycles.

AMD’s naming is 64 means 64-bit, and X2 means dual core. So you have series like Athlon 64, Athlon 64 X2, Turion 64, Turion 64 X2.

Combine physical disks into one logical drive

Got asked this interesting question today. Usually I hear one big physical disk split into multiple logical drives, but this time a single logical drive made up of smaller physical disks is desired.

I think RAID 0 fits this scenario, but to store a piece of file equally in 2 places for personal use (not a server) looks pretty useless to me. If one disk breaks, you’re left with half of every file, which is no different from breaking both. As compared to if you had two logical drives on two disks, if one disk break, you have the other disk with some complete files.

Are there other alternatives?

Unlocker

Fed up with the Windows Explorer message that I can’t delete a folder, because it’s locked. By who? I closed my Firefox and Eclipse and it’s still there. Short of killing my explorer.exe process like I always tool, I checked out a freeware tool called Unlocker.

Right-clicking the offending folder from Explorer and selecting Unlocker showed me it was really Explorer, but I had an option to “Unlock” it instead of killing the process. Quickly done.

Note: Remember to uncheck all other options when you install the tool (such as eBay shortcuts). I’m not sure what Assistant does, I unchecked it too.

The geek is not idle

The geekblog hasn’t been updated, but the geek has not been lazing. We’ve been looking at:

ExtJS –[JSON over HTTP]–> Apache/Lighttpd –[FastCGI/HTTP]–> Mongrel/Thin/etc -> Ruby on Rails –[WebService]–> Java –[etc]–> etc

Why? Because:

  1. We have a set of Java API that we’d like to expose, even to other languages, as a service.
  2. We previously use Mongrel, Rails with JRuby, as we want to invoke Java from within, as well as use JDBC. This restricts us to pure-Ruby libraries or those that has a JRuby port.
  3. Most servers and cluster options are written for Unix. We need an easier Windows solution to run a ruby-server cluster. The cluster is necessary as Rails is single threaded.
  4. We previously had PrototypeJS (came with Rails) implementing a “rich client” on the client side, and communicated in a mixture of data and presentation. We struggled with many features, including drag and drop, resizable layouts, split panes, spinners, trees (plus lazy loading, icons), toolbars (plus icons, dropdowns, disabling highlight), tables (plus sorting, selection, multi-select, column hiding, pagination), tabs, right-clicks, and more. All these seem to be handled by ExtJS. At the same time it allows easy customization by extension and even hooks. This was important as the given widgets may not fit requirements.

This is all interesting to the geek, maybe because it looks like an ‘architecture’.

Shallow Clone

A typical way of cloning an object is to use super.clone() to shallow-clone it, then modifying/cloning any members to create a complete clone.

Extra care must be taken if the original contains members that reference back to itself, e.g.


public class Model implements Cloneable {
  private PropertyChangeSupport support;
  private String name;

  public Model(String name) {
    support= new PropertyChangeSupport(this);
    this.name = name;
  }

  public void setName(String newName) {
    String oldName = this.name;
    this.name = newName;
    support.firePropertyChange("name", oldName, this.name);
  }
}

When this object is cloned the support member variable still references the original object (due to Object’s direct member assignment), thus the listeners would receive a wrong reference.

To fix this, implement a custom clone() method to take care of it. Make sure a new instance is created for it. If you simply change the reference inside the PropertyChangeSupport object, it will screw up the original object instead.


  public Object clone() {
    Model clonedModel = (Model)super.clone();
    clonedModel.support = new PropertyChangeSupport(clonedModel);
    return clonedModel;
  }

An Array of a List of Strings

I needed to create an Array of a List of Strings (actual problem anonymized). With generics I declared the variable:


List[] typedListArray;

Then I proceeded to create it.


typedListArray = new List[4]; // compile error

I needed to create the array first, like how I create new int[4];. But no matter how I moved the syntax, it wouldn’t compile. Read the JLS and searched the web, and finally found this explanation. It was not even a solution.

The reason the creation was disallowed was due to type erasure. Java’s implementation of generics only applies at compile time to ensure that the correct types are used. During runtime, the type information is erased. By creating a concrete parameterized array type, the runtime is unable to ensure that the correct items are added to the list. It is therefore senseless to allow the creation. The ways “around” it were to live with the warning, or to suppress it with annotations.

Then why allow the declaration?

Constructor Design

2 colleagues were in a “heated” argument over a design of constructors, which needed to have some form of the following parameters:

  • int code, String name, Serializable objParam
  • int code, String name, String xmlParam

The 3rd param could be either a String representing XML for an object, or a Serializable object. Both of them agreed there would be trouble differentiating between the two parameters, since Strings are serializable as well, and sometimes clients may want a String to be the Serializable param instead of XML.

To me it’s a non-issue, since the compiler is smart enough to use the String constructor if 3rd parameter was a String, and use the Serializable if I explicitly cast the String into Serializable (if I remember my signature-matching facts correctly).

One of them strongly pushed for a single constructor with 4 parameters, and passing in null for either the 3rd or 4th one. He argued this resolves ambiguity, as well as too many combinations of constructors available.

The other wishes to remove the optional 3rd parameter and use only 2 parameters. The 3rd parameter would be achieved using set methods.

Debate ensued, each bringing up points to support their views, such as cleanliness of API, ease of use, danger of forgetting to set the parameters, more parameters added next time. I wasn’t actually in the debate, I just happened to be the 3rd party in their chat window.

After a long while I suggested using static creational methods to differentiate between the 2 constructors. Something like Class.createXXXType() and Class.createYYYType() which I felt would be clear which “constructor” to refer to, non-ambiguity as well as stability of the instance created.

They didn’t take it very well too, and I left my suggestion as it is. There’s still no conclusion yet, they are still hesitating to call for a design review for this small matter.