Heading to the Cape for the weekend

Except for cutting through Watertown on my bike rides to work and one night where I went to Somerville, I don’t think I’ve been outside Boston, Cambridge and Brookline since May.  I’ve been invited along with a friend to go out to Cape Cod this weekend and I’m looking forward to getting a change of scenery.  I’ve never actually been there so that’ll be something I can cross off my list of things I need to do while I’m a resident of Boston.  Unfortunately it doesn’t look like the weather is going to make it a very good beach weekend but I’m sure we’ll find things to do anyway.  More on the trip later.

My Type System

A brief note on syntax first.  My language is not going to have a Java like syntax but I’m going being the explanations of the language as if it did.  I’m not going to introduce it it’s own syntax, partly because I haven’t nailed down how I want the syntax to look yet, partly to avoid having to explain the syntax while explaining the deeper issues and partly to avoid getting stuck int the quagmire of Wadler’s Law of Langauge Design before I even get to the interesting stuff.  So Java seems like the best starting point since it has a static type system and most people are familiar with it.

As of now you know my language will not contain subtyping.  It will be somewhat familiar though, in that programs will be made up of classes and interfaces.  The first casualty of removing subtyping from the language is that there is no implementation inheritance.  A class can still implement zero or more interfaces but it can’t extend another class.  Two features which will hopefully make up for this are adding a convenient syntax for delegation and loosening the restrictions on what can be done with interfaces.  There are good reasons interfaces can’t contain data fields but there’s actually no good reason they can’t include default implementations of methods.  Scala and the Squeak implementation of Smalltalk contain this feature, and call these sorts of interfaces “traits”.  Delegation allows one to substitute composition for inheritance more conveniently.  I can declare that a member of a class handles a set of methods, rather than providing an implementation for each which calls the corresponding method on that member.

Overall I think removing implementation inheritance isn’t going to be as big a deal as people think.  Much of the confusion when learning OO is about when to use composition and when to use inheritance and this removes that decision.  It also makes the cases where you want multiple inheritance but can’t use it more consistent and convenient.  Additionally it gets rid of the fragile base class problem.  So there’s some win here even aside from the type system.

Since there’s no subtyping, interface names aren’t types strictly speaking, they are only constraints on types.  If I want to declare a method that works on some sort of list I can no longer make the parameter type List.  Interfaces in type declarations now exist exclusively to the right of the “extends” construct in generic parameters, and classes no longer belong there at all.  To declare a method which works on all List you would do the following:

<L extends List<X>> void foo(L list);

An enhancement I will use the lack of subtyping to make to the type system is the introduction of a new keyword “ThisClass”.  An interface’s methods can be declared to take arguments and return of type “ThisClass”.  My langauage won’t have equality built into a base Object type like Java so here’s the interface for things which can be compared for equality:

interface Eq {

boolean equals(ThisClass other);

}

A method to check whether a List contains a certain value would have the following signature:

<E extends Eq, L extends List<E>> boolean contains(L list, E elem);

Note that with subtyping it would be impossible to construct a list that’s guaranteed to be a homogeneous.  That would make an Eq interface with a self type method useless for doing this.  Also note that without adding any features to this type system it’s impossible to create heterogeneous lists.  It’s possible to get that back by being explicit about when it’s ok for a list to be heterogeneous though.  Here’s an interface for things which implement toString:

interface Show {

String toString();

}

If I want to turn all the elements in a List into strings, I don’t care if they are all the same type.  In this case the signature would look like this:

<L extends List> String concatToStrings(L<? extends Show> list);

Another feature that I can add to this type system is that constructors and static methods can be added to interfaces.  The inverse interface to Show is called Read:

interface Read {

static ThisClass fromString(String s);

}

Unlike Java I can use types declared in type parameters to call static methods and constructors polymorphically:

<N extends Number, Read> N readAndAdd3(String s) {

return N.fromString(s) + 3;

}

This turns out to be astoundingly useful, as anyone who has used Haskell can tell you.

So those are the core ideas I’m working with.  Hopefully that made a decent amount of sense.

On technical matters

“The best book on programming for the layman is ‘Alice in Wonderland’; but that’s because it’s the best book on anything for the layman.”

–Alan Perlis

I’ve had a number of people tell me that they don’t understand my blog posts about programming.  Ok, don’t read them.  I won’t be insulted.  If you aren’t a programmer they aren’t for you.  I really don’t want to hear about it everytime I talk to someone who’s not a programmer who reads my blog.  I’ve felt a bit of a need to hold back on the more technical sort of posts due to this, but I’ll be getting back to them soon.

I’ve also had a few people who didn’t understand these posts remark that I must be very smart.  Please, don’t ever, ever, EVER assume someone is smart because you don’t understand what they’re talking about.  It would be much safer and more reasonable to assume they’re a blathering idiot.  Yes, I’m asking you to assume I’m being a blathering idiot when I write those sorts of posts.  I hope that what I’m saying is smart but for the good of society, you should assume it isn’t.  Not only will you be less easily taken in by unsound but fancy sounding arguments, but you’ll be in a better position to understand correct complicated arguments.  A lot of people see something complicated and psych themselves out of even trying to understand it.  If you think you’re too dumb to understand something it becomes a self fulfilling prophecy, so assume you’re smart and the argument seems complicated because the person trying to explain it is too dumb to explain it properly.  Now, like anything this can be taken too far the other way and if you get intellectually arrogant and assume you know everything, you’re just as closed off as if you assume you’re too stupid.

My Room

I’ve done an aweful lot of moving around since starting college and I plan on living here for a year which is the longest I’ve stayed in one place since starting school.  As such I’ve felt a freedom and a pent up need to really get settled in here.  My new room is huge for what I’m paying (well by Boston standards anyway).  It was a big challenging to set up though since there’s no closet.  I’ve finally got it set up to my liking though, so here’s a little tour of the result.

Entering the room, to the right you will find my desk.

dave_room_desk

Continuing around the room is my bookshelf and bureau.

dave_room_bookcases

Followed by the sitting area.

dave_room_windows

Then the music area.

dave_room_guitars

And now from the sitting area you can see the TV and video games and such at the foot of my bed.

dave_room_bed_2

Then, the final wall, with the storage cubes and wall mounted hangers in lieu of a closet.

dave_room_bed1

And that concludes your tour of my room.

Biking to work update

I biked in twice this week.  I think that’s what I’m going to shoot for in the short term, bike in 2 days a week and go for a run on the weekend.  It was cooler today than it has been on previous attempts, which made it much more enjoyable.  I’m looking to forward to biking in in the fall and hopefully I’ll be in better shape by then and manage it more often.

Before my first attempt I did not realize how hot it would be or how sweaty I would get.  I didn’t get as sweaty when I biked to work in Arizona, I guess because of the lack of humidity.  I’m now biking there in a different shirt than I wear during the day and I have a towel and deodorant at my desk.

The route itself is really very pleasant.  The parts in Brighton are somewhat downhill on the way to work and uphill on the way back so I’m learning to save up my energy so my legs don’t fail me right at the end of my commute as I’m heading up hill on Washington St. on the way home.  Still no near collisions, cars have been more reasonable to me than I thought they would be.  One car did cut it a little closer than I would have liked merging into my lane but nothing too major.  I also got honked at and passed today about 30 feet from a red light, which was just funny and stupid.

Health insurance debate

Is there a reason we can’t have an honest political debate in this country? I don’t expect the government to be able to do a perfect job with health care but there are tons of different possible reforms that would improve the situation. Now admittedly, I fall to the left on the political spectrum and am not a big fan of Republicans in general, but I wouldn’t be pissed of if the right wing were trying to push their own plan over what the Democrats are trying to do. The right wing fear mongering over how the government takeover of health care is going to kill all the old people is really disturbing. Watch this video:

The Daily Show With Jon Stewart Mon – Thurs 11p / 10c
Healthraiser
www.thedailyshow.com
Daily Show
Full Episodes
Political Humor Spinal Tap Performance

A friend of mine who had knee surgery was recently denied coverage for her physical therapy. The fact that Obama is being asked whether the government is going to call up all the senior citizens and ask them how they want to die is nothing, when we could be talking about the best way to fix the system is incredibly frustrating. The disingenuous people claiming there will be a government bureaucrat between you and your doctor and that care will be rationed seem to be conveniently forgetting that there is already an insurance bureaucrat between you and your doctor with a profit motive not to pay for your treatment. There are real people’s lives that are ruined by being denied coverage. Can we take this seriously please?

Fun stuff happening recently

I never got around to blogging about this but last weekend my friend Janet invited me to got see an orchestra play in Olmsted Park.  A friend of hers wrote some of the music that was played there.   I had never been there before but it’s a beautiful park.  We had a little trouble finding the performing area but there was nice weather and good scenery and good company so not to big a deal to wander around for a little while.  We eventually found our way there and enjoyed some great music.

I went out to celebrate my new neighbor, Leander’s birthday yesterday.  We started off a the Museum of Science, caught the planetarium show and then wandered around the museum for a bit.  Then we walked to the Boston Beer Works by North Station and got dinner, followed by dessert at a coffee shop in the North End.  Then to close out the night, I finally got to make use of my board game collection and we had a game of RoboRally.  Accoring to Kristy it’s “shoots and ladders for programmers,” an amusing and accurate description.  It was a very full and fun day.