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  

DrJava User Sites and Review

We found more user sites for DrJava and another review, but SourceForge’s shell is apparently down right now, so we cannot update the DrJava website.

Share
Posted in DrJava | Leave a comment

Print This Post Print This Post  

And Another Week Gone

The last week was still spent catching up from Ike. I got lucky, I got power back early, but until pretty much today, the area of Houston that I see on my bike commute to work had been without power. There are still lots of uprooted trees that need to be cleared, and the trash bags are piled high along the streets. Traffic lights seem to be working a bit better, and grocery stores are stocked again.

I was supposed to give a presentation right after Ike, but that day Rice was closed, and not only I was affected, so my talk got pushed back by a week. I finally gave it this Monday, on September 22, in the RAP seminar. It was titled Java Annotations for Invariant Specification and was about Java annotations in general, how I used them to specify and check program invariants, and how much easier that got once I had extended Java to support subtyping for annotations as well. The talk was generally well received, but many of the comments said I should have given a clear definition of what annotations are at the beginning, not interspersed throughout the lecture. I didn’t want to make it so syntax-heavy at the beginning, but I guess I was wrong. I also ran out of time towards the end.

After that, I spent the last two days configuring the JSR 308 prototype compiler on my Mac and my PC at home. It’s not as easy as it sounds, but I finally got it to work, except for the tests. Yesterday I also transferred the changes from xajavac that allow subtyping for annotations into the JSR 308 compiler. But that’s still a work in progress.

Share
Posted in Graduate School, Uncategorized, xajavac | Leave a comment

Print This Post Print This Post  

Presentation: Java Annotations for Invariant Specification

Java Annotations for Invariant Specification

Where: Rice University Computer Science Department, RAP Seminar
When: September 22, 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.

In this talk, I provide a brief introduction to Java annotations and show how limited their use currently is. I then describe a framework for specifying program invariants using Java annotations, and how extending Java to support subtyping for annotations allows programmers to write the invariants in a succinct manner.

Share
Posted in Publications | Leave a comment

Print This Post Print This Post  

Two Weeks, Gone With The Wind

It’s hard to believe that two weeks have truly passed since I last wrote. That’s two weekends, four lectures and one lab I’ve given, a small conference, and one big storm.

On Friday, September 5, I talked about generics and wildcards in my COMP 202 lecture. In the end, I unfortunately had a problem describing lower-bound wildcards. I couldn’t show the contravariant relationship. I corrected that on Monday. I noticed that there’s a big difference between being able to use wildcards and being able to clearly explain them.

Right after the COMP 617 seminar, Walid, Hashim, Jun, Cherif, Angela and I left for Abilene, TX to attend the Middle Earth Programming Languages Seminar. Walid did most of the seven-hour drive in both directions, but I somehow ended up doing most of the navigating, even though I was sitting in the left third-row seat. That sometimes made it hard to hear. Next time, if I navigate, I’ll want to sit closer. I also had some trouble with my allergies and my contacts during the trip — my eyes were getting really dry towards the end of the trip, but all in all the trip was fun. On Friday night, we watched a production of “Moonlight and Magnolias” at Abilene Christian University, and it was simply amazing. That’s one of the reasons why “Gone With The Wind” is in the title of this post.

The trip, and returning just before midnight on Saturday, did take a bit of energy out of me, though, so I had a hard time to get my part of COMP 202 homework #1 graded. Fortunately, the grading went well, thanks to our TA. On Monday, I corrected my mistake about wildcards from Friday, and then started talking about generic lists and algorithms on them.

We also had a lab on Monday so we could help the students with the GUI side of the Hangman game. Our TA was there, but I was a little disappointed about his knowledge of the assignment and Java. Dr. Wong and I plan to get him more involved and ultimately responsible for teaching the labs (as it should be), but this will be difficult.

On Wednesday, we finished talking about lists, and then started using some operations, like getting the first, removing the first, removing the rest, and removing the last x elements of a list to discuss how expensive these operations were. I didn’t quite introduce big-oh notation yet, but we generalized the number of operations to lists of length n. We still had a bit of an argument about which operations should count, so our counts were usually n, 2n, 3n, etc. It was a good discussion. Sadly, the video camera ran out of battery on this day.

On Friday I wanted to formalize this and introduce big-oh notation fully, but on Friday and Monday classes were canceled because of hurricane Ike — the other reason why “Gone With The Wind” is in the title, but more about that later. That made us lose two lectures and got the schedule in a bit of trouble. Today, I moved the exam and homework assignments around a bit. The university ruled that no assignments should be due this week, so I had to move homework #2 to next Monday. But in order to keep lectures and assignments together, I had to move them anyway.

In class today, only half of the students were there; I assume the others evacuated and hope they will be back soon. We finished talking about big-oh notation, and we cleared up why the constant factor in counting didn’t matter.

These entire two week seem like a blur, though, thanks to hurricane Ike. Starting late last Wednesday. we pretty much knew that this would be a close one. I went out to buy some more supplies on Wednesday night already. Some time on Thursday, a notice went out that classes are cancelled on Friday. After work on Thursday and early on Friday, I prepared my apartment for the storm: I taped cardboard covered in plastic bags to my windows again, a ghetto replacement for plywood. I know it couldn’t protect the window, but it should keep shards of glass out and give me a few more minutes to save valuable items. Then came the big wait.

The wind started getting pretty bad around 11 PM on Friday, but I went to bed at 2 AM, around the time “the Eyke” (the eye of Ike, as one newscaster accidentally called it) made landfall just east of Galveston, as a strong category 2 hurricane, just a couple of miles short of category 3. I woke up again at 2:30 AM when my UPSes started beeping. I had lost power. I quickly saved and and copied some files, then shut everything down. It was incredibly dark.

I woke up several times between 4 AM and 7 AM, when either bigger branches hit my apartment walls and windows, or when it sounded like there was hail. The hail probably scared me the most, because one of the meteorologists had said hail might indicate that there is a tornado nearby. A couple of times I was close to grabbing some blankets and moving into my bathroom, but I ended up sleeping through the entire hurricane in my bed.

When it had stopped raining hard in the early afternoon, I went outside and surveyed the damage. My apartment was not damaged, but there were lots of trees turned over. Some had fallen against other apartments or on cars. The fences around my apartment complex were gone. The Braes Bayou was a raging stream. I had expected something like I had seen after hurricane Rita, but this was much, much worse. Rita was nothing against this. And my power was still off. Rita just made it flicker.

Fortunately, I got my power and water back relatively quickly. There were still about 2 million people as of this morning who are without power. Biking or driving through Houston feels strange, because just one street separates apparent normality from chaos without power, water, gas, traffic lights, ATMs — everything we take for granted. It will take weeks before all Houstonians have their utilities restored, and probably months until the scars Ike made have been undone.

Share
Posted in Ramblings, Review, Uncategorized | Leave a comment

Print This Post Print This Post  

Lecture 4 Review

Today we started our discussion of Java generics. I motivated generics by showing Friday’s source code, which used Object... p varargs, and where p[0] had to be an IListFactory and p[1] an IList. Confusing the indices or passing the wrong value would lead to a ClassCastException.

We then looked at how to make a Box<E>, a wrapper that could contain any kind of value, but you had to specify its type. Later we worked out on the board what a generic ILambda would look like, including an Equals example that compared two Integer values. Then we made another Equals<P> that could compare any two values of the same type, so we specified one of the type variables of ILambda<R,P>, but left the other one open.

The last thing I mentioned was that SpecialBox<Integer> was a subclass of Box<Integer> when SpecialBox<E> extends Box<E>, but I’ll have to revisit that again, because the important thing is that Box<Integer> is not a subtype of Box<Object> even though Integer is a subtype of Object.

We also ran into an interesting problem with boxing when we write Equals: p[0] and p[1] are Integers, so p[0]==p[1] does an identity comparison, not an integer equality test, so we had to do p[0].equals(p[1]), but that lead well to the exercise Equals<P>.

I also wasn’t sure about whether primitive types could be used in generics; I correctly said no, but I wasn’t sure, so I’ll reiterate that. I’m pretty happy with this lecture. We’ll see how well my students understood the concepts, because on Friday we’ll talk about upper and lower bounds and wildcards.

Share
Posted in Review | Leave a comment

Print This Post Print This Post  

Lecture 3 Review

Today, we talked about higher-order functions, which also are also called lambdas and commands. Initially, I presented the code for Reverse and Append from last lecture again. Then I added other things that you can do to the mix, such as generating a string representation, adding numbers or dividing them. The latter is important, because division is not commutative. I asked the students what is different between these operations and what is the same.

We came to realize that, depending on whether they use forward or backward accumulation, they all follow the same structure. In forward accumulation, they start with an initial value, perform some kind of operation with the initial value and the first of the list, then recur into the rest, using the result of the operation as initial value for the next level of recursion. In backward accumulation, they start with an initial value that is passed all the way to the end of the list. Then, for the empty list, that initial value is returned, and on the way out of the recursion, for each non-empty list, an operation is performed with the first of the list and the return value of the recursion that just finished, and the result is returned to the next level outward.

I then showed this in a more mathematical way, using a binary function f(x, y), and how forward accumulation yields f(f(f(f(i, l1), l2), l3), l4) for forward accumulation and f(l1, f(l2, f(l3, f(l4, i)))) for backward accumulation.

Unfortunately, I had written out our sample list from left to right, beginning with the empty list, as “empty-1-2-3”, instead of “1, 2, 3”, and that caused me to confuse fold left and fold right.

Another small problem occurred during the discussion of lambdas, the way we implement these different operations. The lecture notes provided code for an Add lambda. In fold left and fold right, the lambdas are binary; however, Add could process an arbitrary number of parameters. It would even add zero or one numbers. I wanted this to be exactly two — I should have previewed the lecture notes better, beyond the point of checking what code is there, but also precisely what it does. Fortunately, the Cons lambda was binary.

After we had discussed lambdas and worked out the code for FoldL and FoldR, we talked about how to do Reverse and Append using fold left and fold right, respectively. We arrived at the interesting result that the operations for both algorithms are the same!

new ILambda() {
public Object apply(Object... params) {
return new NEList(params[0], ((IList)params[1]);
}
}

The two things that differ between Reverse and Append is that they fold in different directions, and that they use different initial values (empy list and the list to append, respectively).

I thought the material was interesting today, and my motivation and the general arc through the lecture was good, but it was marred by the two mistakes, mostly confusing fold left and fold right.

Share
Posted in Review | Leave a comment

Print This Post Print This Post  

Lazy Tool Tips

At our group meeting today, we discussed the delays I had been seeing when Find All results were open and being updated, and I pasted text. A profiling session showed that a large percentage of the time was spent constructing the tool tips for the items in the RegionTreePanel. I don’t quite know why this was never an issue before, perhaps we simply didn’t update them.

The implementation was admittedly rather dumb, though, and created all tool tips at the time an item was inserted into the tree, even if the the tool tip was never displayed. I made the generation of the tool tips lazy by replacing the strings with thunks. Unfortunately, it’s impossible to subclass String in Java as it is final, but fortunately Swing was flexible enough to accept any object as property, as well as allowing me to override both setToolTipText() and getToolTipText().

I think this is actually a valuable addition that could be part of a future version of Swing, so I’d like to make the required changes easily available.

Share
Posted in DrJava | Leave a comment

Print This Post Print This Post  

Lecture 2 Review

Today I finally got the camera set up correctly, I talked some more about the encapsulation issues that came up in the lab, I used index cards for some role-playing for the word list algorithms, and we talked about list algorithms.

I think the role-playing went well, although next time I should perhaps let the students do all of it. This time, I was the “visitor”, so a lot of what was going on was decided by me. On the other hand, this allowed me to mix the role-playing exercise with telling what the algorithms did.

For the list algorithms, we talked about reversing and appending. For appending, I could not find an algorithm that required a helper; my algorithm didn’t need a helper, but it wasn’t tail-recursive. We briefly talked about tail-recursion optimization.

In general, I’m quite happy with today’s lecture, although the video showed that I do have quite a few “uh”s as speech disfluencies, and that I could vary my pitch more. I still couldn’t get into the lab using my ID card, but I’ll check again on my way home.

Lecture 2

Using index cards and role-playing to teach the visitor design pattern in lecture 2.

Share
Posted in Pictures, Review | Leave a comment

Print This Post Print This Post  

Lab 1 Review

In lab 1, we went over the general design of the word list and the body part list. We discussed the need for a state pattern so the objects can change behavior yet remain the same class. Then I let the students recreate the code from the UML diagrams.

Besides some questions that had to do with getting “back into Java programming”, there was an interesting question about encapsulation, whether the visible and invisible states should be implemented as anonymous inner classes. I recommended that EmptyWord and NEWord be nested classes of the concrete word factory, and that AWordState, the visible state and the invisible state be nested inside NEWord, but I hadn’t considered implementing the latter two as anonymous inner classes. When I did that on the projector, it turned out that the visible state was an anonymous inner class defined inside toggleState() of the anonymous inner class for the invisible state. That was interesting, but perhaps made things more complicated.

I didn’t talk much about the algorithms run on word list and body part, so I ended up being a bit worried that not everyone knew what to do. I decided to revisit the encapsulation issue and the algorithms.

As everyone was leaving, there was a question about static as it applies to nested/inner classes. It took a little bit of effort, but I think I was able to explain how static nested classes do not have a reference to the enclosing class’ this, while non-static inner classes do, although I could not come up with a really compelling reason why non-static inner classes cannot have static members, except that static would not convey any advantage, because it could not be called in a static context anyway, but that would not have prevented Sun from just ignoring the static modifier.

I also found out that I’ll have a TA this semester, and I’m already very grateful for that already.

Share
Posted in Review | Leave a comment

Print This Post Print This Post  

“I’m there to learn and not them, morality can go shove it”

This doesn’t fit with anything really except that I’m teaching a college course this semester, but I found this discussion on Ask Metafilter quite interesting: If I want to drop into college courses, should I ask the professor for permission or should I just sit in?.

I’m sure my view has been expressed as a blend of the various responses. If the course cap has been reached, sorry, auditors need to get in line. If it hasn’t, and the presence of people auditing the course has no negative consequences for the registered students, I’d be happy to let them stay. I wouldn’t grade their assignments and exams, though, and I would prefer registered students during office hours and in-class discussion. I wouldn’t stay late to answer an auditor’s question; I would, for a registered student.

If someone were to “sneak into” my course, I’d be feeling a mixture of things: I’d be flattered that someone wants to hear what I have to say, just like with every student. I’d be irritated by the person not asking for my permission or following official protocol. And finally, and this would probably be the overwhelming feeling, I’d be confused why it didn’t occur to the person to ask.

In the end, I’d probably kick a person who “sneaked in” out of the class. Even if I give something away freely and with joy, taking it behind my back is stealing.

Share
Posted in Ramblings, Teaching | Leave a comment

Print This Post Print This Post