Integrity and Everything

I just wanted to mention two programs that I’ve found very useful: Integrity and Everything.

Integrity is a very convenient, easy to use HTML link checker for MacOS. It’s “donationware” and has helped me make sure I don’t have any broken links in my work website, my personal website, and my course website. And currently, it’s working on this blog.

Everything is a fast NTFS file name search program for Windows. Here’s a review. It’s not quite Spotlight for MacOS, because it doesn’t search file contents, it only scans file names, but it is very fast.

Share
Posted in Uncategorized | Leave a comment

Print This Post Print This Post  

Academia.edu and Publications Category

A few days ago, I got an email from Academia.edu, which seems to be something like Facebook for people in academia. It’s a tree of universities, departments, faculty members and students. I originally wasn’t too interested in it, but decided to fill out my profile anyway.

There are profile pages that allow you to upload papers, presentations, declare research interests and describe your teaching experience, so I did that. The documents are uploaded as “iPaper”, and honestly, the preview still needs improvement. Right now, this part of the website is a bit annoying, as are most parts that use the AJAX “Web 2.0” style of editing (not reloading the entire page).

So, right now I wouldn’t use Academia.edu to find material or people, but apparently it has a really high Google PageRank, and therefore a lot of weight for links. It seems like it has given my own website a considerable bump. I think it can be quite beneficial simply from the point of view of publicity.

The website also has an interesting feature that records what Google search terms lead web surfers to your Academia.edu profile. Here are the keywords that lead people to me — the actual things that they typed into Google:

  • converting to a new temperature scale
  • junit concurrent test
  • conclusion on marine biology
  • how to calculate the complexity of a given code using big o notation with exercise and solutions
  • design pattern parser
  • change in temperature calculations
  • In java, show an example of a conversion from celsius to Fahrenheit temperature
  • parsing design pattern

Apparently, temperature conversion is a very popular assignment, and my Temperature Calculator comes up quite often. I’m also amused by the fact that people type whole questions or requests into Google. “Google, please tell me why they do that. Thanks, bye.”

Additionally, Academia.edu has inspired me to collect all my papers, presentations and posters in one place, and I’ve created the Publications category. In that category, I have inserted my publications, both refereed and unrefereed, on the day they were made available. Because of that, the calendar of my blog now stretches back to 2003.

I decided to use a category on this blog mainly because now there is an RSS feed for my publications, and interested readers can easily subscribe and be notified of new material. On my non-blog work website, I have also added a publications page, both with long descriptions and without.

Finally, I’ve added an extra credit part to the COMP 202 schedule, worth 20 points which will be counted towards the midterm. It’s hard to believe that only five weeks are left in the semester. Two thirds are done.

Share
Posted in COMP202, Ramblings, Research, Uncategorized | Leave a comment

Print This Post Print This Post  

Sometimes I feel really dumb

I was reading this MixGen paper, and I came across this symbol in the antisymmetry lemma (5.13). It looked kind of like $\not\vdash$ and I thought maybe that was supposed to be the symbol for antisymmetry, but it wasn’t defined anywhere.

After minutes of confusion and scanning through the paper I realized that it was simply a turnstyle $\vdash$ crossed out. Durrh.

Share
Posted in Ramblings, Uncategorized | Leave a comment

Print This Post Print This Post  

volatile For Synchronizing non-volatile Data

Jevgeni Kabanov on dow.ngra.de made an interesting observation that I had noticed at one point when I was studying the new Java Memory Model, but that I had forgotten again.

A shared volatile variable that thread A writes to and thread B subsequently reads from guarantees that thread B sees everything that thread A saw when it wrote to the volatile variable, even if the other data is not volatile itself.

The most easily accessible documentation about this is from Bill Pugh’s JSR-133 FAQ:

Under the new memory model, it is still true that volatile variables cannot be reordered with each other. The difference is that it is now no longer so easy to reorder normal field accesses around them. Writing to a volatile field has the same memory effect as a monitor release, and reading from a volatile field has the same memory effect as a monitor acquire. In effect, because the new memory model places stricter constraints on reordering of volatile field accesses with other field accesses, volatile or not, anything that was visible to thread A when it writes to volatile field f becomes visible to thread B when it reads f.

Update

A very similar post popped up, Thread-safe non-synchronized read/writes?, and a commenter Matthias (not me, I have just one ‘t’) makes an important point:

Since the revision of the memory model, writing to a ‘volatile’ guarantees that no previous write will be reordered beyond it. Vice versa with reads. That’s why you can use volatiles for synchronization purposes – but only if you both write it in one thread _and_ read it in the other.

(Emphasis added by me).

Share
Posted in Concurrent Unit Testing, Ramblings, Uncategorized | Leave a comment

Print This Post Print This Post  

Mixed Bag

This post is just a mixed bag of things. First, a handful of things I’d like to achieve. I guess you could call them resolutions, although I’m haven’t quite reached the point of resolving them yet:

  • Learn to write the one-sentence email. A few people do this, and while it sometimes annoys me, especially in personal emails and because I like to write, it is really more effective. Last week, I sent out an email that had three short paragraphs with two questions; my conversation partner only replied to the first. When I sent out the second question again by itself, I got a reply.
  • Get up early more consistently even on days when I don’t have to get up early, and go to bed around the same time, even when I could stay up a bit. I have gotten a lot better this year, but there is still room for improvement. When I get up later, the whole day seems to be messed up somehow. To do that, I need to go to bed around the same time, but I love staying up late, browsing the web. It’s one of my guilty pleasures.
  • Take better notes when I read papers. Writing helps retention. I’m more of a big-picture person, so I tend to forget seemingly unimportant details like names of authors or even which papers I’ve read (that doesn’t mean I forget what it was about, I just couldn’t tell you if I’ve read “Smith 2007” or “An Efficient Semantics the Theta Calculus with Futures and Traces”).
    While I can read much better if I don’t have a computer with me, I think using Papers by mekentosj.com could help. It has been described as “iTunes for Papers”, and it can help to get bibliography items right, to tag and search papers, and to store notes. I’ve shelled out the $25.20 for a license after 40% student discount.

And in the past few weeks, I have taken a great liking to some online radio stations and podcasts, and an internet TV station:

  • DW-RADIO liveDeutsche Welle, news from the heart of Europe. World and German news in English. Unfortunately, the program repeats a lot, so you can’t listen to it all day.
  • Scientific American 60 Second Psych, 60 Second Science, and Science Talk. 1 minute/1 minute/30 minutes of miscellaneous science news. Especially the 1-minute podcasts fit in many little breaks during a day.
  • AAAS Science Update – Same. 6 to 10 minutes.
  • Hulu – has many shows that I would otherwise miss by accident or because I have cable. It’s almost a TiVo on the web, and you can time-shift the shows. 30 second advertisement only. I’m watching “The Colbert Report”, “The Tonight Show”, “American Dad!”, “Family Guy”, “House”, “Saturday Night Live” and “Terminator” there.

And finally, ever since returning from Germany and Finland, I’ve started to eat a lot of these foods:

  • Blueberries – I miss having my own blueberry bushes outside.
  • German muesli bread – relatively cheap at my local Fiesta. Now my mom doesn’t have to bring me bread anymore when she visits.
Share
Posted in Ramblings, Uncategorized | Leave a comment

Print This Post Print This Post  

Re: Dear Apple: Some Java Love, Please?

Joey Gibson expresses exactly how I feel. I love Apple, but the state of Java on the Mac is probably beyond what’s rationally bearable.

Share
Posted in Ramblings | Leave a comment

Print This Post Print This Post  

Java Annotations for Types, Expressions and Multi-Staging

I gave another presentation in our PLT seminar today. The title was “Annotations for Types and Expressions”, but I really should have squeezed multi-stage programming (MSP) in there, because that was really the big benefit I want to achieve from adding annotations to expressions and statements.

I’ve been feeling a bit under the weather the last couple of days, so it makes me very happy to think the presentation went well. I got some good feedback again, mainly that I should have advertised the MSP part more. Someone also said that I have a “soothing voice”, which doesn’t aid in keeping tired audience members awake. I need to work on my vocal variety.

I spent the rest of the day grading the COMP 202 midterm and doing some maintenance for the course.

Share
Posted in Graduate School | Leave a comment

Print This Post Print This Post  

Presentation: Java Annotations for Types and Expressions

Java Annotations for Types and Expressions

Where: Rice University Computer Science Department, RAP Seminar
When: October 24, 2008

As defined in Java 1.5, Java annotations can only be attached to very few targets: Classes, methods, method parameters, fields, and other annotations. The Java community intends to extend the list of targets and has issued Java Specification Request (JSR) 308, “Annotations on Types”. The current proposal for JSR 308 is considering allowing annotations on statements, but not on expressions.

In this talk, I discuss how the changes proposed by JSR 308 and its Checker Framework allow programmers to enhance Java’s type system and provide additional static guarantees. Additionally, I demonstrate that the same mechanism proposed for annotations on statements can be used to describe multi-stage programs in Java.

Share
Posted in Publications | Leave a comment

Print This Post Print This Post  

Bad Shortcuts

Sometimes, trying to take a shortcut can make your life more difficult: Today I didn’t plan on staying long after giving my two lectures, COMP 202 at 10 AM and COMP 311 at 1 PM, so I felt I didn’t need to bring my notebook to do some “serious” work. What I had forgotten, though, was that the room in which COMP 311 is held does not have a podium PC, and I didn’t realize that until I had already arrived at my office.

So I had to go back home during my lunch break to get the notebook. I should have just brought it in the first place.

I ended up going through detailed hand evaluations for the first and third sample program, both in call-by-value and call-by-name, and discussed the second program at a higher level, because it was less interesting.

I extracted some new pictures from today’s lecture, Dictionaries & Hashing (#22):

Share
Posted in Pictures, Ramblings, Teaching | Leave a comment

Print This Post Print This Post  

Symphony and Exams

Yesterday, I finally went to the first symphony concert of my subscription. Originally, I was supposed to have gone to a concert over a month ago already, but it was the night that hurricane Ike hit, so I rescheduled it. The new concert was yesterday afternoon, Beethoven 2 and Tchaikovsky’s Rococo.

Beethoven, of course, was fantastic. The cello solist, 25-year-old Alisa Wellerstein, was also very good, although I typically enjoy the entire orchestra more than solists. Therefore, I didn’t like Tchaikovsky as much as Beethoven’s 2nd Symphony. The first of the smaller pieces, “Adagio con Variationi” for cello and orchestra by Respighi was just amazing. Instantly I knew again why I am going to symphony concerts. Here, the interplay between the cello solo and the orchestra was perfect. Finally, Debussy’s “La Mer” was impressive as well.

In a few minutes I will hand out and proctor the COMP 202 midterm. Early today a student told me that he is sick and may not be able to take the exam. I said I will write a make-up exam and schedule a new time for him to take it. I spent the early afternoon writing a second midterm, but now it appears he feels better. If he does take the exam and I end up not needing the make-up exam (@ He ended up not taking the exam, so I need the make-up exam. @), I will probably just use the questions for the final.

On Wednesday I’ll be pulling double duty when it comes to teaching, as Corky has asked me to sub in for him in his COMP 311 class.

Share
Posted in COMP202, Ramblings, Teaching | Leave a comment

Print This Post Print This Post  

DrJava User Sites

I added another user site to the DrJava website (and added the ones I found before but could not add):

I also found out that DrJava is a FreeBSD package, which should make it easy to install on that operating system, and I discovered a blog entry about Kah Hong’s experience of using DrJava in his Programming Methodology class:

Without the reassurance of DrJava, I certainly felt lost during certain points of the test, and also vulnerable to the trick questions that awaited me.

Share
Posted in DrJava | Leave a comment

Print This Post Print This Post  

Addressing the SourceForge Login Problem

I have address the fact that SourceForge disabled the interactive shell, which we mainly used to edit the DrJava website, by creating a mirror of the DrJava website at http://www.cs.rice.edu/~javaplt/drjava/ (something we have inconsistently done in the past), editing the website on CSnet, and then using rsync to transfer them to our SourceForge website at http://drjava.org/.

To do that, I created a javaplt SourceForge account, set up password-less login into SourceForge from javaplt on CSnet, and updated our mirror on CSnet for the DrJava website that we have on SourceForge. Both websites have the same content now.

Changes to the website should be made on CSnet in /home/javaplt/public_html/drjava/.
You then need to copy your changes to the SourceForge website by running the drjava-cs-to-sf script I created (located in ~javaplt/bin, but it’s on the path for the javaplt CSnet account). This script does an rsync to transfer all modified files to SourceForge. Files that do not exist on CSnet anymore but are still present on SourceForge are deleted.

There is also a script that copies in the opposite direction, from SourceForge to CSnet: drjava-sf-to-cs (also located in ~javaplt/bin). Because we should consider the CSnet site our primary location for editing, drjava-sf-to-cs makes backups of deleted or modified files in /home/javaplt/public_html/drjava/.backup/. We should clean that directory occasionally, but it is excluded from drjava-cs-to-sf, so the backed up files never end up on SourceForge.

To do a dry-run without copying, you can pass the --dry-run argument to the scripts; to force all files to be copied (ignoring time stamp and size), you can pass -I. Example: drjava-cs-to-sf --dry-run -I.

I have also updated the update-news script that we had on SourceForge. It is now called drjava-update-news (also located in ~javaplt/bin). It updates the news on CSnet and then copies only that file to SourceForge.

Share
Posted in DrJava | Leave a comment

Print This Post Print This Post  

Poster: Invariant Specification and Multi-Staging using Java Annotations

Invariant Specification and Multi-Staging using Java Annotations

Where: Rice University Computer Science Department, Corporate Affiliates Meeting 2008
When: October 16, 2008

Java annotations allow programmers to attach metadata to programs. During normal execution, the annotations are ignored, but in contrast to comments in the source code, annotations can be manipulated programmatically at compile- or run-time. We propose two extensions — subtyping and expression annotations — for consideration in the Java specification request for annotations, and show how annotations can be used to express program invariants and multi-stage programs.

Share
Posted in Publications | Leave a comment

Print This Post Print This Post  

SourceForge Removes Shell Access, Becomes Terrible Mess

SourceForge is a terrible mess now. The old and new documentation is all mixed up — if new documentation is available at all, which is the exception, then the old documentation is easier to find. When I tried to figure out why SSH access to shell.sourceforge.net wasn’t working anymore, I was finding only the old documentation (which I followed exactly, unsuccessfully, of course), not any new documentation.

As it turns out, SourceForge decided to just remove interactive shell access. The only place I found this mentioned was in the linked support request! How is that documentation?

SourceForge really need to remove outdated documentation! It’s better to have no documentation than to have outdated, incorrect, misleading documentation. I wasted a day trying to figure out what I was doing wrong. Now I realized I wasn’t doing anything wrong, I was just correctly following SourceForge’s incorrect documentation.

I still have not even figured out how to do anything using the new “replacement” services for the shell. We have to rethink the way we update the news on the web site, and right now I don’t even know how to effectively edit the website. Editing it using emacs in the remote shell was very easy and direct; having to rsync the files back and forth seems like a huge hassle.

We need to look at alternatives and consider taking DrJava away from SourceForge and somewhere else, or at least figure out an easy way to update the news and edit the website. I’d welcome any suggestions.

I’m sorry for the rant, but I’m very irritated that I wasted a day on something as silly as trying to log in using SSH, figuring I must be doing wrong.

Share
Posted in DrJava, Ramblings | Leave a comment

Print This Post Print This Post  

Rice’s Bike Policy Needs upgrade, Annoys

Another one of my letters to the editor of the Rice Thresher got printed in the October 10, 2008 issue. This time, I complained about the new bike policy that bans biking on sidewalks entirely.

It’s the third letter down:

Bike policy needs upgrade, annoys

To the editor:

Today, I was stopped for the first time for biking on the sidewalk, even though I was using the bell that the Rice University Police Department had handed out, in addition to yelling a courteous “Excuse me… Thank you.” As law-abiding citizen, I pushed my bike from the music school to Duncan Hall and thus had plenty of time to think. I came to the conclusion that the bike policy goes too far.

In 21 years as a cyclist, I have never made contact with a pedestrian or other cyclist, so I am convinced that a “yell or bell” policy is sufficient. If biking on sidewalks, at any speed, with all due caution, really is so dangerous that it needs to be banned entirely, then the administration should consider the following:

1) The Inner Loop is currently a one-way road. Depending on where bikers enter campus and where they need to go, this could double the distance that needs to be biked on the loop. A narrow “contra-flow” bike lane on the loop in the opposite direction would be tremendously beneficial.

2) Since many buildings are not adjacent to the Inner Loop, there need to be more bike stands along the loop. The number of bike stands near shuttle stops is not nearly sufficient.

3) To avoid the impression that Rice is using the imposed fines to (minimally) pad its bottom line, it should be clear what the revenue is used for and that students benefit from it.

I hope that the administration will reconsider the current outright ban of biking on sidewalks and find a middle ground that provides both safety and convenience.

Mathias Ricken
Computer science graduate student

Share
Posted in Uncategorized | Leave a comment

Print This Post Print This Post  

Update to WordPress 2.6.2

I just upgraded the blog software to WordPress 2.6.2. If you notice any problems, please let me know.

Share
Posted in Uncategorized | Leave a comment

Print This Post Print This Post  

Java Multi-Methods Using Proxies and Annotations

After working a little bit with Java proxy classes for my yet incomplete support library for xajavac, which introduces subtyping to annotations, I started to think about what else I could do with them.

Proxies are essentially a wrapper around another object. Instead of calling a method of the wrapped object, a single invoke method is called and provided the Method object of the method that was to be called, along with the parameters:

public class MyProxy implements java.lang.reflect.InvocationHandler {
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
// ...
return result;
}
}

Inside this method, the programmer can now do string comparisons on the method name, for example, and dispatch different methods, or perform some kind of pre- and post-processing. I used this, together with a very simple @MultiMethod marker annotation, to create multi-methods in Java.

Java normally only performs static dispatch and single dispatch. In static dispatch, the class of the method is decided at compile time already; in single (dynamic) dispatch, the class containing the method depends on the run-time type of the object. Static dispatch applies to static methods. Single dispatch, on the other hand, works with non-static methods and is the foundation of polymorphism. To demonstrate single dispatch, let’s consider the classic example of polymorphism:

interface IAnimal {
public void speak();
}

class Cat implements IAnimal {
public void speak() { System.out.println("Meow"); }
}

class Dog implements IAnimal {
public void speak() { System.out.println("Woof"); }
}

// ...
IAnimal a = new Cat();
a.speak(); // prints "Meow"
a = new Dog();
a.speak(); // prints "Woof"

At the call site, we just have an IAnimal, and we call its speak() method. Depending on whether the run-time type is Cat or Dog, the appropriate method is called. The dispatch is based on the receiver, object whose method is called.

However, the dispatch only depends on the receiver; the run-time types of the arguments do not matter. For example, if we create a feed(IFood food) method in IAnimal and then provide a specialized feed(Catnip food) method in the Cat class, the general Cat.feed(IFood food) method will be called even when the argument is of type Catnip. It is single dispatch, not multiple dispatch:

interface IFood { }
public Catnip implements IFood { }
public PetFood implements IFood { }

interface IAnimal {
public void feed(IFood food);
}

class Cat implements IAnimal {
public void feed(IFood food) { System.out.println("Num num"); }
public void feed(Catnip food) { System.out.println("Meow, my favorite!"); }
}

class Dog implements IAnimal {
public void feed(IFood food) { System.out.println("Gobble gobble"); }
}

// ...
IAnimal a = new Cat();
a.feed(new PetFood()); // prints "Num num"
a.feed(new Catnip()); // also prints "Num num", not "Meow, my favorite!"
a = new Dog();
a.feed(new PetFood); // prints "Gobble gobble"

If Java were to call the most appropriate method, where the class is determined by the receiver run-time type, and the actual overloaded method by the best match of the argument run-time types, then Java would be performing multiple dispatch. This, however, is not part of the Java Language Specification.

Using proxies, however, it is possible to intercept the call to the feed(IFood food) methods, look through the overloaded methods and compare their parameter types to the provided argument run-time types, and then call the method that is the closest to the run-time types, i.e. where all argument types are supertypes of the argument run-time types, and where the types are most closely related (defined as the number of edges separating the nodes in the type hierarchy).

To get a behavior like the one above, Java programmers (and programmers of most languages) usually employ the Visitor design pattern. Multi-methods (methods with multiple dispatch) make this unnecessary. Here is a more useful example of an abstract syntax tree (AST) consisting of integer and variable leaves and addition and multiplication interior nodes. First the code using the Visitor pattern to achieve double dispatch:

interface IAST {
public Object execute(IASTVisitor v);
}

class Num implements IAST {
private int _num;

public Num(int n) {
_num = n;
}

public int getNum() { return _num; }
public String execute(IASTVisitor v) { return v.numCase(this); }
}

class Var implements IAST {
private String _var;

public Var(String v) {
_var = v;
}

public String getVar() { return _var; }
public String execute(IASTVisitor v) { return v.varCase(this); }
}

class Add implements IAST {
private IAST _left;
private IAST _right;

public Add(IAST l, IAST r) {
_left = l;
_right = r;
}

public IAST getLeft() { return _left; }
public IAST getRight() { return _right; }
public String execute(IASTVisitor v) { return v.addCase(this); }
}

class Mul implements IAST {
private IAST _left;
private IAST _right;

public Mul(IAST l, IAST r) {
_left = l;
_right = r;
}

public IAST getLeft() { return _left; }
public IAST getRight() { return _right; }
public String execute(IASTVisitor v) { return v.mulCase(this); }
}

interface IASTVisitor {
public String numCase(Num ast);
public String varCase(Var ast);
public String addCase(Add ast);
public String mulCase(Mul ast);
}

class ToStringVisitor implements IASTVisitor {
public String numCase(Num ast) {
return String.valueOf(ast.getNum());
}
public String varCase(Var ast) {
return ast.getVar();
}
public String addCase(Add ast) {
return "("+ast.getLeft().execute(this)+" + "+ast.getRight().execute(this)+")";
}
public String apply(Mul ast) {
return "("+ast.getLeft().execute(this)+" * "+ast.getRight().execute(this)+")";
}
}

//...
IAST a = new Mul(new Add(new Var("x"), new Num(5)), new Num(-2));
a.execute(new ToStringVisitor());

The interesting point here is that each subclass of IAST has to have an execute(IASTVisitor v) method that accepts the visitor. The method implementations in the subclasses then call the corresponding case method in the IASTVisitor. When we execute the visitor on the AST (the host), we achieve double dispatch because there are two instances of single dispatch, once depending on the run-time type of the host, a, and again inside the execute method depending on the run-time type of the visitor, v.

With multi-methods, we can now remove the execute methods in the IAST hierarchy. We now just have an overloaded apply method in IASTVisitor where the type of the parameter changes and also determines which method gets invoked:

interface IAST { }

class Num implements IAST {
private int _num;

public Num(int n) {
_num = n;
}

public int getNum() { return _num; }
}

class Var implements IAST {
private String _var;

public Var(String v) {
_var = v;
}

public String getVar() { return _var; }
}

class Add implements IAST {
private IAST _left;
private IAST _right;

public Add(IAST l, IAST r) {
_left = l;
_right = r;
}

public IAST getLeft() { return _left; }
public IAST getRight() { return _right; }
}

class Mul implements IAST {
private IAST _left;
private IAST _right;

public Mul(IAST l, IAST r) {
_left = l;
_right = r;
}

public IAST getLeft() { return _left; }
public IAST getRight() { return _right; }
}

@MultiMethod
public interface IASTVisitor {
public String apply(IAST ast);
public String apply(Num ast);
public String apply(Var ast);
public String apply(Add ast);
public String apply(Mul ast);
}

class ToStringVisitor implements IASTVisitor {
public static IASTVisitor create() {
IASTVisitor v = new ToStringVisitor();
v.proxy = MMProxy.newInstance(v);
return v.proxy;
}
private IASTVisitor proxy;

public String apply(IAST ast) {
throw new AssertionError("Should never happen.");
}
public String apply(Num ast) {
return String.valueOf(ast.getNum());
}
public String apply(Var ast) {
return ast.getVar();
}
public String apply(Add ast) {
return "("+proxy.apply(ast.getLeft())+" + "+proxy.apply(ast.getRight())+")";
}
public String apply(Mul ast) {
return "("+proxy.apply(ast.getLeft())+" * "+proxy.apply(ast.getRight())+")";
}
}

//...
IAST a = new Mul(new Add(new Var("x"), new Num(5)), new Num(-2));
ToStringVisitor().create().apply(a);

The @MultiMethod marker annotation states that all methods in the IASTVisitor interface and all its subclasses should use multiple dispatch. To minimize overhead, this annotation can also be placed just in front of individual methods, then only those methods will use multiple dispatch.

There needs to be a method that takes the supertype of the AST classes, IAST, even though that method should never be called, because there are no objects of that type (unless you create anonymous inner classes, or add another subclass, e.g. Sub, for which there is no overloaded method). We therefore throw an exception there. Then there are the method that handle the concrete subclasses. This time, they all have the same name and overload the general method above that accepts the supertype.

Since we need to create the proxy that wraps around the object with the multi-methods, i.e. around the visitor here, we cannot just create the visitor using the new keyword. Instead, we have a static create() method that creates a new object and creates the proxy around it, and then returns it typed as interface. This is important! It must be returned as an IASTVisitor, not as a ToStringVisitor, because as it turns out, the proxies can only simulate interfaces, not classes. The created proxy is an IASTVisitor, but it is not a ToStringVisitor, even though it wraps around one.

Another very important difference is apparent in the methods for the composites Add and Mul, where recursion is necessary. Using the visitor, we could recurse into the subtrees using ast.getLeft().execute(this), where this was the visitor itself. Since we want the multiple dispatch behavior in the recursion too, we need to use the proxy object for the recursion, not the visitor itself. That means we cannot use this, because this is the visitor, not the proxy. Instead, we use the proxy field, where the create() method stored the created proxy. This is really inelegant and can cause numerous problems: If we accidentally use this, we lose the multiple dispatch; we could also make a mistake and overwrite the proxy field, with null for example. But I haven’t found a better way.

Finally, there is a huge limitation: As stated, proxies can only simulate interfaces, not classes. That means that the classes around which we wrap a proxy can only implement interfaces, but not extend other classes. You can never use the extends keyword! That doesn’t for good code reuse. For example, even though pretty much every visitor needs the proxy field, I cannot hoist it into an abstract class. The following example will cause a ClassCastException:

@MultiMethod
public interface IASTVisitor {
public String apply(IAST ast);
public String apply(Num ast);
public String apply(Var ast);
public String apply(Add ast);
public String apply(Mul ast);
}

abstract class AASTVisitor implements IASTVisitor {
protected IASTVisitor proxy;

public String apply(IAST ast) {
throw new AssertionError("Should never happen.");
}
}

class ToStringVisitor extends AASTVisitor {
public static IASTVisitor create() {
IASTVisitor v = new ToStringVisitor();
v.proxy = MMProxy.newInstance(v);
return v.proxy;
}

public String apply(Num ast) {
return String.valueOf(ast.getNum());
}
public String apply(Var ast) {
return ast.getVar();
}
public String apply(Add ast) {
return "("+proxy.apply(ast.getLeft())+" + "+proxy.apply(ast.getRight())+")";
}
public String apply(Mul ast) {
return "("+proxy.apply(ast.getLeft())+" * "+proxy.apply(ast.getRight())+")";
}
}

That’s what we would ideally want to do, but we can’t. This is really a huge impediment, but right now, without heavier machinery such as a bytecode-rewriting class loader, I can’t find a way around it. Proxies are promising, but not as powerful as I would like them to be.

I’m nonetheless making the source code for Java multi-methods using proxies and annotations available, even though it’s definitely a work in progress.

Share
Posted in xajavac | 2 Comments

Print This Post Print This Post  

The Me Meme

Helping to make some silly internet history here: The me meme.

Me

Take a picture of yourself right now.
Don’t change your clothes, don’t fix your hair…just take a picture. (should be super-easy with Photobooth)
Post that picture with NO editing.
Post these instructions with your picture.

from http://www.flickr.com/photos/raganwald/2909791653/

Share
Posted in Pictures, Uncategorized | Leave a comment

Print This Post Print This Post  

DrJava Survey Results

I just at the latest DrJava survey information today.

An analysis of the data is below, but here are my conclusions:

  • We need to test on Windows Vista. One third of our users now have Vista.
  • We need to test on MacOS Leopard. There are more than twice as many users with 10.5 than with 10.4.
  • Only 67 users ran Java 1.4 — not even one percent. I think we’re ready to abandon 1.4.
  • Most users (73%) are now working with JDK6, update 4+, so our JDK6 fix is in effect.
  • 20 users ran Java 1.7, so we should keep an eye on that.
  • Official releases make up 99% of the reports, so I don’t think it’s necessary to have some kind of mechanism to mask out reports by us DrJava developers. Counting only official releases does not change the other statistics significantly.

Operating system:

  • Linux: 349 (5%)
  • MacOS: 776 (11%)
    • 10.3.x: 9 (0%)
    • 10.4.x: 244 (3%)
    • 10.5.x: 523 (8%)
  • SunOS: 19 (0%)
  • Windows, all: 5695 (83%)
    • Windows 98: 1 (0%)
    • Windows NT: 5 (0%)
    • Windows 2000: 24 (0%)
    • Windows 2003: 15 (0%)
    • Windows XP: 3384 (49%)
    • Windows Vistas: 2266 (33%)

Total: 6839 (100%)

Operating system, just revisions 4592, 4639, 4664, 4668:

  • Linux: 339 (5%)
  • MacOS: 736 (11%)
    • 10.3.x: 9 (0%)
    • 10.4.x: 207 (3%)
    • 10.5.x: 520 (8%)
  • SunOS: 19 (0%)
  • Windows, all: 5670 (83%)
    • Windows 98: 1 (0%)
    • Windows NT: 5 (0%)
    • Windows 2000: 24 (0%)
    • Windows 2003: 15 (0%)
    • Windows XP: 3364 (48%)
    • Windows Vistas: 2261 (33%)

Total: 6764 (100%)

Java:

  • 1.4.x: 67 (1%)
  • 1.5.x: 1045 (15%)
  • 1.6.x, all: 5707 (83%)
    • 1.6.x build <4: 695 (10%)
    • 1.6.x build >=4: 5012 (73%)
  • 1.7.x: 20 (0%)

Total: 6839 (100%)

DrJava revisions:

  • 1: 1 — what’s revision 1? bug in the survey software?
  • 4534: 1
  • 4536: 1
  • 4538: 9
  • 4541: 2
  • 4542: 6
  • 4562: 9
  • 4571: 1
  • 4572: 1
  • 4575: 3
  • 4578: 1
  • 4579: 2
  • 4579: 1
  • 4585: 1
  • 4586: 2
  • 4586: 4
  • 4589: 1
  • 4592: 436 — latest development release
  • 4604: 1
  • 4608: 2
  • 4609: 1
  • 4614: 2
  • 4618: 1
  • 4620: 1
  • 4624: 1
  • 4639: 490 — latest beta release
  • 4647: 6
  • 4664: 1971 — latest stable release (before update)
  • 4666: 1
  • 4668: 3867 — latest stable release (after update)
  • none: 10 — before revision information was reported

Official releases: 6764
Other: 75

I guess there’s one more piece of data that is worth keeping in mind. Out of the 36909 downloads of the official releases that we’ve had, we received 6839 survey results, so about 18% are answering our survey.

Share
Posted in DrJava | Leave a comment

Print This Post Print This Post  

Grad Students Not Assisted During Ike

My letter to the editor regarding the treatment of graduate students during hurricane Ike was printed today in the September 26 issue of The Thresher (@Update: My friend Eileen Meyer wrote an opinion article in the October 3 issue of The Thresher which echoes many of the concerns I addressed in my letter, and with which I wholeheartedly agree: Graduate student concerns omitted from hurricane plan.@) :

To the editor:

As a graduate student not living in university housing, I am upset by the lack of protection I was offered by Rice University against Hurricane Ike and, particularly, about the late notification.

In 2005, when Hurricane Rita approached, all graduate students were offered shelter in McNair Hall. Last week, it was not until Thursday afternoon – a day before predicted landfall and too late to organize an evacuation – that I was informed I could not seek shelter on campus and I should follow my “own hurricane preparedness plan.” Guess what? My preparedness plan included coming to campus. The university stated it could not provide the facilities to protect all graduate students, yet I have been told the overflow shelter in the Student Center was closed due to lack of need.

Hurricane Ike mostly spared Rice University, and most students felt safe in their apartments. However, had the storm been worse, the unannounced reversal of the previous shelter policy and the late announcement could have led to injuries and even loss of life. Considering that many graduate students are internationals and have never experienced a hurricane before, the message of rejection broadcast by the university has certainly caused enough anguish. The one exception has been Dr. Adria Baker and her staff at the Office of International Students and Scholars, who were helpful and reassuring throughout the storm.

I encourage the university to provide shelter to all of its students, regardless of where they live. Should this not be feasible, then Rice must send out a warning well in advance, to make students aware that they may have to rethink their hurricane preparedness plans. I knew that Ike was coming; I just did not know I could not rely on my university if worse comes to worst.

Mathias Ricken
Computer science graduate student

I hope the GSA’s proposal mentioned in this week’s front page article will improve the situation in the future.

Share
Posted in Ramblings | Leave a comment

Print This Post Print This Post