Main contents

Archive for the 'Programming' Category

The mighty goosh

June 3rd, 2008

come all without, come all withoosh,
you’ll not see nothing like the mighty goosh

enjoy :)

Posted in Programming | No Comments »

javascript

May 14th, 2008

it may have become clear to the screaming masses by now that i have a rather low opinion of incredibly complex server-side webpages. As far as i see it, business logic should be in the browser, where database functions can be made available using our old friend xmlhttprequest. I can see a number of basic guidelines to getting this right:

1/ the basic page with all the divs should be stored as main.html (or whatever) on the server.
2/ a way must be found to separate the javascript files which deal with business logic from those which deal with displaying information.
3/ methods for displaying information should be pretty general. for example:
 function addNewRecordToTable(newRecordObject, tableObject)

more ideas to come once i’ve got the basics ironed out :)

Posted in Programming | No Comments »

GoogleDocs

May 9th, 2008

ich habe soeben eine anwendung fuer googledocs entdeckt. ich wollte soeben zuhause eine sammelbestellung bei emp.de abgeben, der eine hatte aber die falsche artikelnummer eingetragen, also konnte ich nicht bestellen. emp.de aber speichert den warenkorb in einem session-cookie, also habe ich den cookie geklaut und in googledocs gespeichert, damit ich ihn auf arbeit benutzen kann :)

schauen wir mal, ob es funzt. ich bin gespannt :)

update—

leider hat es nicht geklappt. vor allem schwierig war es, die cookies.sqlite-datenbank zu bearbeiten, aber google hat ein plugin fuer firefox geschrieben :) gaaanz cool :)

Posted in Hobbies, Programming | No Comments »

Getting to grips with Seam

May 8th, 2008

Maybe you belong to that lucky 99.9% of the population who has never heard of this wonderful web framework called seam. Now that i’m using it in this new job, i thought i’d tell you something about it.

Firstly, don’t try to understand it. Seam is a Java framework based on pretty much every one of the Java Family of Technologies with the result that it is a black box. Any attempt to understand Seam will cost you a lot of time and won’t get you anywhere. Creating a new Seam project involves generating about 20 files with no rhyme or reason to them and saving and archiving them in strange locations and formats. As well as this, you will also be required to know what database you are using, where the database is, user name and password and supply the right driver for JavaEE to access it.

Seam is a web framework for developing database front ends. if you want to do something else with a web page, don’t use Seam! The way the user has to build a Seam application may seem strange at first, so i’ll sketch that out and why it is that way.

A database web application contains a lot of data, stored in a database. That may not surprise you. Let me add something to that. In a database web application, every piece of date that can be altered/deleted/added over the graphical user interface should be stored in the database. That is after all why we use a database. So if your application manages people’s names, the names should be contained in the database and any changes you make should be written to the database as soon as possible.

So what else does the server do here? well, the server must get the information from or store the information in the database and send it to the browser in a nice form. Now we have to consider a couple of words: stateful and stateless.

let’s use an analogy. most lego stones are stateless: there is nothing about the stone which can tell you what it has done in its life. a bike is however not stateless: it has different gears, for example, so by looking at the gears you can tell something about how fast if has just been ridden. the software on the server is in general stateless. most methods you use will do the same no matter what you have done beforehand and will always do the same. An example: let’s consider you want the database to give you a list of names. you could write (in pseudocode):

function getListOfNames:
  return myDatabaseConnection.submitQuery("SELECT * FROM names")

If you wanted to make it more complicated:

function getListOfNames(caller):
  if !caller.isLoggedIn:
    return
  return myDatabaseConnection.submitQuery("SELECT * FROM names")

but the function is still stateless. it will always try to perform the same steps and if it is successful or not does not depend on who called it in the past. Methods like this have the advantage that if something crashes or goes horribly wrong, information is not lost.

However, in a web application there is a large amount of state to be saved that you don’t want to be immortalised in the database. For example, if you click a link in the application to go somewhere else, you expect to be shown a different page. Another example: if you want the same list of names to appear on every page, you may want to keep certain objects around in memory for a while to avoid the expense of looking them up in the database repeatedly. Here there are two approaches:

  1. Save state in the browser as an ajax application
  2. save state on the server using sessions

Of course, saving state on the server does have some problems. The server could be dealing with many requests at once, so it needs a way to tell the clients apart and to make sure that one process doesn’t interfere with another. In general, state is best saved in the browser as an ajax application (why should the server know where i am in the application? if i want a list of names it should just send me them after checking my id). However lots of people who should know better love saving state in sessions on a server. This is how Seam works.

However, even the Seam developers were quite unsure that they were doing the right thing, so they decided to separate the html from the java. So you end up writing lots of html pages with embedded fields which are then processed by the application server before being sent on their merry ways (rather like Apache processing php code before sending it to the browser. I suppose you could make the java stuff in the background generate html (or xhtml) but it’s certainly not the idea.

So you have a backend which tries to save the state of the user’s session and process requests so that the result can be added to some very strict templates. if you want the scripting side to be able to make huge changes to the representation of the data (if the name “howlingmadhowie” is in the result set, please print this extra large on the screen and use some javascript to animate it, for example), you will have your work cut out for you with seam (as you would with every framework i know–in general, framework X will allow you with very little effort to write a framework X application, if you want to do anything else, it will turn your life into hell).

anyway, now we get to one of the most confusing things about Seam (and i don’t mean really, really strange annotations and the usual java problems like String being final (which i will write a rant about some day)). The Java classes in the Seam framework have to deal with 2 types of persistence: database entries which will change what everybody sees, and session state which depends on who you are and where you are in the application. If you didn’t have a framework, this wouldn’t be a problem. you’d just have your SQL queries for the database, and your session variable (of a collection of cookies or whatever) to represent state. However, some bright people thought that a framework could make accessing the database something that happens in the background. This means you create a List of objects, wave a magic-wand and everything is in the database. when you log in tomorrow and want to read them again, you wave this magic-wand again and there they are.

This approach has a number of very serious problems. Let’s go through them from most trivial to most hair-raising:

  1. You have to keep your wits about you to know where something is stored (is Seam going to store that as a session state or should it be in the database?)
  2. You are second-guessing the abilities of the database to manage queries and organise data. This is what databases are designed to do
  3. You have to give the database user Seam uses to control the database wide-ranging powers.

The last one is really, really bad. what this means is that if somebody finds out login name and password of the Seam database user, your whole database can be wiped out. As far as i can tell, you cannot restrict the database user to use procedures only. You are left with trying to restrict the place the database user can login from (db.host) and other stuff. The best way is to make the database user incapable of screwing things up to a great degree. A database user who only needs to update fields, select information, add new records and delete records once in a blue moon should only have these rights and the database should check exactly what the user is doing.

So you may well be reaching the conclusion that i have a rather dim view of Seam and you’d be right. Every web framework i have seen up to now has made the life of the poor web application developer more difficult and not easier. Web frameworks tend to offer capabilities to make some things easy (by obscuring what it’s actually doing) and everything else nearly impossible.

It is however not all good news. Java applications are difficult to write, not only because Java as a language is extremely old-fashioned (what sort of language in the 21st centuary has explicit typing?) but also because everything has to be compiled and deployed before you can see it. At the moment i’m correcting some css errors in our application. Without firebug, this would take days. Everytime you change something in a .css file, you have to compile and deploy the project and wait for the jboss server to realise it’s still alive. This usually takes about 2 minutes. Any comparison with php/python/ruby/perl etc. where you just press “refresh” in your browser, is bound to be very unfavourable to the Java way of doing things.

Summing up, you could probably say that the development time of a Seam application in eclipse is around 4 times as high as hand-coding the page in php using emacs. The one advantage i can see at the moment is that Seam forces the programmer to separate the representation layer (html) from the logic behind (Java code). But that’s something you should do anyway and trivial with embedded php tags and functions.

Posted in Programming | No Comments »

gnewsense

May 1st, 2008

the new version of gnewsense is out! yippee! and my torrent’s running as i type :)

if you want to speed up my download, the torrent can be found here: gnewsense-torrent. don’t forget to check the md5 sums: md5sums!

Posted in Programming | No Comments »

microsoft promoting free software and open standards (unintentionally)

May 1st, 2008

we had something amusing happen at work recently. a client sent us a template we could embed in their internet page to be dynamically populated. our boss convinced the client the best format would be microsoft xml from word 2003 (because the client uses word 2003). so they sent us the template and their was a lot wrong with it (images in the wrong place and wrongly scaled, missing borders, wrong font positioning etc. etc.). we sent the template back and asked them to correct it. they sent us a new version which had the same problems. we sent it back. this carried on for about a month until i suggested we find a version of office 2003 to view it in (those that use windows at work had been viewing the document in word 2007) and then everything looked perfect. to quote moss, “egg and my colleague’s faces were in alignment”.

this of course left us with a problem. at some stage in the future the client will update some of their computers and install office 2007 or later. we cannot claim that we did not know about these problems. fortunately i’m just a code-monkey so i find it all highly amusing. at some stage i will tell my boss that there are java libraries for processing and creating odf files (at the moment we’ve been populating the word xml file by greping the text for strings and replacing these), and that sun makes a plugin for word. but i’ll let him ferment for a few days first until he’s really desperate.

Posted in Programming | No Comments »

wenn ich einmal reich wär

April 30th, 2008

well i finally got my first paycheck. yippee!

the first thing i did was give amazon its 10% and order a number of books on ejb3/seam/jsf stuff (and one book on scheme, so i have something interesting to learn).

speaking of java, i’ve just discovered the bean shell. this almost makes java tolerable, so if you’re a java programmer and haven’t heard of it (unlikely, i know), then go take a look at www.beanshell.org.

Posted in Programming | No Comments »

ultra10

April 26th, 2008

well i’ve just spent most of the day installing ubuntu 8.04 on my ultra10 (remind me to get my blade 1000 fixed someday, so i have a machine that can run solaris, and i refuse to run solaris on anything other than a sparc). sometimes i enjoy battling with whatever bugs you can find, and this time there were lots of them.

you can read about it here: http://ubuntuforums.org/showthread.php?t=768997

Posted in Hobbies, Programming | No Comments »

8.04

April 24th, 2008

well, it’s finally here.

one good thing about having lots of computers (in my room i have the following:

  • athlon64
  • another athlon64
  • ultra10
  • G3 imac
  • sgi indy
  • pentium 4

) is that i can try out lots of different gnu/linux distributions on lots of different bits of hardware. so at work today i dialed into my nas per ssh and set rtorrent in a screen session downloading the new ubuntu releases. maybe i’ll spend the evening cleaning up my main computer. it still has a huge reiserfs partition on it from 3 or 4 years ago. giving it an 8.04 makeover may be a good idea :)

Posted in Programming | No Comments »

OOXML vs. ODF

April 19th, 2008

well here i am trying to generate an ooxml file through java. It’s a nightmare, because OOXML is totally fubar. The syntax is horrible. I mean, nobody can possibly understand it without spending a lot of time with it.

one of the horrible things it does is cover the xml file with random magic numbers which are sometimes important. in my current document, the following appears at the start of most lines:

<w:p wsp:rsidR="00000000" wsp:rsidRDefault="00240B78">

anyone care to guess what that’s about? odf seems to get along fine without this stuff.

Posted in Programming | No Comments »