Dienstag Jan 06, 2009

A MySQL GlassFish Application

During my time as a teaching assistant, I used to say to the students, "Imagine, you visit your grandmother and she asks you, 'Now boy, what did you do at the university today?' It's hard, but you have to do your exercises in a way, as if you were talking to a six year old." On the other hand, students are often frustrated, if they don't understand a subject down to its bare bones. It's only natural to have such feelings.

Giving a tech talk, you have to find an interesting sample, but it also has to be simple, for you don't want your audience to fall asleep. I was dreaming of a database-web application without tables full of employees, departments and managers or flight schedules. It had to be something, where the design tools and the web stack stand more in the foreground.

I started a project -- www.mimesy.com, using the NetBeans IDE, JSP, the jMaki framework, the MySQL DBMS and the GlassFish application server. It's some kind of a blog site, but the user cannot actually blog, microblog or nanoblog or upload any media files. The only thing you can tell the world is a color. There is also no history of colors, just a color you have at the moment. Login data and the color information can easily be stored in only one database table.

Mittwoch Sep 24, 2008

A Kiss from the Lambda Calculus


This month, I went to the Berlin.jar conference (a Java conference in Berlin), a two-day event at the FHTW Berlin (university of applied sciences). This year, it was the first Berlin.jar and it's planned to do it again next year.

One of the many presentations was about the Ruby programming language. Like some other languages, the language contains the lambda keyword. Historically it comes from the λ-calculus, a theory intended to be a foundation for mathematics (like Frege's logicism, this attempt failed). The keyword lambda introduces an (anonymous) function (object). In particular a function can be returned by a function and can be a parameter to a function, including itself. The lambda example, given in the presentation, was an anonymous function which takes no arguments and returns a random number.

This wouldn't be possible in the λ-calculus, nor in a pure functional programming language (e.g. Haskell). There the purpose of λ is to bind variable names, just like quantifiers do it in predicate logic, and a λ without variables is syntactically incorrect. It would also be impossible to have a function that doesn't always return the same value for the same arguments, a function with no formal parameters is simply a constant. In contrast, an imperative language allows side effects (the result of a function does not only depend on its arguments), therefore the meaning of the Ruby lambda is not the same.

An imperative λ. How ironic. Walking around after the conference, I made this picture of a remaining segment of the Berlin Wall near Ostbahnhof (Brezhnev kisses Honecker, above "Lord, help me to survive" is written in Russian).


Dienstag Sep 02, 2008

Sun Studio 12 IDE on Debian GNU/Linux

I have installed the Sun Studio 12 IDE on Debian Etch recently. With a slow internet connection, you don't want to always download everything, and I have some of the SDN All Access Kits (the 10/2007 version) for giving away to students. The kit consists of two DVDs, with Sun Studio 12 (20070730) and a lot of other software on them. On Debian GNU/Linux, we need some magic if we want to get the install wizard to work (there are other versions, I know).

SDN All Access Kit

Type su in a terminal window and become root. Change to the Sun Studio directory on the DVD and Copy the Linux directory to root's home: cp -r Linux ~ (do not use GNOME's file manager).

Install the Java Platform SE 6, I used the Java SE Development Kit 6 from one of the DVDs (copy it to root's home, extract, copy the extracted directory to /usr/java). Install additional Debian packages:

   apt-get install gawk alien libc6-dev

The alien package will give us the rpm command (RPM Package Manager), rpm is needed during the installation. The installer assumes it to be in the /bin directory, therefore create a link:

   ln -s /usr/bin/rpm /bin/rpm

Start the install wizard: cd ~/Linux && ./installer (now it should work). In the components window, uncheck Sun Studio 12 Performance Library ML (otherwise the installation will not complete, any ideas?). Leave everything else as it is and click '->' until you see a 'Close' button. Click 'Close'.

Montag Jul 21, 2008

Sequential ZFS Mirrors

Last month, an ambassador colleague shared the idea of having ZFS mirrors on only one hard drive. One of the immediate questions is: how fast is such a zpool? I did some tests on a 1.7 GHz Pentium M laptop with a 120 GB IDE drive (WDC WD1200BEVE) and 1 GB of main memory, running the OpenSolaris 2008.05 distribution. Leaving some space behind the root file system during the installation, I used the remaining three primary partitions for a zpool (“m3”) where the data was replicated twice (two mirrors).


Testhomedir (within rpool)m3
Creating a 1 GB file (with dd)33 s, 32 MB/s134 s, 7.8 MB/s
Reading the 1 GB file (with dd)22 s, 46.7 MB/s41 s, 25.6 MB/s
Compiling the wxWidgets library9 m 18 s9 m 41 s

Donnerstag Apr 24, 2008

Too Many Return Types

(inspired by a discussion on one of my mailing lists)

The compiler says 'No'

Thank to the overloading feature in the Java programming language, method names within a class have not to be distinct (as long as the signatures differ). Can we overload a method by changing only the return type, i.e. if there is a method, can we define another one with the same name and parameter types and order, but with a different return type? The compiler says 'No'.

   class A {
       S f( p ) { ... }
       T f( p ) { ... }   // ST, p is a parameter list

This behavior is defined in the language specification [1] and, with the return type not being part of the signature, it is not a violation of our definition of overloading. Of course, the language-specification argument is only for the compiler a strong one for treating the situation in this way. For those, who sit on the other side of the code, it's more a fact than a reason.

Who you gonna call

Although we don't hold methods to be objects in the sense that they are instances of OOP classes, in our minds a method still has a type, and the most interesting properties are possessed by its input and output. Thus, if we imagine that a method is something like a function, we can write

P1 × P2 × … × PnS

as the type of the first f from the example above; the type of the second f looks similar, S is replaced by T. Let's now suppose, there is a call to f somewhere in the source, so that it's
  1. a call where the return value is thrown away, or
  2. a call where the return value is passed to a method or an operator (as an argument).
At this point we run into difficulties, for it's not always clear which f should be called (we'll see, that this holds for both cases). Since the difference lies in the method type, we must specify the type of the method we want to be called. The types behind the arrow can be derived from the call itself. This is how an overloaded method is normally chosen, but here we have to specify the return type as well.

The obvious solution is at the same time the behavior we want to have claiming return-type overloading. A call is always within a certain context, and it's the context that shall specify the return type. For a (non-overloaded) method g of the type SR (Svoid), putting a call to f into the argument place, we want the first f to be chosen. If S or T is void, case 1. specifies an f too, otherwise we don't know which f is meant.

However, there remain more situations where the context does not do the job. First of all, return-type overloading collides with parameter-type overloading (and with generic programming). Suppose there are now two methods g, one taking an S and one taking a T as an argument. Then in g(f(...)) we want the call to f to specify the context, on the other hand we want the context to specify an f.

Implicit type conversion can be treated as a kind of parameter-type overloading (e.g. a method that takes a java.lang.Object as an argument does not distinguish between all the subtypes). Sometimes we want to cast a return value. Again, we can think of a cast operator as an overloaded method.

From the existence of such cases it is apparent, that we need a special syntax that resolves ambiguity, and it's not possible to stay within the grammar of the language.



Sun Campus Ambassador,
University of Frankfurt (Germany)


« Juli 2016