The Hyperpessimist

The grandest failure.

Seven Languages, Week 7: Haskell

So, this evening I finished the homework of Haskell day 3. Immediately after that I went to grab a beer as a small token of celebration for finishing “Seven Languages in Seven Weeks” successfully (I’d say).

What about Haskell? Well, I like it. Programming in a functional way in Haskell is actually quite fun and straightforward. As for functional languages Haskell is at the top and actually quite what I’d wish Scala to be. From the languages I kinda sorta “speak” Haskell compares best to OCaml and in a number of things favorably.

In specific, I really like the type classes and found working with them extremely pleasant. Also, in some cases the Haskell syntax is less messy, especially when defining types, I never liked the alpha, beta, etc stuff that OCaml definitons include. Other things I liked less, like the indentation. Not exectly because of the indentation itself, but the ugly results:

1
2
3
exploreMaze p = let complete = completePaths p
                    found = complete /= []
                    in if found then (head complete) else exploreMaze (p >>= extendPath)

So, I get punished for giving long names. Possibly this can be circumvented, but as I have quite a lot of stuff to do than learning Haskell properly, let me complain about this.

Another thing was that right in the first homework I ran into problems with the monomorphism restriction, so I had to add a line to the top of my code which disabled the restriction. I don’t really know the exact reasons why it happened but I fear the explanation is not simple. But that leads me to some things I really liked about Haskell.

For once, the REPL of GHC, GHCi is pretty awesome. I’d say it is by far the best from the other ones in the book. It supports readline directly, it has tab-completion for files, starts quite fast and works (almost) like if I were writing code in a file (well, I have to use let to set values, but this is shorter than Prologs assert). The error messages of GHC are usually really cool and sometimes even offer the proper name of the function if I mistype function names. Awesome.

There is a number of handy things that I liked, like the . compose operator and even more the $ application operator. Not entirely surprising since my favorite operator is the thrush-operator -> (sometimes called thread-first operator, common in Clojure), so yeah, I like control-flow-bending operators.

Talking about control-flow, let’s talk about monads. Haha, of course, how can one write a discussion of Haskell without monads? Well, I’ll be smart and won’t write a tutorial on monads just yet, but if you haven’t seen monads before, like me, and feared to learn about them because they were deemed “complicated” rest assured they are not. After I saw my first monad, I was more like “that’s all there is to it?”. For once, the “Seven Languages in Seven Weeks” description was quite good and I picked them up quickly.

The book introduces for the Maybe monad which is quite cool, since it solves exactly a problem that I’ll run into in my bachelor thesis in OCaml soon: propagating faulty state without having to pass the fact that something failed everywhere. After I saw the Maybe monad, I thought it would be cool to have a version of it that can not only pass around the fact that something failed but also what exactly. Turns out, such a thing exists and is called the Error monad. So yeah, the trip to Haskell-land has paid off already.

Generally, I quite liked Haskell and even learned some things on the way. If I were to judge, I’d say that the Haskell chapter has learned me more than the other chapters from the book, which is maybe not that surprising since the topics discussed in the Haskell chapter were the most in-depth ones.

Seven Languages, Week 6: Clojure

We’re near the end and this week (cough, the last 2 days) I did CLojure. I used Clojure some years before, I even got “Programming Clojure” standing in my shelf, although I with it were “The Joy of Clojure” instead. Nevermind.

Clojure is powerful. Actually, Clojure is immensely powerful and super-concise. My experience is whenever I ask for code review on the Clojure IRC channel or mailing list, they reduce my code to 1/3 of it’s length. Form the book, it was obvious that Bruce Tate liked Clojure as well, unlike e.g. Scala, so in the Clojure chapter he also described what was not covered in depth.

Personally, I could have gone without defrecord and defprotocol, as the introduction was kinda weak and did not make much sense. The usage of protocols felt incredibly forced and the homework where one should design and implement a protocol was difficult, because I had no idea what to implement at all. So I made a protocol for ranting.

But this time, the homework was at least not that boring, in general. For example, one was to implement unless, so I actually went the extra mile and made it work just like if which means that it can take an optional else clause but does not have to.

1
2
3
(defmacro unless
  ([test iffalse] (list 'unless test iffalse 'nil))
  ([test iffalse iftrue] (list 'if (list 'not test) iffalse iftrue)))

So the first version expands into a recursive macro call with the second argument set to nil, in a similar way like if works. Coming from Scheme and syntax-rules I think this looks kinda ugly to construct these things with literal calls to list and manual quoting. Well, I guess it is simpler and simplicity is a big proint for Clojure. And furthermore I can keep my syntax-rules if I like.

Day 3 had an interesting/tricky task, the Sleeping barber problem, where one had to implement a concurrent solution using the Clojure primitives. Turned out to be tricky, because I’m not really sold on agents. Implementing this problem with Actors would have been easy/trivial, just send some messages around. With agent, you do it the other way ‘round: instead of sending messages to functions, you send functions to threadsafe values.

Changing my thinking took quite forever, but the first step to get to a solution was to define an agent. The first breakthrough was that barber was an agent of the number of people he serviced. So you could implement a function that pauses for 20ms (“working”) and then increments the counter. So, maybe it would make sense to make the number of free waiting spots an actor too? I did this and implemented a function to try to add a customer to the waiting queue (try-occupy) and turn him down if it is full already. Freeing a seat is easy (when the barber finishes a customer and gets a new one), just increment the number of free seats in free-seat.

Now that you have a function to free-seat, you need to tell the barber to free one seat before going off to work on the customer in cut-hair.

If you run it on this point, nothing happens, because no customers arrive. This kinda ticked me off because now we’d need to create a thread that tries to occupy a seat every 10 to 30ms and this did not seem elegant. Yet at the end, I did not see a better solution so I helped myself to a function that sleeps and recursively creates new customers, client-arrive.

When you try starting it at this point, you realize your waiting queue is full with 3 customers but the barber does nothing. So yet again, we need a function that moves people from the waiting queue to the barbers chair, move-to-chair.

Then just start these two threads, wait for 10 seconds and check the value of barber. For me, in the initial run on Clojure 1.4.0 it was around 250 clients serviced which was rather poor, with Clojure 1.2.1 it was three-hundred-something which was better but still poor. I considered running it on a faster computer and it dropped to 122 customers which was really awful.

After some head-scratching I tried putting the move-to-chair thread to sleep for 1ms, to prevent it from gobbling up all computation. Lo and behold, 480-490 customers out of a theoretical maximum of 500, I’d say this is pretty decent.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
; barber <serviced>
(def barber (agent 0))
; seats <free>
(def free-seats (atom 3))

(defn any-seat-occupied? []
  (< @free-seats 3))

(defn free-seat [free]
  (inc free))

(defn try-occupy [free]
  (if (= free 0) 0 (dec free)))

(defn cut-hair [serviced]
  (if (any-seat-occupied?)
    (do
      (swap! free-seats free-seat)
      (Thread/sleep 20)
      (inc serviced))
    serviced))

(def continue-running (atom true))

(defn move-to-chair []
  (loop []
    (if @continue-running
      (do
        ; prevent this thread from gobbling up all processing power
        (Thread/sleep 1)
        (send barber cut-hair)
        (recur)))))

(defn client-arrive []
  (loop []
    (if @continue-running
      (let [time (+ 10 (rand-int 20))]
        (Thread/sleep time)
        (swap! free-seats try-occupy)
        (recur)))))

(future (move-to-chair))
(future (client-arrive))
(Thread/sleep (* 10 1000))
(println @barber)
(reset! continue-running false)
(shutdown-agents)

To my great surprise, I had absolutely no correctness problems at the first try. Maybe it paid off that I was drawing the things on a piece of paper to compose my thoughts?

I was curious how other people solved this and to some point I was actually quite disappointed by some solutions. Ben’s takes the cake, because he writes Clojure with Java syntax which makes my eyes bleed (actually, he writes Io like this too) and his solution is verbose and awkward. This awkward-syntax thing is also in Bash-Shell’s code (seriously, camelCase in Lisp‽) but the actual solution behind it it is similar to mine. Devnoo again is awfully Java-istic. But there is hope, Yannick’s solution seems to me quite idiomatic and Frédéric’s solution is so immensely similar to mine, I was actually wondering. Actually, after I wrote mine, I took some inspiration from him, like the fact that free-sets should better be an atom and not an agent as well as to use future instead of the (.start (Thread. function)) clutch I had before.

Seven Languages, Week 5: Erlang

So, Erlang this week. Well, I have to admit that I understand why people think Erlang is wonky. It seems like they took the odd syntax of a logical programming language (hint, hint, hint) and made a general purpose language. Oh wait, they did.

I have to admit that I kinda liked the concepts, the pattern matching on tuples, the restarting of processes. This all feels simple and powerful. And to my surprise the BEAM VM does not use that much memory as I was expecting. Things were instataneous on my old trusty ThinkPad. Much appreciated.

Due to tail call optimization, loops with pattern matching are actually pretty elegant, you just call the function again and that’s it. The syntax for transmitting messages is straightforward, no wonder Scala was inspired by this.

But there’s a number of strange things: the exact syntax of delimiters is driving me up the wall. Like in Prolog you can define a predicate with pattern matching, but in Erlang definitions of a function must be consecutive and be separated by semicolons and finished with a full stop. This example:

1
2
3
4
5
words("") -> 0;
words([32]) -> 0;
words([_]) -> 1;
words([32|Tail]) -> 1 + words(Tail);
words([_|Tail]) -> words(Tail).

Every time I had syntax errors in Erlang, these were caused because the interpunctuation was wrong. Because it is non-intuitive and random. Oh well. From the example, you can see another wonky thing: when you put numbers in a list, Erlang sees this as a string. So this example calculates the number of words in a string separated by spaces (ASCII 32). It is a kinda odd way.

The book chapter on Erlang was quite ok I’d say, just day 3 homework was so frustrating that I left it out. Let me tell you how the tasks looked like:

  • Implement a task that monitors another and restarts it if it dies
  • Implement a task that monitors itself and restarts itself if it dies
  • Implement a monitor that monitors the monitor and restarts itself if it dies

Well great, basically the same thing three times, so I just left out this homework. The remaining tasks were surprisingly fun.

Back to Erlang: I can’t see myself using Erlang because of these syntactic oddities, but I liked the concepts. Maybe something like Lisp Flavored Erlang or perhaps better Elixir would fit my needs better. Actually the latter seems to be in the spirit of CoffeeScript to Erlang, so I’d probably try this first.

Seven Languages, Week 4: Scala

After the slowness caused by Prolog, I managed to finish Scala almost on time this week. I’ve used Scala before, to build an Android widget and a compiler for Caml Light, but I can’t really say I like the language too much.

On the one hand, it sounds like a dream language: a powerful functional programming language with strong support for functional programming while retaining OOP support. That sounds pragmatic. Unfortunately, it isn’t: the type system in more complex than in languages like OCaml and the syntax is rather unpleasant for me.

What’s funny is how the “Seven Languages in Seven Weeks”-book basically picks out the parts of the language that a friend of mine considers warts. First, the possibility of adding strings together via +, second the Actors which seem to be outdated due to Akka and third, XML literals are an awful idea. Kind of “good on paper, bad in reality” awful, like checked exceptions in Java.

On the other hand, I kinda liked the homework, the size of it was fitting and I had fun exchanging strategies to solve it with a friend. For the censor homework I decided to use a simple string replace but add captitalized variants and read the censor words from a JSON file, whereas my friend used a more efficient solution with regular expressions and a custom text format. Both are valid and it was fun to compare.

Also: the new profile pages on GitHub with the contribution graph are fascinating and awful, because they add a certain amount of game to it (gamification): I have to contribute, otherwise my current streak breaks. And the longer the streak, the more geek-cred. Or something like that. Unfortunately, it also causes more useless commits to prevent streak-breaking.

After all, if I were looking for a JVM language to use on Android phones, Scala would probably be it.

Seven Languages, Week 3: Prolog

Wow, now this was a long week. Actually, it was more like a month with Christmas and the lack of motivation, to get me through this chapter.

Why did it take so long? I’ve never programmed in a logical programming language but I have to admit, not being too thrilled about Prolog. Logic programming is kind of a one-trick pony for me and while it is fun to let it solve a sudoku for you, it is not being efficient at that but rather dumb. If you want to optimize a Prolog program you have to use sophisticated operations at which point it does not really seem straightforward and requires more intricate knowledge of Prolog. Also, debugging is awful, you just get ‘no’ as response. Supposedly one can use trace to debug, but I haven’t investigated further.

While I suppose Prolog was the most annoying part, the reward level was on par with Io. Once my stupid solution worked, I was jumping around happily. As an example, day 2 has the homework to implement a sorting algorithm in Prolog, here’s my take on Mergesort:

The hardest part by far was the splitlist function, as I really struggled how to express it properly. In the end, I needed a friend to help me and even now I am not completely sure what exactly was wrong with my previous, non-working solutions. The rest of the functions were rather easy.

During this “week” me and my friends had a number of gripes with Prolog: I personally don’t like the syntax very much, especially that defining new facts in the REPL requires assert and couldn’t be done with fact(a, b)! or something similar. Another problem is that predicates are not first-order, that is, you can’t parametrize things nearly as nice as in about any other language by just passing “functions” as arguments.

Fun fact: the Prolog stats are completely invalid, since Prolog and Perl share the file extension .pl (also in Vim), therefore four of the five most forked repositories in the stats are not even Prolog. Popularity wise, Prolog is way lower in reality than #21 on GitHub would suggest.

In the end, I was quite disappointed in the Seven Languages-book chapter on Prolog, I had some trouble expressing things in Prolog afterwards and, well, the solution to Sudoku presented there seemed kinda lame: “well, let’s get these predefined predicates from GProlog and put them together”. Yeah, it is understandable, but the GProlog predicates do all the magic.

Will I be continuing Prolog? Probably not except for the occasionall dabble. It seems to me too limited for real usage and I get annoyed too fast with it. Logical programming on the other hand might be worth investigating further, maybe with Oz or Mercury or even Clojure’s core.logic.

A Curse of Second Names

In case you are planning to become a parent and think about giving your child one or more second names, let me give you an advice: don’t.

I got a second name and I’d love to be rid of it, if it wasn’t so complicated. First off, usually you never actually use your second name. I don’t know anyone of my friend who has a second name that would be used popularly. We all call them by their first name, even if there are conflicts because every second person in Germany is called “Michael” or “Andreas”.

In polish tradition you get a second name at baptizm. So I have a second name that hardly anz of my friends know, none can pronounce it properly and it was given to me by an institution I don’t care about.

The only places that care about your second name are officials. They force you to specify all your names even if you don’t use them at all and whine around if you leave names out that you never use. Worse still, they even manage to fuck them up. My sister used to have her name typed incorrectly in her passport (!) and my bank still thinks that my second name is devoid of any vocals.

And worse still, if your child decides to go to a foreign country, he or she does not only have one name that get’s misspelled and they have to spell it out, but two of them. Awesome.

Do your child a favor and spare him or her from this.

The Awful SmartTV Experience

New year, new rant. Lately I had the “pleasure” of using a Smart TV, namely the Samsung UE46ES8000. My grandfather bought this thing and was using it for watching TV and BluRay discs. For this task, the device is pretty fine, looks nice and shiny and has surprisingly good quality when playing DVDs via his BluRay player.

Now there’s a but: it has way to many completely useless features, being a “Smart TV”. So it has its normal remote. The Samsung BluRay player has its own remote which can control the TV via HDMI CEC which works pretty well, but now you got two remotes. Next you have a fancy little remote which features a touchpad which works similar to the Macbook touchpads. I suppose it uses Bluetooth and can control other devices by a fourth device that translates this fancy-remote signal to infrared.

Needless to say, my grandfather can’t use any of these things, except for the ordinary remote, because that’s the only thing he understands. And I can only use the remote because it’s the only thing that works.

Let me add some structure to explain you, why you should not get a Smart TV but a DumbTV. I’ll explain in the end what I mean by DumbTV.

1. Input Methods suck

I tried using the touchpad remote. It looks really nice and shiny, but the first time I used it, I didn’t know how to even click. After checking the manual, turns out it works like a Macbook touchpad. Fair enough. It also features a microphone, so you can just speak your commands. Sounds awesome, right?

I respect new input methods, for example the Bluetooth PS3 remote is probably my favorite remote ever and we shouldn’t ever have to go back to anything less. But the Samsung touchpad remote is awful. It is a remote, so I fully expect it to work from a couch that is some 5 meters away from the screen. You see where this is going because it doesn’t work. The remote goes so some energy saving sleep state really fast, so unless you use it all the time, it turns off and when you turn it on, it transmits all motions at once in a burst.

You get a shitload of incorrect outputs. It’s like an application that froze and upon thawing it executes all the actions you clicked while the application was frozen.

My grandfather also likes new and shiny things so he also bought a wireless mouse and keyboard, because the “experts” who installed this TV told him it’s a good idea. Guess what, it’s not.

When you connect the keyboard, it asks you for the layout and then proceeds to tell you that “the keyboard might not work in all applications”. Where “not all” translates to “none” because I haven’t yet found an application that works correctly. Searching in the YouTube app? Well, up and down works because it is presumably mapped to the keys on the remote. Media keys? No, sir! But ok that was a bit much to expect. In the browser it works, but the mouse that works in the main menu does not work in the browser.

I kid you not.

The browser did not work with the mouse.

On a related note, the 2.4 GHz wireless mouse input is jagged and laggy. In all fairness the box says “up to 5m” and if I use the mouse directly in front of the TV it works. Just not on the couch which is 3m away.

2. The UI is awful

The TV boots into TV mode from where you have to boot into Smart TV mode. Kinda like booting Windows 3.1 by typing “win” in the prompt. Smart TV takes some 20-30 seconds to load which is two or three times as long as the TV mode, it then opens into a menu where you can start apps.

The menu is a mixture between shiny UI and icons with a area where I saw a flashing advertisement to install some app. Flashing advertisements in my TV? Please shoot me.

It looks style-wise kind of like Android with the Play Store replaced by Samsung Apps, so it is kinda like Samsungs Android TouchWiz UI without Play Store. I tried to open apps to be greeted by a message saying I need to update them first. sigh Okay. There’s no real UI for downloading, so you only see a throbber in the upper right corner saying “updating”. No indication if it is downloading, installing or even stalled. Nothing. And you can’t cancel. Only by turning off the TV. Which is what I did at least three times because updating the browser took 10 minutes.

Furthermore, everytime you move the selection, you get a selection sound. Well, if the touchpad remote gets unstuck and sends many operations at once, the selection sounds starts, then the next one starts stopping the previous one, then another starts and you get a cacophony of sounds. It’s 2013 now, I shouldn’t need to facepalm on this.

If people complain the Android UI is wonky, they clearly haven’t used Samsung SmartTV.

I’m 100% sure my mom won’t be able to use this, don’t even think about my grandpa. Hell, even I don’t really want to cope with it.

3. The connection is flaky

It is a SmartTV so it is just smart to connect to the internets. Admittedly. The hardware supports 802.11bgn, no complaints there. What it does not support is effing holding this damn connection. Every couple of boot-ups, it tells me that there is no internet connection.

My (Samsung) smartphone displays four bars out of five in the same WiFi and the connection to the internet is fine. None of the three other smartphones nor the three other laptops in the same WiFi have any kind of problems.

Well, then it says, “alright, I can connect to the router but still not to the internet”. Which is a lie. If you repeat the connection assistant for a couple of times and reboot the TV once or twice, it detects the internet connection. Magic.

What a farce.

4. The apps, oh, the apps!

One could argue the whole point of having a Smart TV is to install and use apps on the device. But for apps, you got to have an ecosystem. The Samsung SmartTV hasn’t. So the apps there have close to no quality at all.

I tested a number of apps. The app of the national television (TVP VOD) either freezes in the menu, does not display the menu contents or just starts up forever so I have to reboot the TV.

The other streaming app I tried has decent selection but it is too retarded to buffer properly, so it just buffers every 3 seconds, worse than YouTube some six years ago. Fun fact: the ads it displays don’t have any buffering issues. And after it stops playback for the 20th time, it decides to give up and show an error message. After that, it seems to buffer in the background and next time it can play the video kinda okay. I suspect this application was indeed written by monkeys punching on typewriters.

And it’s not the bandwidth. I can play YouTube in 1080p just fine, so some SD content shouldn’t be an issue. At all.

Talking about YouTube. There’s an app for that. It boots up for like 60 seconds and the keyboard does not work. So after you type in your search query using direction keys on the remote (haha) it searches fine and displays the video. With some buffering issues but at this point I am fully willing to let it slide. I’d even argue that this thing is so far the best app on the TV. Or the least bad.

And of course there is the usual crapware, with Facebook and Twitter. How many of you think my grandfather who is 80 now, will use Facebook? At least I got around to explain him what Facebook is. At least you can uninstall some of these. Not all, mind you.

5. The localization

Alright, polish is not the most common language, but the one my grandpa is most familiar with. So he set the TV’s language to polish. When he asked me to set up the TV, I was quite tempted to set it to english because the translation should be less botched. Korean should be fine as well. But the polish one is awful in a funny way.

To give you english native-speakers some insights: usually localizations are either incomplete with english paragraphs or menus mixed in or use strange words or grammer. Sometimes the special characters are wrong. This one is neither:

It shortens every word that is longer than 5 letters. Even where there would be enough room for the whole words. Sometimes it is hard to even understand what the menu item is supposed to mean. I felt like crying, navigating the menus helplessly.

DumbTV

The worst thing, I can wholly understand how this thing came to be. The idea sounds good on paper, using a TV to do tasks that are usually done using a computer. Problem: computers are better at this, because the software on computers is written by software programmers who know their stuff, not by hardware companies that invest into their own platform.

I get it why the apps are bad: because nobody bothers to write them properly. Things have to be shipped and if they are half-working that’s good enough. The UI is bad because nobody bothered to make it good. This is surprisingly similar to “smartphones” before Apple presented a device with really polished UI - the iPhone, in 2007.

So what if you’d like a Smart TV solution? Get a device from a vendor that cares about the software like the Apple TV or even Google TV.

The DumbTV thing is what I’d want to have: a TV that does one thing, and one thing well. It should display video content, like a monitor. Without any fancy bullshit. If I want to have “smart” content, I’d stream it from my PC or phone. Maybe using something like WiDi or Miracast.

A Curious Kind of Review

Well, most hardware reviews go about devices that are brand new and yet to be released or recently released. I’m going to do the other way round, a review to a device being decommissioned.

So this is going to be about the Google Nexus One aka HTC Passion.

The Google Nexus One is a smartphone from the generation that presented Android as a viable system. This generation includes other devices like the twin model HTC Desire (a huge seller in Germany, you can still see many people using it) and the Motorola Droid/Milestone and shipped with Android 2.0 or 2.1.

The Nexus One got kind-of a false start in Germany, since it was only sold in stores for two months by Vodafone untill they pulled it from the shelves (actually, it was not on shelves, you had to ask for it). And while there was no branding, Vodafone still managed to flash their own firmware to it, meaning that the updates came form Vodafone and not the Google, effectively meaning that you had to wait a lot for updates.

But let’s talk about the device first. The Nexus one has a 3-point-something screen and as such can be used rather well with one hand. The singlecore 1 GHz Snapdragon is maybe not the fastest, but still fast enough for most day-to-day tasks and still, two years later specwise faster than entry-level Android devices. The Nexus One has two variants, one with an AMOLED screen, the one I own, and a later one with LCD which was produced because of AMOLED shortage. The AMOLED screen is rather okay, although you can see the PenTile artifacts. But still, better this than an overall lower resolution. The brightness is fine if you never leave home or live in places without sunlight, although if you wait long enough the autmatic brightness regulation kicks in and cranks up the brightness a bit.

The Nexus One was available in many colors: Black screen, and a pinkish brown bezel :-) Being a HTC product, it feels sturdy and according to my involuntary drop tests it is. I dropped it once from about 2m on a tile floor which split the device into three pieces… the back cover, the (removable) battery and the remaining device. After reassembly, the thing booted without a hitch. All the droptests caused a number of scratches in the body, though the screen does not have any, despite not being Gorilla glass or whatever. Also, my Nexus survived flooding in my pocket, because I was travelling during a japanese typhoon and it drowned. It crashed, displayed a red screen and after spending three days in a bag of rice it was revived, just like Jesus. Except for the vibration which is less intensive now, the device works just fine.

But the thing does have it’s hardware faults: the digitizer sometimes goes haywire and detects touch events with random offsets (fixable by turning off the screen, waiting, turning on the screen). The second issue is that the power button wears out and breaks if you press it often. Which is funny, because hardware issue #1 is fixable by pressing the power button which causes hardware issue #2. Also, the built-in amount of flash memory, 256 MB is ridiculous and can be only partly fixed by moving apps to SD since this only moves part of the app.

So, we made clear that this thing takes a lot of abuse. Let’s check the software. Mine came with Android 2.1-update1 which means “Android 2.1 with emulated multitouch” but was eventually updated to Android 2.2 and then 2.3.5. At this point, Google abandoned updates to the Nexus One, and Android 4.0 was only released for the subsequent Nexus S. So my “Nexus experience” was rather disappointing. At some point, I unlocked the bootloader (which was indeed easy) and flashed CyanogenMod.

One advantage of CyanogenMod is that it supports unlocking the screen via trackball, so I don’t have to use the flaky power button anymore.

Other surprising issues with the Nexus One: the battery is really good, I haven’t seen any (subjective) decrease in battery runtime at all. If anything, the runtime has increased with Android 2.3 which has some power usage optimizations.

Overall, I kinda think this was one of the best devices I ever owned. It’ll stay in the family :-)

Seven Languages, Week 2: Io

The second week in the “Seven Languages in Seven Weeks” book explores a more unusual terrain, namely Io. Io is, for lack of a better word different and while I had some things to complain about the minimal docs I have to admit that I kinda love the language. Well, probably more as a plaything because it is missing a bit to much for everyday use.

Io is object-oriented to a point that I have never seen in other languages before to a point where things like method calls do not exist and the recipient object only sees a message which he can parse however he wants. In other words: the parameters of a method call do not have to be evaluated necessarily, which means you can implement nifty things like your own control flow statements.

One thing that I really like about Io is the syntax. It is simple, regular and reminds me a lot of Lisp (which is why I indent similar to Lisp). I think it is a good deal preferable to what JavaScript provides and while at this, it is vastly more powerful.

I’m not completely sold on the syntactic extension abilities (similar to Scala 2.8 and probably Ruby), each syntactic extension seems like a hack by combining a lot of orthogonal hooks together to just work which seems kind of “by accident”, as every possible syntactic extension needs to be thought of before to add the hooks to the Io implementation. Overall, this is the least impressive part, especially as defining operators does not work in the current parsing unit, so you can’t define a new syntax in a file and immediately use it. Kinda sad and the workaround (execute your extended code with doString/doFile/doRelativeFile) looks ugly.

I’ll give you an example which is pretty awesome yet demonstrates one of my complaints about the syntactic extension facilities of Io:

So we define a method squareBrackets that creates a list l, evaluates all of its arguments (1 is 1, 3+1 is 4) and appends the results to l which gets returned. squareBrackers is called when Io sees [], so this thing works. Really nice and cool but what if you want to use some other character like % or Å. There is no Åbrackets. What if you want the dividers to be something different than , maybe ; as in OCaml? You are out of luck because now you need to edit Io and add these hooks to the language. This is why I am only partly impressed with the “macros” if you like to call it this.

At the end of this week, a short critique of the Seven Languages-book: while I do like the topics that are presented and the ideas that get presented, the code is sometimes quite awful. Extending this code is often painful and the result looks quite ugly (if it is even possible). I got stuck in the XML formatter task, extending it to take an optional Map as first argument, first because of the afore-mentioned parser weirdness which makes using the newly introduced syntax tedious and second because the code uses writeln which makes it impossible to evaluate an argument without printing it immediately.

As for a random observation, I use vim to write the code and while the Ruby plugin was pretty awesome, the Io plugin I used was less so. We fought about our ideas of indentation and it gave up when I defined my own syntax (this is not entirely surprising of course).

Another funny observation is that Io’s killer app is the “Seven Languages in Seven Weeks” book. If you check out GitHub’s stats on Io you’ll notice that many repositories recently created or modified are repositories for hosting code of the book, just like I do :-)

Well, that’s it with Io. Overall I liked this week quite a bit more than previous week because it was way more of a challenge. Next week is Prolog, which will be a good deal more of a challenge. Oh well.

Laser Etching a ThinkPad T41

I just love epic unique things and as such, ThinkPads kinda qualify so I ended up with a collection of ThinkPads, they started to pile up in my room. Let’s do something with them!

The device itself, or how to find a victim

Recently, I revived my old T41 but this device is 8 years old and slow. So I needed something to fancy it up and after I saw that the Chaos Computer Club Munich got a laser cutter, I immediately knew what I wanted to do:

Etch some things into the cover!

Apparently, I am not the first one with this idea. So we got this 40W CO₂ laser and the fine folks at RaumZeitLabor already tested it with ThinkPads. Beware: The R-Series has a different shell material which apparently produces Hydrogen cyanide. But the X40 was apparently fine and as far as I know the T and X series use the same materials, so my T41 should be safe (as in: it won’t kill us on the spot).

The preparation, or where to steal the content

I started by gathering logos of (mostly) Free Software projects that I like and that have a pretty logo, in SVG format. Wikipedia is immensely helpful, because the only Clojure did not have a proper SVG. For other logos, I searched the web and found the logo of the Mozilla Foundation, The Pirate Bay and Octocat of GitHub fame. For the etching, you have to keep in mind that the laser only supports black and white (at least ours, maybe other more sophisticated support dithering to display shades of grey). So crach open Inkscape and edit the logos at will. Everything white will be left un-etched, everything black will be etched, so you’ll have a kind-of negative of your logo.

The process, or how to not die

After creating the SVGs, we needed to feed them into the engraving software. This strange thing emulates a printer driver, so you can export from any application that supports printing, like Inkscape. The only other “sensible” format it supports is XPS (can be created using the Windows XPS printer driver and worked slightly better in our case). I don’t think I have to mention that it is Windows-only, but running it in VirtualBox and communicating via USB works really good.

(Click on the links, I made some short videos of the etching)

You insert the laptop, put the laser into the top right corner of the ething area, focus the laser and off we go. Depending on the power it can look quite fascinating, with sparks and burning (40% power). In my option, the optimum is around 30% power as in the three logos in the corner.

And then, sometimes catastrophic failures happen. After we started, the carriage with the laser started hitting the border of the laser area, therefore my Octocat is split in two because the carriage was moved in mid-etch. I think the software should detect that you’ll laser an area that is outside of the reach of the carriage, but oh well.

The not-dying-part? Yes. Keep good ventilation. With 20% power the smell was ok, with 30% it was annoying. With 40% it burned quite deep and the burnt shell made the whole room smell awful (and probably the fumes are not healthy). We redirected the fumes with proper ventilation to the outside in the first place but our laser is not airtight. We should improve this someday.

The results

A picture is worth 10K words - but only those to describe the picture. Hardly
any sets of 10K words can be adequately described with pictures.

Alan Perlis

More pictures and in higher resolution my album. Feel free to follow/share.

Observations:

  • The Pirate Bay logo is too light. You can see it from the side but not from the front
  • The Mozilla logo is actually shaded, because the ThinkPad was not laying flat, because of the surface below the laser is crooked. Not a big issue, looks kinda funny.
  • The git logo is really deep
  • The Octocat is split. Maybe I’ll put a sticker on top of it.

Overall, I am still really impressed and I think my new old ThinkPad is pretty awesome now. It was about 15 minutes of laser etching (the club charges per minute) so it cost me 15€ overall and some 4 hours of work.

Etching tips, aka don’t repeat our errors

  1. After that messed up Octocat, we went for something diagonal (Debian, GNOME, Clojure), so we had to tilt it in Inkscape and import it in the etching software. But it is difficult to calculate, so we figured out you can do a test run without the proper laser, the laser pointer mounted on the carriage is enough to see whether there is overlap or not.

  2. You can switch to cutting mode, then it only etches the outlines, so you can see even more clearly, if what you want to etch is in the proper place. We did this with the three logos multiple times, and adjusted it on every run. This worked out really good.

  3. Random observervation: our camera recorded in MPEG1 with MP2 audio. The resulting file for the Mozilla recording was 347 MB. Stripping the audio out end encoding the video produced a 11 MB H.264 (MP4) file and a 12 MB WebM file with hardly no worse quality.