Author: francis

Diary

What’s the matter with people

Today I remembered why I hate driving.

Incident 1:

Coming up to a set of lights just before a 30 zone. I’m in the outside lane, doing about 40. Car on inside wobbles part-way into the outside lane, sees me and wobbles back. I carry on. I’m about a foot from him (or her) and they start coming again. No indicators, nothing. Fortunately I’m able to use a right-turn lane to go round him. We then stop at the lights.

Horn beeping at me. I look in the mirror and shake my head. Then the abuse and shouting starts.

Let’s get this straight: I managed to avoid an accident, I manage to stop this person spreading me and my son all over the road, and somehow it’s my fault.

I indicated right (as in look, this is what indicators look like) and waved at the indicators. More beeping and abuse.

The lights change and we move off.

For some reason this is still winding me up at 1 o’clock in the morning and I bet the idiot concerned is sleeping soundly. There ain’t no justice.

Incidents 2, 3 and 4

All at roundabouts, people pulling out at me. I’m not speeding, I’m obeying the rules about signalling properly. I just don’t get it. If you’re going to take a risk because the traffic’s heavy you should get out of the oncoming person’s way, not make them have to brake to miss you.

Incident 5

I’m coasting to a stop at the lights and someone swaps lanes when I’m maybe six inches from them. Fortunatly they’re moving and can get away from me before I hit them. I just wave hello, completely speechless.

All this for the two or three seconds you save at 2 o’clock on a Saturday. Not even in a busy part of town. Why risk your neck for this? I don’t get it, not at all. All of these incidents happened in the same hour or so.

Sad thing is, this happens to me all the time when I drive to work. No wonder I love going there so much. I wish people would chill and calm down a little, just think through how little life we all have left, before they start taking dumb risks in cars made of kitchen foil.

Family stuff

Took Jon to the kid’s club at Awesome Walls. He manged to get his first award. We’re going there tomorrow (today, actually) so we can all climb. I then went and got him a new controller for is PS/1, because the old one’s broken. This was a reward for getting something called a silver book award at school for having a good attitude.

Programming Projects & books

Just finishing reading Advanced PHP Programming by George Schlossnagle (0-672-32561-6). Very good book, even if you’re not interested in PHP he has a lot to say about cookies, caches, security, reverse proxies, using design patterns (as in getting some value from the academic view), as well as a host of other useful stuff. PHP differs from Java in that it doesn’t use threads: the persistent thing is in fact the interpreter. This makes it hard to crash but perhaps slower because it’s difficult to share things across sessions. Not an issue for my project but worth remembering.

I also really like the __get() and __put() object methods, where you can add arbitrary fields to objects that you can access using standard syntax rather than a method call. I think this is going to be a very useful facility for my database abstraction layer.

Motivational books

If you’re struggling with motivating people or yourself I think you should read Whale Done by Ken Blanchard (I think of One Minute Manager fame). Essentially:

  1. Catch people doing things right and sincerely thank them for it.
  2. If they are doing things wrong, take the blame and then redirect their energy where you want it to go.
  3. Praise improvement, however small.
  4. Don’t forget to catch yourself doing things right.

It revolves around positive feedback. The metaphor is based on how they train the killer whales at the Sea Life Center in Florida. You can’t use coercion on an animal that is a top predator and weighs 1000 pounds. You have to become its friend and find out what it wants as a reward. People are even harder than this and yet we all persist in saying GOTcha.

I think this is why I’ve been so fed up recently. I have no idea what the value is of anything I do, and I get no feedback; either positive or negative. How can I improve or fix things without a benchmark? Also being told that your work is good when you know you are demotivated and underperforming calls your integrity into question and adds to the stress. Brains are weird.

Ah well, just finished some camomile tea.

Oracle Ingress and Postgres

In response to this:

http://www.theregister.co.uk/2005/03/24/ingres_and_open_source/

Hi Philip,

Speaking as someone who has jumped from Oracle to Postgres, mostly for cost reasons, I’m curious about what the relationship is between Ingres and Postgres. I thought Postres was Ingres. I obviously haven’t been following it too well.

The other thing about this database is that it is a much better implementation of the relational model. I can create proper domains that describe what a thing is instead of some techie crap like varchar(27) maybe or maybe not being a soundex code (or whatever). I like this because you can see what a table is supposed to do when you look at its description. Oracle still haven’t understood this.

Apropos Oracle, a lot of my friends say that they’d be very happy with an open-source (or just virtually free) version of the old Oracle 7.3.4, perhaps with the 8.1.5 PL/SQL engine. I would say that most of us just want a reliable data store and don’t give a stuff about all of the high-end stuff. 9i RAC and 10g – who gives a toss, really, apart from the half-dozen big corps (mostly telcos) that need big databases. I don’t care about Java in the database either, quite happy running it in the middle tier where it belongs, or just using PHP because it takes a tenth of the time to do something useful without fity squnitillion XML files that are sometimes ignored in some middle-tier framework that’s too hard to use.

Don’t get me started on their Applicaton Server – was a nice usable thing and is now a pregnant elephant in a temper with more layers than an alpine climber. In the light of which I’d like to see an article looking at the relative merits of JBOSS, OAS and WebSphere in the real world. Are there any plans to do anything like that?

Somewhat off the point but never mind.

Regards

Converting Java XML to PHP XML

Thought I might make some notes about this to help the next person along.

Firstly, PHP5 on windows just has the XML SAX parser installed by default so, even though there is a PEAR XML library, you don’t need it.

Attributes

The Java classes have a org.xml.sax.Attributes class. When you get passed this you can call a method to get values you are expecting, e.g.:

1
2
3
4
5
6
7
8
  void handleTable( final Attributes att )
  {
    firstColumn = true ;
    currentTable = att.getValue("name");
    os.println("create table " + currentTable );
    // Set up markers to create the tags table later
    if ( "true".equals(att.getValue("hasTag") )) tagTables.put(currentTable,currentTable) ;
  }

In Java there is an idiom where if there isn’t a value it will return null (which is why I have the string to test against the constant string first in the equals test, so that you don’t get a null pointer error if the attribute is null). PHP, on the other hand, uses the very useful associative arrays and the function became:

1
2
3
4
5
6
    function handleDomain( $att )
    {
      os::doprint("create domain " . $att["name"] . " " . $att["type"]);
      if ( array_key_exists( "nullable", $att ) && $att["nullable"] == "" ) os::doprintln(" not null");
      os::doprintln(";");
    }

Notice that I now have to use array_key_exists to test for something’s existence before I can do anything with it.
In this class, instead of having a local variable that is set to a print stream I have created a static class that I can use to do the printing instead. I may change this again, not sure.

A lot of the O-O junk isn’t there in PHP, a class is static if it doesn’t have any methods that need to use the this variable. Purists won’t like this but I don’t care, to be honest.

Method calls

One thing to be aware of is that PHP insists on the $this→; operator in front of any class methods. If you don’t put it there it will think you are calling an internal function but won’t complain until you try and call it.

Simplification using associative arrays

This:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  void handleTags()
  {
    String table = null
    ,      column = null ;
    Object [] theKeys = tagTables.keySet().toArray();
    for (int i = 0; i < theKeys.length; i++) 
    {
      table = (String)theKeys[i] ;
      column = (String)tagTables.get(theKeys[i]) ;
      os.println("create table " + table + "_tag" );
      os.println("( " + column + " id references " + table + "(" + column + ") not null" ) ;
      os.println(", tag_id id references tag(tag_id) not null" );
      os.println(");");
    }
  }

Becomes:

1
2
3
4
5
6
7
8
9
10
    function handleTags()
    {
      foreach ($this->;tagTables as $table =>; $column) 
      {
        os::doprintln("create table " . $table . "_tag" );
        os::doprintln("( " . $column . " id references " . $table . "(" . $column . ") not null" ) ;
        os::doprintln(", tag_id id references tag(tag_id) not null" );
        os::doprintln(");");
      }
    }

Which I think is quite good. A ton less code to get to what you want to do. I think there is a similar thing to foreach in java 1.5 but nothing as easy to use as this.

All in all, for getting the job done, I think PHP wins hands down. Java is very low level and has to do everything through a class and chuck arrays of Object around. The people who developed PHP weren’t afraid of putting things like associative arrays in the core language and this saves a whole ton of code. If you want to override methods and go the whole O-O hog you can, but you have to explicitly say you are going to do so.

PHP5 has most of the Java-like constructs apart from this see http://www.developer.com/lang/php/article.php/10941_3302171_1

Got my vote

If you want to see a very coherent and logical explanation of why software patents are such ridiculous nonsense see http://www.kuro5hin.org/story/2005/3/9/93357/91614.

Can you imagine a world where the particular genius of your favorite author’s rendering of an archetypal story would violate a patent? Quite often I read a novel for the characterisation and the inner life of the characters, but if the plot was patented then it wouldn’t exist. All those fantasy novels

  1. Problem – evil in the good land
  2. Gathering of the good guys
  3. Gathering of the forces of evil
  4. The impossible quest
  5. The struggle to complete the quest (sub plots, party gets split, is betrayed etc.)
  6. Quest is complete and good triumphs (always at the last second)

I read them if the characters are interesting and well-written. I know what the plot is, the interest is in the execution! Maybe I should copyright this, only problem is I don’t want to get any money from the really bad ones because it would be too embarassing.

Imagine if physics was patented. You would be paying money to the patent holders when you read a book explaining it, instead of which the author has to acknowledge who did the work, had the idea.

I mean, what if they patented breathing?

See how silly it is?

Has Knuth patented his fundamental algorithms (well he gathered them together and validated them, but you know what I mean)? There’s a scary thought.

PHP

Got talked into looking at PHP rather than Python.

I really like it: it’s got a lot of the lovely features of the unix shell (heredocument and `), you can have nice structures like

if ( cond ) :
expr
endif

So you can block your code properly. I have always hated the C and Java thing about the closing brace not telling you what’s being closed; this can be a source of bugs that only becomes apparent when you run the code through a formatter. Of course, it also supports the annoying {} as well, which makes it nice and flexible and easy for the Java/C heads to get into. I know you can do stuff like

if ( cond )
{
// 20 pages of “stuff” (Should only be about 20 lines if you structure it properly)
} // If

I hate this though. Just looks ugly and you have to remember to do it or enforce some really annoying coding standards that people will ignore because they think you’re being too pedantic. By the way, I always place the opening brace under the if so that if you have a mountain of conditions in the if statement you can see where the executable expressions begin. In PL/SQL I do this for the same reason

if cond – no brackets, irritiating things; why do a lot of modern languages pretend to be C?
then
Stuff
end if ;

I’m skim reading the tutorials at the moment to get a feel of the language’s capabilities.

I am going to rearchitect my system away from Struts and the like: I think I can just get a move on and get the thing finished quckly in PHP. Like Paul Graham says: the power of the abstractions of a language help you to get the job done and think PHP is ideal for what I need. And there are tons of exellent tools and large well-written projects to look at. There are also lots of nice free editors (including my all-time favourite VIM).

My plan currently is to redo the XML parsing I’ve been doing in PHP (a good learning exercise). Then I will create some self-describing objects that will define how the site is put together. Then PHP will be used to deliver these objects up to the end user. Make a change, regenerate (or maybe just change the XML descriptors), site stays up. That has always been the goal. I plan to use Open LDAP and suchlike for user and resorce management.

It looks loads less hassle than Struts for a small project like mine. I’ve been trying off and on for weeks just to get an HTML form that allows me to update some data, haven’t even got to the XML rewrite capabilities yet. Time to change to more powerful tools that can help me build the tools I need before I die of old age.

Postgres vs MySQL

I prefer Postgres as a platform, even to Oracle, because it is a purer implementation of the relational model. Particularly the ability to create domains, which is central to relational theory, but Oracle doesn’t do it. Types in Oracle don’t cut it, sorry, too fiddly and hard to insert and retrieve out again. Besides, they answer a different problem about composite data types. Problem is I need to run PG inside Cygwin on my XP machine and it hasn’t worked for a while, I discoverd that I need to run something called cygserver but it won’t play. There is now a native Windows version (have a look on the site here) but I need some time to investigate it. I’ve downladed MySQL as a temporary stopgap but don’t like it. Transactions and other stuff you need are relatively new: Postgres and Oracle have had them for as long as I can remember. MySQL is (I believe) mostly in-memory which makes it fast, but what happens when things fall over? Maybe it’s just my old-fashoined, data-centric training making me want stronger medicine than MySQL, I know it works very well for lots of people. I just want something stronger that suits my purist leanings, describe a table and you can see that a given column has a type of ID or Adress_line, you know what it’s for; what use is integer or varchar2(256), where are the semantics? Also change the domain and you know all of the related tables are OK. That is the way it should be done, not by relying on a tool like Designer or some external XML document that is used to generate scripts to align domain-related columns – rubbish, a waste of time and energy.

Amazon

Whacked 25 old computing books up on Amazon, I’ll give them a couple of months to sell and then bin them. I was holding on to a load of old Unix, Prolog, C programming, Smalltalk, Forth (from 1985!). I also inherited my mother’s poetry collection, which I will sell on too, but suspect that a ruck of paperback poetry won’t sell.

Ah well, off to bed. G’night all.

PS – I suspect I’ll be lookng at Python too, maybe to replace Awk as my text-processing “quickie” tool. Not sure yet.

Mail to Paul Graham

In response to this

OK Paul

You’ve persuaded me to look at Python. I must admit I use Gawk a lot and I’ve made my windows XP machine into a Linux one by installing Cyngwin. I use Vim all the time, I find the way the vi navigation lets me get to the end of a word, or delete up to an underscore Just Works. This is by far more productive for me, even though I spend a lot of time writing PL/SQL and use the TOAD tool. I find I use TOAD for browsing stuff but need a decent editor with RE’s and callouts to Awk to be productive. I will probably migrate my Awking to Python. PL/SQL is Ada without the interesting bits.

Anyway, I half agree with what you say about Java being “for the rest of us”, but the interesting thing is that there are a lot of cool(ish) projects, particularly Apache Struts and Jakarta, that give you a lot of leverage if you are looking at solving some kind of web-based problem quickly, and it’s all open source. If I have a problem in Java I can usually find someone else has solved it in about 10 minutes using Google.

One of the guiding principles of J2EE was that people wouldn’t need to know how to program with threads, for example, and I don’t think this is necessarily a Bad Thing in and of itself. Most of us have to solve boring business problems for a living and we want well-defined architectures that will take the weight and let us get rid of them as fast as possible. I confess I’m still trying to see the point of EJB’s, other than being able to talk intelligently about them at job interviews.

So, I think that when you are being a craftsman it is far better to use more expressive languages (I’ve even worked my way through your book on ANSI Lisp and loved it) but when you are assembling stuff for boring work applications what you want is components you can assemble quickly and others will be able to follow when you’ve gone. That’s the problem, I think.

Ora-20103: Null input is not allowed

Another fine problem to grapple with:

I got this error when I was trying to process a string that was over the limit for a varchar2, which is 32767. What Oracle 9i does is quietly demote CLOB data to varchar2 if it can and then throw one of these exceptions if it can’t.

so you can have, say, small clob is 3200 characters and big clob is 3300:

htp.p(small_clob) ; – – No exception
htp.p(big_clob); – – 20103 not a useful error message really, and the call stack looks wrong too

I was trying to output the CLOB from the HTP package and it choked on it. I give to the world this noddy procedure I wrote that solved it (8i people beware, substr does not work on CLOBs before 9i, you’ll have to use dbms_lob). 

  — Local procedure that will put a CLOB using the HTP package
procedure put_clob( p_cl in out nocopy clob ) is
l_buffer varchar2(32767) ;
k_max_size constant integer := 32767 ;
l_start integer := 1 ;
l_cloblen integer ;
begin
l_cloblen := dbms_lob.getlength( p_cl ) ; — actually, length() might work with this in 9i, try it
loop
l_buffer := substr( p_cl, l_start, k_max_size ) ;
htp.prn( l_buffer ) ;
l_start := l_start + k_max_size ;
exit when l_start > l_cloblen ;
end loop ;
htp.p;
end put_clob

The in out nocopy thing is more efficent, allegedly.

Don’t forget this can get even stickier with database columns, varchar2 is still only 2000 chars. I wish Oracle would just have one character stream type of indeterminate length (well LOB types are limited to 4GB, but you know what I mean). Allowing you to interchange varchars and clobs is OK, until you get weird errors like these, which only became apparent when a piece of dynamic html got to 33000 characters. Of course in 8i interoperability of varchars and clobs probably wouldn’t be allowed; maybe it was better?

I’ve also had this exception when calling a function over a database link. If there is an exception in the function it throws one of these errors. The real exception was in fact No data found, but I need to look at the code in more detail to verify this, perhaps the execption was being caught and what we were getting back was a null.

Debugging 404 errors in Portal and mod PL/SQL

This was a weird one that took me hours

Something stopped working. It was now giving me a 404 (page not found for the unititiated) error.

An HTML form was calling a procedure that was constructing a magic URL that was being used to redirect things back again and pass some arguments back to the portlet.

I used the excellent facility in the Firefox web developer add-on that allows you to turn posts into gets so I could see what it was trying to do. This also shows the hidden fields as well, fantastic.

I changed the procedure to just dump out the arguments it had received into the browser and then return.

I then trimmed and messed with the URL for a while until it did something. Then I added things back in until it broke.

At first I thought it was something to do with using PL/SQL table types (which has always worked as far back as I can remember).

I finally tracked it down to the procedure referencing types defined in a package that is in another database, on the other side of a DB link. I changed the procedure to only use locally defined types and it started working. It seemed to sometimes work if I just took out the tables but then it stopped completely.

Now, I couldn’t do this for the production version because we’ve literally just shipped it. Also, it was working when I tested it a couple of weeks ago, unless I’ve gone completely mad.

I have 2 client databases with different DB links, one is 9.1.x, the other 9.2.×. The portal infrastructure db is 9.2.×. I discovered that if I rebuild (not recompiled but reloaded the code) the package in the remote 9.2 db it works. It won’t with the 9.1 one. Probably something to do with caching PL/SQL but there’s nothing in the log files, even if you try and turn the logging on, which didn’t work for me.

Of course, the long term solution is to change it to use local types but at least I can get things running if there’s a problem out there in the wild.

Oddly the Portal server has not fallen over on me for ages since my last post. Weird.

Added 12 April 2005 we discovered that the constant falling over was due to a lack of disk space.

They always said I should be certified

I got my Java 1.4 Certification at the end of January. Now I can move on and look at the more interesting certifications. I think the next one will be the Business Components one. I need to write off to Sun to get the logo.

I thought maybe I could do some J2EE stuff through Oracle because we get a discount but all I could find was the usual Oracle tools stuff which I’ve been doing for nearly 20 years.

Paddled the river Crake on Saturday. Not bad when it has some water in it. My forward paddling is rubbish. Because I shepherd groups down rivers I’ve got into the habit of sitting on a low brace and watching other people. If I want to improve I’m going to have to do a lot more me paddling on grade 3+ water. To that end I went to the Tryweryn on Wednesday (we were going to do the Conwy but no water). Colin helped me a lot and I’m now doing much better. I need to keep it up if I want to get anywhere though. Was paddling my Dagger Redline which is quite a bit longer than the playboat and will actually get up waves and things. I enjoyed paddling it a lot more than I thought, which is interesting.

Oracle Portal/9iAs is a pain in the proveribial

I’m really struggling with 904. It keeps locking up. I think it’s something to do with using session variables in PL/SQL. It’s very hard to keep up a sustained development effort when you have to reboot the server every 20 minutes.

Rosie’s Birthday Party

Festivities started on Saturday when Rosie’s mum took us to an excellent meal at Oriental Delight where several beers were drunk. On Sunday the party was muppet themed and we got into the swing of things quite well, with me as the swedish chef (hat and rubber chicken), Rosie was Animal, Katherine was Beaker, Deb Miss Piggy. We now have enought chocs to stock a small shop and we’re both trying to lose weight.

Old Friends

Met an old school friend with whom I hadn’t parted company on the best of terms a couple of weeks ago. It was nice to see him and talk through old times and people. It’s interesting how we both hate a lot of the same things and at least some of my enemies (who he still keeps in contact with) have mellowed into reasonable folk. Nice to catch up, it’s a shame he didn’t make Rosie’s party but I suppose he might have felt a little out of it.

Buddhism

Going back to this again. Unfortunately Lama Jampa has moved to London so it’ll be difficult to get to him to ask for advice. I will write him a letter. One of my relatives was quite sarcastic about my beliefs which made me quite angry. Maybe if they had ever seen something worthwhile through to the end I could take it seriously. I have come to the belief that any connection with this tiny foolish life and an enlightened being somewhere downstream of me is very tenuous. This doesn’t mean one should give up, more that what you have now is even more precious.

I came up with a personal mission statement the other day:

Spend the rest of my days helping other people to succeed in between having lots of fun!

Blessings all

Letter to the Register – Tsunami man in prison

In response to this:

Hi John

While I’m sure a lot of people would feel very angry at the way this idiot behaved, and I agree with them, I think that his sentence is very harsh. Drink drivers who kill people often get less than this – it’s on a par with the billions of dollars fines and lengthy prison sentences for spamming el Reg reported some weeks ago. I think there needs to be more of a sense of proportion. If taking a human life has a lower penalty than playing a nasty malicious prank then there’s something wrong.

Regards

Francis Fish