Skip to content

Programming as Art – 50 in 50

Guy Steele and Richard Gabriel’s quixotic wanderings through the history of programming languages is something every programming afficionado should appreciate. I really enjoyed it.

http://blog.jaoo.dk/2008/11/21/art-and-code-obscure-or-beautiful-code/

I’m selling my white macbook.

UPDATE: It’s been sold. Via the blog no less. Thanks, all!

If you’re interested, let me know. I’m looking for about 650 euros.

1.5 year old, mid-2007 model. Looks as good as new because I’ve kept it ‘docked’ virtually all the time, and transported it in a protective bag otherwise. The topcase has been replaced half a year ago (for free due to a small crack), which does mean that this new topcase certainly won’t crack as it has been built after Apple figured out that particular problem.

Extras: – A macvatar topcover sticker which makes your mac unique and easy to find at barcamps and the like. – An extra battery from fastmac, which isn’t quite as good as apple’s original battery, but on the plus side, the apple battery is in excellent state because it hasn’t been used as much. – Protective cover, Tucano brand. – mini-DVI to VGA dongle – mini-DVI to DVI dongle – original box, original CDs.

The system’s stats: – 250GB harddisk (I replaced the old one). – Core2 Duo 2.0Ghz processor – 2GB RAM geheugen – Combodrive (dvd-rom, cd-rw) – no dead pixels. – I’ll clean up the harddrive and leave leopard on it for you. – powerbrick. – 2x USB 2.0 port – 1x FireWire 400 port – optical and standard audio input/output

You can come pick it up at Delft or The Hague. I’ll ship it around europe at cost, too, if you prefer.

Ooh, shiny!

First thing I did when I got off the plane is head down to LJS and buy a MacBook Pro. Turns out that MacBooks aren’t -really- small notebooks; you can’t comfortably type on them in cramped spaces like an airplane seat, so if that is out, then you might as well go all the way and take a 15″ notebook. It’s only half a kilo heavier anyway.

The one disadvantage – that new clickable trackpad is very noisy. Other than that, it’s nice. The keyboard keys are ‘pre-worn’ – they are less grainy than the old macbook keys. They feel about the same as the area of the spacebar that’s worn down a little, which makes me think the keyboard plastic was changed slightly to prevent that wear from showing. Or at least, that’s my theory.

Other than that, nothing much to report. The screen is great, the sound is better, the trackpad is enormous which is nice, and getting used to the full-size clicking was so fast I’m already trying to press the old macbook trackpad through the battery.

Here’s a little video me unboxing it.

Tagged , , ,

Live from San Francisco: Yes We Can!

Reporting from the heart of San Francisco where its a bit like newyear’s, with massive crowds milling about partying on the street.

On the way back from an extremely busy schedule on the Deloitte Fast 50 tour to the hotel, we heard Barack’s historic speech on the radio. Our hotel is near Union Square, basically the center of SF, and the location of the Westin, which hosted the official democrat party of SF.

The first sight when we walked into the crowds was two groups walking towards each other, screaming various Obama slogans, fiercely hugging each other – then moving along. One group consisted of older african american men, the other, white women. Call me cheesy, but the symbolism wasn’t lost on me.

Unfortunately its going to be a very early day tomorrow so I haven’t gone down to some of the other ‘party centrals’ around the city, and I’ll keep this short.

Congratulations, everybody!

Tagged ,

non-null in static languages.

Very technical programming post about having a ‘no value’ concept in statically typed languages. Specifically: the difficulty of representing this in a static typing system.

Quick intro: Right now most static languages either have a concept called ‘null’, which means no value, and every object reference can point to null, such as Java or C#, -or-, there’s no ‘null’, and instead you can use a so-called ‘Maybe’ type to represent an optional value. Haskell does this. From here on out I’m assuming a Java-model static language (Fan and C# are similar enough to count).

Recently there’s been some push to add the possibility of null to the typing system itself, for Java. Stephen Colebourne reports that Fan recently added null to its typing system. However, his post is severely lacking in actual technical detail. The way he writes it, Fan’s support for null is fundamentally incomplete. Unfortunately, most people I talk to about this think adding nullity is a matter of tossing in a suffix-! to indicate definitely-not-null, or for the default is not-null fans (Like Fan, the language), suffix-? to indicate that null is allowed. This isn’t sufficient.

The notion that there are only two different states (allows-null and never-null) is wrong. Think of java generics; List<Number> foo = new ArrayList<Integer>(); is not legal, even though Number foo = new Integer(5); is legal. In generics, we have a convoluted but necessary trifecta of ways to say that your type contains Numbers:

List<Number> t; //allows reading Numbers out and writing Numbers in. List<? extends Number> t; //allows reading Numbers out, but no writing. List<? super Number> t; //allows writing Numbers in, but reading gives you 'Object'.

In the above, the most flexible option (the first, where we can both read and write) is also the least accepting: Only a List<Number> would do; you cannot give either a List<Integer> or a List<Object> legally, whereas in the second and third option, where we restrict ourselves to reading or writing, we can accept more.

We need the same trifecta for nullity:

List<String!> t; //allows reading non-null out. List<String?> t; //allow writing null in. List<String> t; //neither, but more accepting.

In the above example, those three are distinct. Specifically, While you can obviously assign a String! to a String?, as in: String! f = "foo"; String? t = f; //legal, obviously, you can NOT assign a List<String!> to a List<String?>. Here’s why: If it would be legal, you can sneakily add nulls to a non-null list. In the next snippet, we’ll assume for a moment that you could assign List<String!> to a List<String?>

List<String!> t = new ArrayList<String!>(); List<String?> f = t; f.add(null); String! s = t.get(0); //this returns null. WHOOPS!

This is entirely analogous to why a List<Number> does not allow you to assign a List<Integer> to it; you can secretly add a Double to a List<Integer>, which is bad.

So, List<String!> cannot be assigned to a List<String?> and a List<String?> is not assignable to a List<String!>. Okay, but, what do we do if we want to write a method that should accept either form? The need to do that is perfectly legit: If we only read and null check, or we only write non-nulls, or a combo of those two, then we really don’t care about the nullity of the incoming parameter. It would be ridiculous if it was impossible to convey this. And yet I don’t see how you’d do this in Fan.

For example, let’s say we have a method that sets the values for a row in a GUI table. The table has a sparse mode, where a column entry isn’t rendered and its space is provided to the cell to its left. ‘null’ is used to indicate this. However, obviously, lots of tables will be rendered from data out of, say, a database, where this feature just isn’t needed. Worse, if the data is also used elsewhere, it would be perfectly legit for the data to be handed to the code that renders the GUI in List<String!> form. To now pass this to the method that sets the row data, the only option is an unsafe cast and a @SuppressWarnings annotation, or copy the list, just to satisfy the type system. Eeeeugh. You need a way to say that you don’t care about the nullity type of a generics parameter.

The IDEA java editor has support for a @NonNull annotation, but they cop out entirely and don’t support it in generics bounds, which, in my opinion, means its useless.

You also need this trifecta (never-null, definitely-allows-null, either way) for generics bounds; for example:

List<?? super Integer> t; //You can add null to this. List<? super Integer> t; //Can't add null, returns Object? on read. List<?! super Integer> t; //Can't add null, returns Object! on read.

List&lt;?? extends Number&gt; t; //Can't write, returns Number?
List&lt;? extends Number&gt; t; //same as above
List&lt;?! extends Number&gt; t; //Can't write, returns Number!

Etcetera, etcetera. Incidentally, <? extends Foo> and <?? extends Foo> and ‘Foo’ and ‘Foo?’ are the only two in the entire lineup that are synonyms. You can construct a table of assignment compatibilities (can you assign a List<Integer!> to a List<?? extends Number?> – yes, you can), but that process is already complicated due to generics. Adding nullity to it makes it even more complicated.

Consider this a soft vote for the Maybe principle, however, because there’s so much legacy code out there, going that route just isn’t feasible. I’m still in favour of adding type-checked nullity to java, just like I think generics was a great idea even with the complexities introduced. However, make no mistake about it: It’s a complicated issue. And Stephen’s explanatory page about how Fan does it seems like they didn’t get it right.

ADDENDUM: The fourth nullity state.

Java language changes, or for that matter, any programming language change, does not live in a vacuum. There’s old ‘legacy’ code to consider, written before the feature existed. New code should be capable of interoperating with legacy code relatively painlessly, otherwise no project can move on to any of the new features without completely overhauling every last snippet of code they use. Thus, if nullity-in-the-type-system is to be adopted, it needs to interoperate with pre-nullity code. How do we do that?

Let’s look at generics, which is the closest relative. In generics, there’s a concept called a ‘raw’ type. In source, raw types are always easy to find: Its the ones without ANY generics bound, not even the < and > symbols. Java handles raw types by letting everything go (you can assign anything to a raw type, and a raw type can be assigned to anything; List<String> = methodThatReturnsARawList(); is legal). However, anytime you do so, you get a warning that basically says: Okay, if you say so, but the type system doesn’t take any responsibility for the correctness of your code.

A nullity proposal really should work the same way. If I KNOW a method will return a List of things that never contains null, and the list itself is also never null, but it was written before the addition, then, it would be nice if I could just assign the result to a List!<String!> and get a warning which I can then suppress, instead of a flat out refusal, or, also suboptimal, an unsafe cast, which would later have to be removed when the library I’m using gets updated.

Unfortunately, with our three modifiers (definitely not null, definitely allows null, and don’t know), we’re out of luck; unlike generics, the way it used to be written is also valid in the new way (specifically, in the examples above, it meant ‘don’t know’). We need a ‘raw type’ for nullity, which is distinct from the most null-accepting type. Here’s the difference:

a method that takes a List?<?? super Number> – explicitly written just like that, will simply not accept a List<Number!> as input. (after all, the method could add nulls to this list due to the ??). If you try, you get a compiler error. The method itself is allowed to write in nulls, and when reading, gets Objects out, that could be null.

On the other hand, a method that is legacy and has as signature: List<? super Number>, has the same behaviour: Writing nulls into the list is allowed, and when reading, you get Objects back which might be null. However, it isn’t the same as List?<?? super Number> for the same reason generics ‘raw’ types aren’t quite the same as any specific generics bound: In the legacy case, you CAN give a List<Number!> to the legacy method that accepts a List<? super Number> – however, because the type system does not know what the legacy method does, it will give you a nullity warning message that simply states: Okay, if you say so, but I cannot guarantee that this legacy method you’re calling will never write null into your list of Number!s.

So, we now have a 4th nullity state: legacy. That makes 4 states:

Definitely-allows-null, Definitely-not-null, Don’t care, and Legacy. How do we separate these states?

Here’s a modest proposal:

All new files only get parsed as java7 syntax if they start with “source 1.7;”. Then, never-null is the default, ‘*’ is ‘Don’t care’, ‘?’ is ‘definitely allows null’, and its not possible to actually create a legacy type; you can just interoperate with them. Without the source keyword, all your types are legacy-null. ! is no longer used except to promote a generics parameter to non-null. An example for that last one: Let’s say list has a method that returns the value if it isn’t null, and a default if it is, where the default may itself not be null, you could write:

public T! getIfNotNull(int index, T! default) { T x = get(index); return x == null ? default : x; }

There’s a bit of weirdness in the notion that a generics name (such as ‘T’) carries its null-nature with it, whereas a plain type, like, say, ‘String’, doesn’t. Therefore, you need both ? and ! to promote/demote whatever it was to the definitely-not-null or definitely-allows-null variety, with no modifier meaning: Whatever nullity state the type name was bound to.

In other words, if you go: new ArrayList<String!>, then The ‘T’ in the ArrayList class source is bound to ‘String!’, using ‘T!’ would also be ‘String!’, and using ‘T?’ would be ‘String?’. ‘T’ by itself works a bit like ‘don’t care’ – where relevant you must null check when reading, but you must not write in nulls when writing, because you don’t know if null is allowed or not.

Tagged , ,

Which macbook do I buy?

UPDATE: The old chargers should fit into the new macbooks. You CAN replace the memory yourself. This MacWorld article has loads of details.

Just looked at Apple’s new macbooks, and… OMG! Shiny! Want!

The question is; which one? I’ve always considered the blackbook a pointless waste of money, and even the macbook pro was a disdainful extravagance; far too unwieldy and far too expensive.

However, with these models, I’m not so sure. So, which one should I get? It’s a tossup between the cheaper new 13″ and the cheaper new 15″. I doubt I’m the only one with a decision to make, so I’ll list the differences here. + is an advantage for the 13″, – is an advantage for the 15″ and ± is a mixed blessing or simply the same, but not something you might know.

 - cheap 13″ has no keyboard lighting.

 - 13.3″ vs 15″ and 1280×800 v 1440×900 pixels

 - 2.0Ghz instead of 2.4Ghz.

 - 160GB vs. 250GB harddisk (You can buy a laptop 250GB for €60,-)

 - The new 13″ has no firewire anymore. The 15″ still has one.

 - Only the 15″ has an expresscard slot.

 - The 15″ has better speakers.

 ± Both have an invisible sleep light (invisible when it’s off) – like the old iBooks.

 ± Both have a new trackpad with the MacBook Air/iPhone’s multitouch features, and both are made of a new material (polished glass – no really), which is also a button; the entire trackpad physically moves down and clicks mechanically when you press down on it. Because ther’s no dedicated button, they are larger.

 ± Both have a side-to-side access panel on the back taking up almost half the notebook which locks in place with a lever. RAM and HDD are user-serviceable, and the battery is stored in this compartment as well. The iBook had a really bad battery locking system, the macbook’s was a bit better, and the old MBP didn’t have a user-serviceable HDD bay, so much improvement across the board. (I can’t find a note anyplace that the RAM is user-serviceable, but I’d be very surprised if it wasn’t. EDIT: It looks like it really isn’t replaceable, which means you need to shell out 140 euros to upgrade to 4GB, and you need to decide when you buy it. Eugh!)

 ± 15″ now have the same battery life as the 13″ (5 hours for both), probably because the 15″ has a redundant crappy GPU which is used when you aren’t doing anything intensive and running off of battery power.

 ± The 15″ has a better GPU, but, compared to a standard macbook, you won’t notice the difference; its incomparable to what plastic macbooks have.

 ± All new macbook screens are glossy, unfortunately.

 ± You need to buy 2x2GB SO-DIMM (about €50,-) and install it yourself, either way.

 ± Assuming you can claim VAT/BTW back, no real price difference between Europe and the US.

 ± Both are equally thin; slightly tinner than plastic macbooks.

 ± Both use a new display plug so you need to rebuy your VGA/DVI adapters, though this new one is a standard and royalty/patent free. I’m not sure if the charger is the same. The actual charger that ships with it seems different, but I can’t tell from the images if the magsafe plug on the notebooks themselves are different.

 + ex VAT/BTW, you save €505,-

 + The 13.3″ is 450 grams lighter.

 + The 13.3″ is 32.5×22.7 cm – the same size as the old (but thinner). The 15″ is 36.4×24.9 cm; 23% more surface area (and bigger than the old MBP 15″ by 4%)!

 + The 13.3″ powerpack needs 60W, the 15″ needs 85W. Apparently most outlets in trains and planes don’t give more than 80W, so you can either use the machine or charge the battery, but not both, for the 15″. The powerbook is probably larger (I can’t find a definitive answer, but the old MBP charger was larger than the MB’s).

 

I haven’t found any pictures of the bottom; I really disliked the battery locking mechanism on the old iBook, and a few pictures I’ve seen sort of suggest that you slide the battery into the side, instead of into the bottom. I assume the memory and harddisk are still user servicable, which means there needs to be a way to remove the bottom part of the casing.

Netbooks and iPhones/gPhones are making the portability factor somewhat less important; for short trips you no longer need your macbook, and the set of advantages for the 15″ are rather sizable. I’m edging towards shelling out the extra 500 euros for it. How about you?

Tagged ,

Brain-dead experiments: The traffic jam free day.

Here in the Netherlands we routinely rack up 300 to 400 kms of traffic jams during the morning and evening rush. It’s not for lack of train services; the Netherlands are just that densely populated. I live right next to the busiest 15kms of highway, where traffic moves at a snail’s pace about 6 hours a day, every day.

Traffic Jam

So, my interest was piqued when the ANWB (the local Automobile Association) organized a traffic jam free day, today, October 9th. There’s a site (filevrijedag.nl, it’s in dutch) and a million or so spent on TV and newspaper ads. The ads were light on what you were actually supposed to do, though apparently the jest was that you should try to work from home, or take the train, today.

What the hell were they thinking?

I see three possible outcomes here:

A. Everyone assumes that there won’t be any traffic (after all, file vrije dag literally means ‘traffic jam free day’), and takes the car. That’s the whole point of the tragedy of the commons, isn’t it? Asking everyone to take the train should logically result in more cars on the road. Now we’d have even more traffic. Okay, fine, you get the issue of traffic jams in the news, perhaps, but also your crazy incompetence for spending a million bucks to actually worsen the problem.

B. Due to the lack of suggestions, no one does anything, and there’s about as much traffic as usual. Great. No one cares and you’ve proven that you don’t know how to market an idea.

C. Hell freezes over and people actually do take the train. The trains are crazy busy, suggesting to those that tried the train for the first time that its a horrible mode of travel, and none of the experimenters actually get to enjoy the traffic jam free day, other than reading about it later, and probably being called a sucker, the next day, by those who did take the car. Endresult: Those who were thinking of taking the train to work now no longer will due to their bad experience.

traffic jam

Talk about a crazy plan. The results are in, and there was slightly less congestion on the road (‘just’ 250kms worth of traffic jams today). No word yet on how busy the trains were, but it looks like a result somewhere between B and C.

Simpler suggestion: Offer specific home-city to work-city year passes for a symbolic amount to everyone who wants it, staggering the introduction based on a factor that has no relation to the trajectories offered, so that the influx of extra passengers is gradual. With increasing fuel prices, the solution sells itself, really. The railways should probably do this at any rate; by introducing more people to the train system, which is really one of the best of europe*, more people will consider travel by train, even for things other than work/home travel.

*) Tickets are relatively cheap, trains run more often with more coverage than any other european country, and while the trains don’t run as punctually as in germany, its not too bad. However, whining about the sorry state of the rail system is a favourite pastime of the dutch, for some reason.

CSRF, Crumbs, and Cookies.

Simon Willison held a talk showing off a cavalcade of security hacks that have plagued major sites in the recent past, along with the ways to ensure you don’t suffer from the same problems.

One particular attack, or rather, the solution to it, piqued my interest: Cross Site Request Forgery, a.k.a. CSRF, a.k.a. seasurf. Simon suggested the use of a ‘crumb’. Cristiano did some research and figured out that symfony, a PHP framework, uses the same strategy, so it seems to be a popular scheme.

I think its effectively broken.

I’ll explain here why I think this is below the fold. Comments are of course very welcome.

Continue reading ›

Tagged , ,

Four Starters

I’ve been a bit silent on the blogging front until recently, however I’ve picked up the pace again.

My posts will generally be found at FourStarters.com from now on though, unless it’s about very specific programming ramblings.

enjoy!

Dean Kamen’s presentation from TED 2002…

is fun to watch and an excellent example of the ‘naked’ presenting style. A more detailed look over at fourstarters, where I will be blogging all my more in-depth articles from now on: Dean Kamen’s Segway Presentation.