The T-Files


Tue, 30 Mar 2004

Things to bring

If you plan to visit me from Germany, please bring along the following papers/magazines:

  • taz - die tageszeitung
  • Bild Zeitung
  • c't - magazin für Computertechnik
Thank you.
Sun, 28 Mar 2004

Yanaka

Within walking distance from our apartment, just across Nippori station, lies Yanaka, which was a religious centre of Tokyo during the Edo period. It seems every family at that time established their own temple, and as a result the neighbourhood now abounds in them. Yanaka has between seventy and eighty Buddhist temples today, seven of those on my pilgrimage to the Eighty-eight Places Within Tokyo (of which I have seen nine so far). I started going to the Eighty-eight Places Within Tokyo in addition to the Thirty-three Places in Kanto, because those are quite difficult to reach, but I will not begin visiting the Thirty-three Places of Edo or the Other Twenty-one Places Within Tokyo before I am done with either of them.

Yanaka also has a big cemetery. Cemeteries in Japan function as public parks, too, and as it is sakura season and perfect weather now, it was packed with people sitting on blue plastic sheets, having barbecue under the cherry blossoms.

Sat, 27 Mar 2004

Tokyo Duo City

We are moving! Not immediately, mainly because the house has not been built yet, but almost definitely in March next year.

Fri, 26 Mar 2004

The thousand and one reasons to love Perl: [3] Subroutine parameters

There are many complaints brought forth against Perl. One of the few that is valid is the lack of a formal way to specify parameters when calling subroutines. It cannot be denied that this is a serious shortcoming, mainly because it prevents the compiler from checking the validity of your subroutine calls, which would catch errors early on, make debugging easier and save some coding effort on your part when checking parameters yourself. Since there is no official parameter passing convention, different styles have developed, which tends to confuse beginners, sometimes to the point that they stop using parameters and pass stuff around in global variables. Not good.

The upside of all this is that because you have to implement parameter passing yourself, you can do it according to your needs and liking, and the process becomes more flexible than in most other languages.

Simple (positional) parameters

sub foo{
    my ($a, $b) = @_;
    ....
}

Optional parameters
Since there is no parameter checking, you can call a subroutine with less than the full number of parameters. The subroutine will receive an undefined value (that is: the well-defined value called undef) and can be coded to act appropriately. So you can call above subroutine like

foo(123,345);
foo(123);
foo();

Variable parameter lists
The popular printf function takes a format string and a variable list of parameters to print according to that format. If you wanted to implemented it in Perl (which does not make sense, since Perl already has printf) you could write

sub printf{
    my ($format, @list) = @_;
    ...
}

Named parameters
If you have a lot of parameters, some of them optional, it makes sense to change from positional to named parameters. In Perl, this can be easily implemented using hashes (which are a core language element).

sub bar{
    my (%parameters) = @_;
    my ($size, $offset)  = @parameters{ qw [ size offset   ] };
}
# call this function like
bar( offset => 100, size => 22 );

Named parameters with default values
Setting up default values for optional named parameters is simple, just put the defaults in the parameter hash before the actual parameters, so that they will be overwritten as needed:

sub bar{
    my (%parameters) = ( size => 100, offset => 0, @_ );
    my ($size, $offset)  = @parameters{ qw [ size offset   ] };
}

The future
Perl6 (which should ship within the decade, maybe even before Duke Nukem Forever) will have a syntax to formally specify parameters (if you want, it will be optional) that will support all of the mentioned features (plus parameter type checking, return types and other goodies), so that you will be able to write

sub bar
    ( int +$size=100 , int +$offset=0) 
    returns Array of Str { ... }
Wed, 24 Mar 2004

Saving bandwidth (Part Two)

Chances are that a browser visiting your web site has seen it before. In this case, some parts of your site are probably still stored in the browser cache. A few of those parts may have changed in the meantime (such as the writing on your top page) but others will be the same as before in which case there is no real need to transmit them again. Not transmitting things obviously reduces bandwidth usage. Loading large image files from a local hard disk cache rather than over the network noticably speeds up the display of web pages.

The way this idea is implemented in the HTTP protocol is called conditional GET. When a browser requests a file that it has downloaded before, it will send an If-Modified-Since header. If the document has not been modified from the indicated version, it is not retransmitted. There will be just a 304 Not Modified response from the server instead. For static files, this is automatically implemented by all common web servers, so unlike with content compression you do not have to do anything to use this feature. Dynamic files are a different matter. If you want to support conditionals GETs for them, you have to implement it yourself. This is not often done, and the effort does not really pay off most of the time (since dynamic pages have a tendency to change too often to be cached anyway). One case where it is worth to support conditional GETs, however, are RSS feeds. For the usual blog, they do not change more than once or twice a day, but they are polled much more often than that, often hourly.

During the last (admittedly not very busy) week, the T-Files RSS feed (about 5300 bytes at the time) has been requested 304 times. But it had to be transmitted only 17 times, and half of those transmissions have been compressed to 1900 bytes. This brings the average transfer size down 96% to just 195 bytes.

Tue, 23 Mar 2004

Oscar Wilde: The Picture of Dorian Gray

The first piece of serious literature I have read in quite a while, and it came in a heavily annotated edition, comprising the original short story published in an American magazine and the later extended British novel version, as well as examples of the discussions it sparked in the papers at the time it was published, extracts from the protocols of the trials that followed and essays about the book. The story itself was surprisingly interesting and the novel is full of witty aphorisms (which I find myself unable to remember in a quotable quality, however).

Sun, 21 Mar 2004

Paycheck

With Lost in Translation still not showing, the subtitled version of Innocence (somehow related to Ghost in the Shell) discontinued due to unavoidable production circumstances (?!), and having missed Once Upon a Time in Mexico by an hour, it is good to still have movies like Master and Commander or Paycheck to default to. It would have been even better, if Paycheck lived up to the standard set by Minority Report and Total Recall (other Philip K. Dick adaptations) or Face/Off and Mission Impossible 2 (decent John Woo Hollywood movies).

5 points

Fri, 19 Mar 2004

BeanShell - Lightweight Scripting for Java

BeanShell is a small, free, embeddable, Java source interpreter with object scripting language features, written in Java. BeanShell executes standard Java statements and expressions, in addition to obvious scripting commands and syntax. BeanShell supports scripted objects as simple method closures like those in Perl and JavaScript(tm).
You can use BeanShell interactively for Java experimentation and debugging or as a simple scripting engine for your applications. [...] you can call your Java applications and objects from BeanShell; working with Java objects and APIs dynamically. [...] you can freely pass references to "real live" objects into scripts and return them as results.

Very, very useful (for projects where Perl is not an option and you have to use Java). It gives you great rapid prototyping capabilities, speeding up your development (especially the testing and debugging part).

BeanShell is also used internally by the JEdit text editor to write macros.

Wed, 17 Mar 2004

Kill is Love

I am putting together a campaign page for Kill Bill 2 (we are actually selling officially licensed avatars!) and I could not help but notice the strange tag line.

Kill is Love? This is probably (hopefully?) only used in Japan and another perfect example for Engrish.

Sun, 14 Mar 2004

Cirque du Soleil: Quidam

We saw Cirque du Soleil yesterday. Exotic costumes, disturbing images, great music (although we were somewhat at a loss trying to figure out in what language the songs were), and of course fantastic acrobatics. Unlike Holiday on Ice or the acrobatics show we saw in Shanghai, they also had clowns, which is generally a good thing, and people entering the stage from holes in the ground.
Thu, 11 Mar 2004

Tokyo Banana

From Tokyo to all over the country since 1991:

People gather to TOKYO from here and there with memories of their home. And then, Tokyo gets the everyone's home town.
Mon, 08 Mar 2004

The thousand and one reasons to love Perl: [2] String literals and interpolation

Perl (Practical Extracting and Reporting Language) was originally designed to work with text, and as such has plenty of nice features to work with strings. A very basic element is how you can specify string literals (constants) in your program source code, and Perl offers unmatched flexibility and convenience here. Those are simple things, sure, but why not get the simple things right?

Simple string literal
Well, every language can do that...

my $foo = 'A string';

String literal that contains quotes
If you want to include the quote character in your string, you usually have to escape it. Otherwise the parser will think it terminates the literal string. You can do that in Perl, but you can also simply choose different quote characters that are not contained in the string. With the qx operator you are fairly free in choosing the delimiter.

my $foo = q{A string with ' " quotes};
$foo = q[blah blah];
$foo = q=blah blah=;

Simple multi-line string literal
Many languages do not allow you to spread a string literal over more than one line. Perl does.

my $foo = 'A string
with two lines';

Very long multi-line string literal
There is an additional syntax called here-docs that is specifically designed for long multi-line strings which can also include all kinds of quote characters, that you would normally have to escape. It starts with <<MARK where MARK is the end-of-string mark of your liking. The string starts on the next line and continues until you put the MARK on a line by itself.

my $foo = <<RAVEN;
 Once upon a midnight dreary, while I pondered weak and weary,
 Over many a quaint and curious volume of forgotten lore,
 While I nodded, nearly napping, suddenly there came a tapping,
 As of some one gently rapping, rapping at my chamber door.
 `'Tis some visitor,' I muttered, `tapping at my chamber door -
 Only this, and nothing more.'
RAVEN

Interpolation
Just like a command shell (but unlike most other programming languages) Perl allows for convenient interpolation of variables within strings:

my $name = 'Tyler Durden';
my $greeting = "Hello, $name!";                      # note the double quotes
my @numbers = qw( one two three four five );         # nifty way to quote an array of words
my $foo = "I can count: @numbers";                   # interpolate the array
$foo = "3: $numbers[2]";                             # or just an array element
$foo = "even: @numbers[1,3], odd: @numbers[0,2,4] "; # or some array elements

The True Show

Last Wednesday I joined Natasha (and Marek, and Roberto, and about 60 other foreigners) for the recording of a segment of SMAPxSMAP, so if you have a chance to see Fuji TV tonight at ten, by all means do, as you might catch a glimpse of yours truly.

Part of SMAPxSMAP is The True Show, in which a celebrity has to disclose a well-kept secret. In this case it was SMAP member Tsuyoshi Kusanagi, who has also become known as Choran Kang since he started his own Korean language TV show three years ago. He has become very popular in Korea, made a few albums, and promised the prime minister to make a movie (which, surprise, surprise, happens to be premiering these days). The confession he made to show master John Kabira (speaks native American, native Japanese, DJs, comments play-by-play on the Japanese national soccer team for TV and video games) was that he did not speak Korean at all in the beginning, but just memorised the pronunciations.

TV shows all over the world work with premeditated cheers and jeers from audiences, but Japan takes it a step further. Not only was the whole studio audience paid to be there on Wednesday, and every one of their reactions carefully rehearsed (so that a three minute segment took four hours to shoot), the audience also consisted wholly of foreigners, most of them could not follow the confessions they were supposed to spontaneously react to. Two of us even had to shout scripted questions. Note the ironic twist that made Kusanagi confess about faking an interview in a language he did not understand to a jury that could not understand him either.

Sat, 06 Mar 2004

The thousand and one reasons to love Perl: [1] Inline::C

Consider this: You have to add support for some electronic payment system to your shopping website. You have to access the payment gateway using a vendor-supplied C library. The documentation suggests you write a CGI script in C, or use the Java Native Interface. Well, Perl to the rescue!

Perl is written in C (Perl6 will be, too). There is an mechanism to create Perl extensions in C, providing access to native libraries. This is frequently used to make Perl interfaces for things like XML parsers, database drivers, OpenSSL, or efficient mathematical algorithms. Using that mechanism is not for the faint of heart however, as it has a steep learning curve. But in Perl, there is always More Than One Way To Do It (tm), and in this case there is Inline::C.

Inline::C is a module that allows you to write Perl subroutines in C. You can just place them in the middle of your Perl files (hence the name, Inline). You can also access external libraries. All of this is surprisingly hassle-free with compilation and linking going on behind the scenes.

use Inline C => Config =>
    ENABLE => 'AUTOWRAP',
    LIBS => 
        '-L/usr/local/edy/lib -L/usr/local/ssl/lib -lssl -lcrypto -ledymallapi',
    INC => '-I/usr/local/edy/include';

use Inline C => <<'EDY';

#include<edymallapi.h>
#include<edyerrcode.h>

# just declare the function headers, wrappers around the
# C functions in the edymallapi library will be automagically
# created

int edygeterrorcode();
char *edygeterrormessage( int );
EDY

# and now I can call the C function from Perl
# just like that

print edygeterrormessage( edygeterrorcode());

Have a look at the Inline::C cookbook.

Roger Stern: The Death and Life of Superman

The foreign language section of the Shibuya public library has some rather annoying gaps. There is for example not a single volume of Philip K. Dick, Douglas Adams is limited to Mostly Harmless, no sequel to Hyperion and no Mrs. Dalloway. They make up for this by having what seems to be a complete collection of Stephen King, Danielle Steele, and John Grisham, supplemented by sports biographies and adaptations of Star Trek, Star Wars, comic book, and TV shows. I can only hope that those tumbled out of an expatriate bookshelf in the form of a donation, rather than being the result of tax yen spent (in this case, building superfluous bridges and roads instead does seem a good choice).

Stern's novel is the write-up about the events leading to Superman's death and rebirth in 1992/1993. It is based upon the comic books published during this period, with additional material drawn from other volumes of this long-running series. So if you want to learn about Superman's encounter with Doomsday, his dealings with Lois Lane, his foster parents in Kansas, the people and police of Metropolis, Lex Luthor, Supergirl, the Justice League, the media, Superboy, several clones, impostors, and aliens, but you do not want to read the comics itself, this book is for you. I said if.