Pages

Monday, December 24, 2007

Lego Star Wars - Problems with wide screen

A little while ago I bought Lego Star Wars to join my other copy, Lego Star Wars II.
There were initially some problems getting the joystick to play nice, but after removing the override settings in the joystick configuration and deleting the SWLEGO.BIN file, everything was sweet.

Until I noticed issues with the screen resolution. You don’t actually get to select what sort of wide screen you want to display, some how it just picks it up for you. I would set the screen detail to max (1600×1200), quit, start the game up and somehow, it was displaying 1920×1200. I could tell because it wasn’t shifting my wallpaper on my second screen like some low res games do (Starcraft for example).
You would think this would be alright. Except the next day when I would play the game, it wasn’t wide screen anymore. It wasn’t even 1600×1200. It was back to the simple 640×480 mode. When I set it back to 1600×1200, quit and re-open: it would be at 1600×1200. I was missing out on the wide screen.

Solution
After deleting the SWLEGO.BIN file a few more times and making sure that it was reproducible (at least on my machine) I worked out that I could copy a certain version of the SWLEGO.BIN file (when I had changed to 1600×1200 for the first time) and it would start up at the right resolution with widescreen. I was about to head over to the Batch file section on the wiki to write me a script that would do the copy automatically (not much really) when it dawned on my *make the file read only*. In the process, I was concerned that if the program was writing to this file on startup, a read only config file may cause it to barf. But it didn’t. It’s great. As long as I don’t have to change anything else I should be set.

Finding help on the game has been a little difficult, as the official website http://www.legostarwarsthevideogame.com/ doesn’t seem to be configured.
The first time I visited http://www.eidos.com/ to see if there were any patches or forums I was running into trouble on a) how to find the game and b) where are the on the page are the downloads. On second viewing (when writing this post), it seems a little more accessible.

One thing I found funny in the readme
Make sure you do not have any Anti-Virus utilities (like Norton’s AntiVirus) running resident prior to playing LEGO Star Wars.

Is this really the sort of things that professional companies should be pushing?

Anyway, I hope that someone else finds this interesting. I’ll see if I can raise a bug with eidos or possibly decode the binary file to find out why it is forgetting the screen resolution.

Saturday, December 15, 2007

Another toy

Who needs words when you have a picture like this…

This should keep things interesting for a little while although I really need to find a good place to put it.

For all of you following the progress of my broken helicopter, it is still in two, but I know how I want to fix it now. It has only taken a couple of months to work out what I want to do :D

Wednesday, December 5, 2007

Belated last day

My last day at hyro was a little busier than I had hoped. So busy that I had to finish up my documentation on the weekend.
But that didn’t get in the way of having cake.

You may have noticed that the cake was in the shape of some shorts. The joke being that you were eating my shorts. I got a laugh at of some people. Most just thought of it as a typical Russell joke.

The great cleanup has begun, but it was only a small dent yesterday. I love not being in a rush to do anything.

-= Comments
1. Mark | December 4th, 2007 at 9:18 pm
Your photos always get a laugh at of me

2. Daniel Mullens | December 6th, 2007 at 9:11 am
Hey Russler,

Was bored at work so I thought I’d scope out your site again.

Quiting your job? Kudos. Must be rad to turn your back on the man and enjoy a prolonged vacation. And what a way to celebrate - with arse cake…

Probably see you at the Mullens Xmas Festivus.

Peace.

Saturday, November 17, 2007

Working with XSLT

The project I’m supposed to be working on is going to have a large focus on XSLT. So a while ago I looked into it and had a play around.
Then did some XSLT related to the project. All was good.

But you never really learn anything unless you use it for your own requirements. So I thought: “html should be valid xml. I should be able to apply XSLT to a html page and get some values out of it”. The wiki we use at work supports an xslt tag and the page I was going to target was bash.orgs latest page. On my first few attempts, I only got errors.
So I simplified it to use a working example (just to make sure that the XSLT engine was working in the wiki); all was good.
I changed the XSLT to be as simple as possible. still good.
I then changed the source back to bash.org and it failed. Turns out that the site is invalid. Pitty.
I have a feeling that the web will change and become quite interesting when everyone adheres to well formed html.

Anyway, to the interesting point.
At one point, I was parsing an XSLT document as the source of information (since XSLT is well formed XML anyway).
It got me thinking. Could you ever write an XSLT transformer with XSLT? (probably not)
But the funny thing I thought of, the first bug tracking system. If it was done in an agile fashion, version 0.0.1 would only support creating bugs, and the bug list would look something like
* Cannot edit bugs
* Cannot resolve bugs
* Cannot assign bugs to person
* Cannot tell who created bugs
* Cannot distinguish between bug and feature request
ah, distractions. Probably should get back to work.

-= Comments
1. Mark | November 16th, 2007 at 11:03 am
“html should be valid xml. I should be able to apply XSLT to a html page and get some values out of it”
Valid XHTML is XML and you can apply transformations, but HTML isn’t well formed.

“I have a feeling that the web will change and become quite interesting when everyone adheres to well formed html.”
I don’t think we’re going to get there any time soon, when XHTML is actually supported in browsers I forsee a big shift in the way markup is generated and used, XHTML must be valid or it just dies. So people won’t be typing long strings of XHTML by hand but rather parse it with other proccesses that ensure valid, well structured markup.

It’s hard too see where we’ll end up though, while Web Standards is gaining ground - so are frameworks where the bottom line is productivity, and web standards isn’t on their prioirty list. I think we’re going to lose of people to the Flex, good luck parsing that! ASP.NET encourages you not to work with / think about the generated markup, the controls are that abstracted. This is another reason I’m really enjoying Rails at the moment, it generates clean markup, and it encourages best practice in the front-end coding.

But you can still use DOM to walk the tree of a document, even if it isn’t completely valid. Thinking about it you should be able to request a page with HttpRequest and then traverse that with DOM..maybe

xhr.open(’GET’, ‘http://www.bash.org/?latest’, false);
… do things..
var content = document.createElement(’div’);
content.innerHTML = xhr.responseText;

// Get all links In page
var linksInBashLatest = content.getElementsByTagName(’a');

It’s not as efficient or as nice as XSL but if you need to get parts of the document you should be able to it with javascript..perhaps

Wednesday, November 7, 2007

How not to start a long weekend


Low life, pathetic scum.
I think it was done at the Bayswater car park, but I didn’t actually notice when I got in the car to drive it home.

Gaa

-= Comments
1. Mark | November 8th, 2007 at 10:00 am
VINCENT
You know what some fucker did to it the other day?

LANCE
What?

VINCENT
Fuckin’ keyed it.

LANCE
Oh man, that’s fucked up.

VINCENT
Tell me about it. I had the goddamn thing in storage three years. It’s out five fuckin’ days — five days, and some dickless piece of shit fucks with it.

LANCE
They should be fuckin’ killed. No trial, no jury, straight to execution.

VINCENT
I just wish I caught ‘em doin’ it, ya know? Oh man, I’d give anything to catch ‘em doin’ it. It’a been worth his doin’ it, if I coulda just caught ‘em, you know what I mean?

LANCE
It’s chicken shit. You don’t fuck another man’s vehicle.

From hyro to ....

I’ve put this off for a while but it is worth noting now.
Lucien picked up that I added an end date on my employment history on the wiki. Now I get to say why.

I originally join HotMagna, a small agile company that focused on simple Java solutions to technical issues. About the time I joined they were bought out by hyro. Like any joining, there was a little turbulence whilst the company worked itself out and I was happy to sit through it and assist in its transformation. hyros focus has been more on creative solutions and assisting companies in advertising their services.
For the past year or so, hyro has gone from an interest to buying Synergy, acquiring Synergy and starting to integrating their business into the hyro “family”. This is where things started to get hard for me. We now had 3 companies that approach different problems and internally, solved problems in very different ways. Whilst I have no doubt that once the company as a whole works out its direction, it will be an interesting company and place to work; it has got in the way of me coding.
And there focus is definitely on me.

I want to code. I miss the days of Uni where I would wake up early Saturday and code through day and some of the night until I needed to sleep. I can’t do that in a standard business because budget is always going to get in the way.

Many have pondered what I will be doing after I leave. The most direct answer I can give is sleeping in. After that, I’m not sure.
There are a couple of options that I have available:

  • A couple of friends have caught wind of my intentions, and would be happy to work with me (more development).

  • My brother is always looking for more people to join him as an air conditioner architect.

  • I’m tempted to find out how hard it is to make money out of google ads on a website.

  • I could also chase the dream of building entry level websites for small business owners.


I’m probably not going to look for anything in December since most people will be gearing down for Christmas. I am going on holiday with the family in January so I won’t be looking for a job then either.

If I come up with anything else that might be relevant, I’ll let you know.

-= Comments
1. Andrew B Coathup | November 6th, 2007 at 11:45 pm
Leaving your first job is very hard.

Leaving and not having anything lined up is a big step.

Enjoy the summer break. There are companies out there where you can just code. If I had more time in my day then I could do that where I am. Don’t give up the coding.

I know people who have lived the dream and set up there own companies. There is still lots of money (and fun) to be had doing applications for very niche markets. The VB boys did that for all of the 90’s.

Good luck. You have made a big step.

I did the same 2 and a 1/2 years in to my first job and went travelling.

2. Xavier | November 7th, 2007 at 1:20 pm
Nice one. It really annoys me when people complain about their jobs but won’t quit.

Steve Pavlina has some really good articles on making money out of a blog (and life in general), which I’d highly recommend.

Also, come along to the melbourne ruby meetup next thursday. Always companies looking for good people, plus it’s a good crowd to have a drink with. And it’s ruby! Also, I am doing a presentation

Monday, October 8, 2007

I don’t know why cyclists get a bad name

I have nothing against people who ride bikes on the road.
Sometimes it would be nice not to have them there, but they normally don’t do anything wrong.

Then I seen this guy.

Yup, that’s right. On his bike and using a mobile.

-= Comments
1. Mark | October 8th, 2007 at 9:39 pm
You always have a camera at the ready

You just solved a riddle though, this morning I wondered why the exhausts on busses shoot out of the right side and fill my car with fumes.. It’s for the benefit of the one armed cyclists talking on mobiles, I mean he couldn’t possibly stay on his bike AND talk on the phone AND breathe fumes…

2. Matthew Delves | October 8th, 2007 at 11:59 pm
Most cyclists do use a handsfree.

As for me, just as when I’m driving, I refuse to answer the phone.

Thanks,
Matthew Delves

Monday, October 1, 2007

iTunes and meta data

I started out hating iTunes from day one, but I feel that I’m stuck with it to get videos and podcast feeds updated on my iPod video.

I have recently been ripping some of my DVD collection to the machine to keep me entertained.
The application I’m using by default uses the disks name and track information as the default name for an mp4 file. This is obviously fairly useless to someone who pants to pick a clip based on the series I’m ripping and the episode.
Not a problem, I’m used to manually changing invidual items. I’m good at it.

The problem: On a 3meg mp3, the write operation is fairly quick. You blink and the whole file is re-written. Video on the other hand is a little bigger. Using iTunes, this means that I have to wait for the whole file to be re-written before starting to re-name the next file.
This takes forever.
I know with mp3’s the meta-data is at the beginning of a file and I just checked that an mp4 file also has the meta-data near the beginning.
If it had it near the end of the file, it could have at least just changed the end of the file instead of the whole lot :(. But that would mean that anything that wanted to read the meta-data would have to work out how to jump to the meta-data section (possibly taking longer to read)
I guess since reads would occur more than writes, the file structure is read optimised.

Bah.

-= Comments
1. Zooba | October 1st, 2007 at 11:34 am
As I understand, ID3 tags have fixed length fields, which means once the tag has been created the whole file doesn’t require rewriting to modify it.

Possibly an MP4 has a similar structure, in which case getting your ripping software to put a dummy tag in the video will mean you won’t have to rewrite the entire file to modify it later. Having said that, I’ve never played around with ripping videos, but it does work with MP3s.

Saturday, September 22, 2007

Just not thinking in portals

The last few days I’ve been looking into portals and portlets, specifically JSR168 compliant ones.
Reason: Our new intranet runs as a portal and they would like some additional developers working on it.

So I started looking around. The concept is really cool. You have a site the displays content: The portal. It provides things like authentication and page layout. You then have portlets that display information. They rely on the portal to provide a way to store state and session information, but they can do anything else you want with them. They don’t have to worry about how they are presented, just that they present some information.
In the world of cool ascii:
______________
|    PORTAL    |
|  ___    ___  |
| |   |  |   | |
| |___|  |___| |
|____\____/____|
      \  /
    PORTLETS
I had a look at a few of them (pluto, jetspeed, liferay, uPortal) and was disappointed from a development point of view. I have grown fond of the hot code replacement when developing j2ee application with tomcat. I would be able to debug and change logic. I could update jsps and have them recompile the next time I hit refresh in the browser. It is great. I wanted to do the same thing with portlets since it is really just an extension of servlets.

Pluto is the apache reference implementation of a portal server. It provides the basics to get a portlet running and visible on screen. Sounds like just what I am after. Unfortunately, to get portlets deployed to the portlet container, you have to provide pluto specific configuration information for pluto to detect your portlet. This is going to hinder development rather than assist.

Jetspeed was really easy to setup and get going. I had a play around with this one a little more because it was really easy to get into. Layouts where easy to play with, colours, portlets where all just simple to add to the page. From a site building tool perspective. It was great. I deployed the testsuite from the Pluto project to find out what it was like deploying additional portlets. Deploying was ok. But when I started testing these portlets, performance seemed to have taken a walk. My cpu usage would just skyrocket for a few seconds and then stop when the page returned. Whilst Jetspeed didn’t have to have any specific configuration information in the portlet to get it to load, the only way that a portlet does become registered is if you deploy to the portlet container. This means every time I want to make a change, I have to bundle my portlet and deploy. This would also hinder development rather than assist.

Liferay is very similar to Jetspeed and I feel sorry that I am discussing it after Jetspeed because I am just going to brush over it. I played with it for a while because it had the same usable simplicity that came with Jetspeed. The only difference I noted was that when I deployed the testsuite, it didn’t seem to suffer the same performance slowdown. Since I still have to deploy every time I make a change to my application, it’s not going to help development.

I couldn’t get uPortal to work out of the box, so there is not really much I can say. But it does raise an important point. If you have something that you want the world to use, it has to work out of the box. You have to be able to download, unzip and start. The hypersonic database is really cool for providing a light database that works just connecting to it.

So I was disappointed. I couldn’t believe that I had to jump through hoops to get an portlet to be recognised by the container. So I spent some time looking into how why they can’t determine the portlet information automatically. ServletContext has a getContext call which takes the context path, but it doesn’t seem like there is a way to find out all of the contexts deployed to the application.

So, there is my rant on Java portals and portlets. Most of the information I’ve been reading is from 2003-2006 which is kinda disappointing. Either I am looking in the wrong places or JSR168 portlets haven’t taken off. I am going to take a second look to see if I can find a way to list all of the contexts because when I first looked I thought I seen an old method that has been deprecated and just returns null, but now I can’t see it.

-= Comments
1. Xavier | September 30th, 2007 at 10:19 pm
oh god we used Oracle Portal with portlets to build My.Swinburne and there were so many headaches. Maybe that was the oracle bit and not the JSR bit. It was a while ago so I don’t have any useful criticism save to say I’m sufficiently burned that I’m staying well away from any job to do with portlets…

Sunday, September 16, 2007

Nothing but net

Mum asked me today if her phone added a timestamp to pictures she took.
I checked it out while she made a hot drink.
Found out how to do it and went to show her. As I was pushing the up key to get to the right menu, the phone slipped up my hands. I fumbled to grab it but just couldn’t get a good grip.
Then it landed in my hot chocolate.
I cursed. I took a moment to laugh at the situation then cursed again as I realised I should probably make an effort to get it out.
Covered it in tissues and rushed to pull it apart.

I let it sit in the tissues a while. I cleaned the dried hot chocolate off the phone and put it back together. The first time I turned it on, the camera didn’t work. I still had to put some screws in so I pulled it apart, cleaned it a little more, did the screws up and turned it on again. Camera works again.
There seems to be a little bit of a smear on the screen and it doesn’t seem like the speaker is as loud as it used to be, but it seems like everything will work.

Not the way I wanted to start the weekend :(

-= Comments
1. Matthew Delves | September 16th, 2007 at 4:10 pm
You are fighting a loosing battle my friend.

The phone won’t last too much longer no matter how much you try.

Thanks,
Matthew Delves

Wednesday, August 8, 2007

Welcome to the family

And the lastest to join the collection (the one on the right is the new one):

Another Dell, 17″ Dual Core 2ghz (64bit this time), 2gb ram, 512 mb video card, 80gb HDD, all the wireless options I could get and lots of light :D
The XPS feels really nice. There is just something different about the keys (althought it could just be the new feel).
I’ve tried Vista. I’ve customised it back to the win9x L&F but it just doesn’t feel right.
I always envisaged formatting it and putting linux on it, but it was worth a try.

Tuesday, July 31, 2007

Zombie processes and Forward momentum

I’ll get the easy one out of the way first: Zombie processes. This morning, it felt like someone flicked the switch because I feel like a zombie. 15th day programming without much of a weekend and I think it is starting to take its toll.
It does sort of lead onto the second thing though: Forward momentum.
A while ago, I started build one of my lego models:

And because that was rather relaxing, I built my spaceship:
So, from the looks of things, you would thing I was powering forward. My biggest drawback is that I still haven’t setup my server. It is sitting there, ready to go. Just got to get it up and running.
I was looking at writing a java port forwarding program just for the joy of writing something that requires a lot of thinking power. Given my current progress, I think I should just bite the bullet and use standard configuration items.

-= Comments
1. Xavier Shay | July 31st, 2007 at 2:06 pm
LOOKOUT YOU CAN’T PRINT ON VIDEO GAME CONTROLLERS

2. Jonathan | July 31st, 2007 at 9:31 pm
*

1. Xavier Shay | July 31st, 2007 at 2:06 pm

LOOKOUT YOU CANâ'T PRINT ON VIDEO GAME CONTROLLERS

Ok, I laughed. God how I miss lego.

3. pimaster | July 31st, 2007 at 9:36 pm
Ah, so that is what I have been doing wrong.
oh, I forgot I clipped out the picture of the cups test page.

Wednesday, July 18, 2007

A physical weekend

So another weekend passes by. I didn’t do any coding this weekend as I was assisting my dad with installing some poles for a shade sale that we are putting up in the front lawn to give some protection to the cars.
It has been a while since I did some heavy lifting and manual labour, but it feels good. You can stand back and enjoy what you have built.

But there has been one thing bothering me this weekend. Friday afternoon, one of my colleagues put in an email a discussion of how we are currently tackling software problems.
In one short sentence, stated that MVC and OO design principals do not work together. I thought for a second: “I’m writing objects, I’m keeping logic separate. I am making them work together, what is she on about”. Moments later and a little more reading (and thinking back to Uni days): “MVC keeps business logic away from the business objects. OO is meant to have methods that modify the model close to the model. We are all taught that a Bird object should be able to fly (OO). You don’t pass a Bird thing to a Bird controller telling it to ‘make it fly’ (MVC)”.

Quite honestly, I’m a little lost. You can’t change your whole approach mid-project (especially when you are half way through and have 2 weeks to go), but what am I going to do after it?

Where do I begin?
It almost feels like everything I have learnt has just flushed out the ears…
Somewhere I am hearing “What works for one project may not work for the next” :D

-= Comments
1. Matthew Delves | June 18th, 2007 at 7:52 am
From my limited understanding of MVC, you would have a bird that knows how to fly, it is then the controller that tells the bird where to fly to.

Hope this helps.

2. Xavier Shay | June 18th, 2007 at 2:22 pm
Controllers are responsible for the “flow” of the application. In web based apps, 90% of controllers either just render something, or save a model then redirect based on the result (success/failure). Controllers are glue, and you want as little of it as possible.

(In the rails world, this concept is often referred to as skinny controller/fat model)

3. Xavier Shay | June 18th, 2007 at 2:24 pm
… and remember, you generally want one model per view/controller action, so if you need a composite form or something, look into the Presenter pattern.

4. Zooba | June 18th, 2007 at 7:25 pm
I agree with Matthew, that’s how I understand it as well. At least in OO terms.

If you apply MVC to a RDBMS your business logic is kept in the controller with the data/information kept in the entities/tables.

The issue here seems to be the divide between what is the controller’s responsibility and what is the object’s responsibility. IMHO, the entity should have entity logic while it is the controller that has business logic. To carry on with the previous example, a Bird knows how to fly, but the controller knows (and tells the Bird) when and where to fly.

5. Xavier Shay | June 19th, 2007 at 2:00 pm
No way … what is the point of having a Model layer if your model is just … data? A PurchaseOrder should encapsulate the “business logic ” of what happens when it gets paid for.

I don’t like the bird example … you don’t model a bird in software and it doesn’t map to real systems.

Friday, July 13, 2007

Email comments. Commenting in emails

I need to write this post so that I can remember to use it in the future.
Email addresses are allowed to have comments in them.
<username>+<comment>@<host>
[Edited 19-07-07 as I forgot to escape the >’s]
You can even include multiple +’s (or (\+.+)+ for those among us that love regex)

Just incase you can’t form the right query in a search engine, here is the very useful blog entry I came across:
Anders Jacobsen’s blog

-= Comments
1. Xavier Shay | July 13th, 2007 at 2:56 pm
Rule #1: Don’t ever use a regex to match an email unless the author provides RFC compliant tests. There are so many shit email regexes on the internet AND IT ANGERS ME

Thursday, May 31, 2007

one language to rule them all…

And no, it isn’t java:
lolcode
[java]
HAI
CAN HAS STDIO?
I HAS A VAR
GIMMEH VAR
IZ VAR BIGGER THAN 10 O RLY?
YA RLY
BTW this is true
VISIBLE "BIG NUMBER!"
NO WAI
BTW this is false
VISIBLE "LITTLE NUMBER!"
KTHX
THXBYE


Finally, a programming language that can be understood :)

-= Comments
1. Jonathan | May 30th, 2007 at 7:29 pm
Well, maybe one day they’ll over degrees in lolcode.

2. Mark | May 30th, 2007 at 10:28 pm
O RLY? cracked me up :)

Wednesday, May 9, 2007

1 cats, 2 cats

I just faced a pluralisation problem at work today.

I then realised that I had no tools to combat it.

Looking around I found a really good paper that I want to re-read (hence this post)
Algorithmic Approach to English Pluralisation

I thought spring hand some nice ways to handle it, but I can’t remember if I read it or just imagined it

Looks like I might be writing my own tool again.

-= Comments
1. Xavier | May 12th, 2007 at 4:22 pm
pluralize(2, “cat”)

Rails has this problem solved, if you’re writing java code yourself you could do worse than porting their code. There’s also a really neat library around for things like creating lists (”cats, dogs, and aeroplanes”), but I can’t recall its name.

2. Xavier | May 12th, 2007 at 4:24 pm
(check the “Inflector” class in the rails docs)

3. pimaster | May 12th, 2007 at 9:54 pm
Cool.
The only problem I foresee is that is an english only solution.
Java has message formatting via the usual
“I have {0} message”, 3
If I could have something like:
“I have {0} {message|messages}”, 3
I’d be a happy monkey

4. Xavier | May 13th, 2007 at 11:55 am
You can customize the Inflector class in your configuration for specific words it doesn’t know about (Ox -> Oxen), not sure if that solves your problem.

5. Andrew B Coathup | May 17th, 2007 at 8:27 pm
email is the singular and the plural. emails is not a word. Just thought this was a good place to have a wee rant.

Rant rant…

Ok, I am done now.

6. Hari | May 19th, 2007 at 8:22 pm
Of course emails is a word.

Which sounds better: "I sent you three emails yesterday” or “I sent you three email yesterday"?

Monday, May 7, 2007

Tackling the elusive goto

Obviously this is in response to Zooba’s post Break/Continue vs. Goto. Whilst I don’t consider myself a purist. I do not like the idea of using explicit gotos.

The first thing I want to spell out is that eclipse will happily tell me where the break is going to drop to. True: if I change an if to a while, the location of where that is going to go will change but if you are changing an if to a while, you are probably going to have to fix a lot more that where you drop out to. The delphi IDE I was using at Advatel (can’t remember the name of it though) would also tell me where breaks would jump to when the break word was selected. With a nice little addon, it would also draw coloured lines on the screen.

As for simplifying the code. I actually managed to get it shorter than your goto example.
[java]
do {
for (int i = 0; i < 100 && getMeOutOfHere == false; i++)
{
p += 8; // or some constant
if (p < eof && DoStuff(i, j))
{
j -= 10;
}
else
{
getMeOutOfHere = true;
p = eof; // if the presevation of p to eof IS required
}
}
}
while (getMeOutOfHere == false);

One thing I am having trouble with though is when to subtract 10 from J. In one instance, you state:
[java]
if(DoStuff(i, j) == false)
{
getMeOutOfHere == true;
break;
}

Which obviously breaks if DoStuff is false. In the next example, it breaks if true:
[java]
if(DoStuff(i, j) == true)
{
goto getMeOutOfHere;
}

But seeing as these are examples: we can probably just ignore it.

Final word:
The reason I wanted to use a neat, non-goto method is Zooba’s reason for writing his post: “The point of this whole post is that goto is not evil”. By analogy, neither is a gun. But both can be used in evil ways. At least breaks and continues are limiting to the loop they are in. goto can obviously jump around a lot more. break will always go to the bottom of the loop. continue will go back to the start. Where does a goto go to? Anywhere: hence the name. I’m sure an IDE will let you jump to the location. I’m sure a skilled programmer can use it to their advantage. Unfortunately, not every programmer that makes it out to the world has those skills. Eventually that code then has to be cleaned up and maintained.

-= Comments
1. Zooba | May 6th, 2007 at 3:47 pm
Okay, you got me on the typo. I’ve fixed it. That’s what happens when you copy-paste and then only fix in one occurrence (hence you shouldn’t copy-paste code - put it in a function).

Aside from the fact that your simplified code will not work (read mine again, I’m not doing ‘p += 8′ anywhere, which brings up another typo, all the ‘j’s should have been ‘p’s) I don’t believe it is any shorter. Short-circuiting conditionals which include side-effects also introduces more to think about while you’re reading.

I’ve never noticed Eclipse show a break destination, but I don’t use it often. MS VS definitely doesn’t. Maybe I’ll have to grab the latest Eclipse and have a play.

The fact that break and continue have destinations specified by the language introduces more confusion when using them. My later examples show that it is impossible at a glance to see where they will go. Good use of goto prevents this. Including BASIC-esque comments such as “} // end while(x > 0)” may also help, a comment such as “// The BREAK above comes here” helps slightly more, but when you’re faced with deciphering indentation and braces, a fixed location is considerably more helpful.

2. pimaster | May 6th, 2007 at 5:17 pm
When I seen the while loop that was just incrementing p, and breaking on every 8th line, I thought the best thing to do was a p+=8. Now that p is being used elsewhere, I would have to look over the function again. But I’m not going to.

it is a fair point you raised about the boolean short cutting. If I was really writing the code, I would not have done that.

I feel that I’ve done a good good of cleaning up the code without using gotos. For me to right the thing properly, I would need to know what the task at hand is (Some sort of pseudo code?).
As it currently stands, it looks like the code scrolls backwards through a file. I want to know what happens when p becomes negative.

3. Zooba | May 6th, 2007 at 6:22 pm
The main problem with the ‘p+=8′ is that the loop actually rounds ‘p’ up to the next multiple of 8. Simply adding eight is a different behaviour altogether.

In fact, it is a completely different behaviour. Since p is a pointer to an int (assumed to be a 4-byte integer), every second increment will make it meet the condition of the loop. Adding eight will actually move the pointer by 32 bytes, rather than the 8 intended. This is partially my fault, as I intended the increment to only move it by one byte.

p going backwards by ten is totally arbitrary, I have no idea if it means anything or not, I just made it up. Since p is a pointer it is more likely to go outside of a valid page before it becomes negative, either of which will cause a crash that isn’t caught by this snippet and quite likely isn’t caught by the application anywhere. The example isn’t meant to do anything, I was basically making up a combination of loops and conditions that would help illustrate my point. I feel that my second set of examples is more powerful.

4. Gatesy | May 6th, 2007 at 11:37 pm
The fact that break and continue have destinations specified by the language introduces more confusion when using them. My later examples show that it is impossible at a glance to see where they will go.

Java allows for labeled loops & breaks, so if you were worried about readability you could always label the loops so that it was clear what you were breaking out of…

5. pimaster | May 6th, 2007 at 11:44 pm
Gatesy, that is something I did not know.
For all those that want a read (as I did) Java Documentation on Breaking
But is this much better that a goto? I think only slightly. I allows you to jump to any one of many looping statements, but at least it still limits you to the loops.

6. Gatesy | May 6th, 2007 at 11:56 pm
It might be only of minor usefulness, say for breaking out of two loops without needing an extra flag variable, but it’s still more maintainable than gotos.

On the other hand, if you build an app full of gotos, you might just have job security for life!

7. pimaster | May 7th, 2007 at 2:33 pm
I just wish I could remember where I seen:
If you are required for the task, you can never get promoted.

8. Zooba | May 7th, 2007 at 6:53 pm
I don’t think that’s better at all. I find it horribly counter-intuitive. You label something and go somewhere else? Also, it doesn’t come anywhere near solving the lots of braces problem.

“if you build an app full of gotos, you might just have job security for life!”

This is the reason that goto isn’t taught, or, if you prefer, is ‘banned’: People take things to extremes (”app full of gotos”) and the response is equally extreme (never ever ever ever ever ever ever use gotos).

Goto fits in the same vein as globally scoped variables. Both have their uses, however limited, and there exist cases where one of these is cleaner and more readable than the alternatives (unless the reader has had this part of his/her education skipped). Banning either of them outright forces people to write, and later decipher, unnecessarily convoluted code.

9. pimaster | May 7th, 2007 at 8:33 pm
Please don’t tell me you are going to sit there and state that “globally scoped variables” are sometimes useful?

Constants: yes
Variables: no

10. Andrew Walker | May 8th, 2007 at 10:08 am
I agree that for large team projects globals can cause problems, however I’ll be more than willing to back zooba up on this one.

Global variables if used correctly can simplify design, reduce development time and remove unnecessary performance degrading abstractions.

One good example is how python and lisp code make use of globals for factories and loggers. This removes the necessity for abominations like the singleton pattern.

11. Zooba | May 8th, 2007 at 6:45 pm
Globally scoped variables are sometimes useful.

Of course you always have to weigh the benefits against the potential problems. There are definitely more ways to use them wrongly/dangerously than correctly/safely, but the fact remains that there are some situations that best suit a global variable.

I’m not denying that there are ways of getting around this. All I’m denying is that any way not involving global scope is better. Same deal with goto.

Friday, April 27, 2007

Java Gotcha - Set.add(obj)

I’m going to use this post as a reason to start a new category: gotchas.
We all know they exist and they are a pain in the neck. The best way to learn from them is to let everyone around you know about them as well.

This one is for Java. The Set.add() javadoc states:
More formally, adds the specified element, o, to this set if this set contains no element e such that (o==null ? e==null : o.equals(e))

The gotcha here is that an implementation I am using: HashSet, will only consult the equals method if the two objects have the same hash code.

I’m using: org.apache.commons.lang.builder.EqualsBuilder and org.apache.commons.lang.builder.HashCodeBuilder to keep the hash code and equals code nice and clean.

1. Fuzz | April 26th, 2007 at 3:15 pm
You posted about Big Brother being your project… then a gotcha’s section…

So can we assume that the security issues they were having may have been your bug?

Nice site anyway

2. Zooba | April 26th, 2007 at 7:26 pm
A hash code is (intended as) a unique fingerprint for the contents, ie. no two different objects should have the same hash code. An easy optimisation is to compare hash codes for equality before doing a deep compare.

The only way this is a gotcha is if the equals method has side-effects. In this case, the gotcha is worse, because the equals method will be called for each item which already exists in the set.

Not convinced…

3. pimaster | April 26th, 2007 at 8:12 pm
Zooba, I was just trying to point out that the HashSet does not follow what the javadoc says it is meant to do.
I know that it is fair for the HashSet to check the hashcode first, but it would have been nice if it was documented.

Fuzz. I was part of the team that worked on BB. The security issue is not related to this gotcha. It was a small issue with the latest videos that are shown on the site. I also helped with the news section and the searching. I was also working on some of the caching which keeps the site snappy.

Unfortunately I don’t think I’m at liberty to talk about the security issue. Big problem, simple cause.

4. Zooba | April 26th, 2007 at 10:33 pm
Your sample of javadoc is from the Set class, not the HashSet class. The HashSet documentation for add simply says:

“Adds the specified element to this set if it is not already present.”

The small code snippet is simply a convenient way of explaining to programmers how the algorithm works without resorting to an overly verbose description. Personally, I think the only gotcha here is that the comment has been interpreted as the actual implementation.

5. pimaster | April 26th, 2007 at 10:50 pm
Isn’t that the definition of a gotcha, thinking the documentation reflects the implementation?

6. Zooba | April 26th, 2007 at 11:53 pm
It does reflect the implementation. The snippet “(o==null ? e==null : o.equals(e))” reflects the condition for an item being added is that there isn’t an item already in there which is equal to it. The fact that this condition is expressed in Java does not mean that the actual code looks like this:

[java,N]if(o==null ? e==null : o.equals(e))
{
// add item
}

That is a case of the documentation being the implementation. It is foolish to assume that documentation requires no interpretation. Even more so when the documentation belongs to an interface rather than the class in question.

7. Zooba | April 26th, 2007 at 11:56 pm
Well, apparently I don’t remember how to get syntax highlighting to work correctly. I also accidentally negated the action. Hopefully when the condition is true the action will be to stop searching through the set and return false. The rest of my comment is valid, it is only the comment in the code that is incorrect.

Monday, April 23, 2007

"Secret Project" goes live

So, today is the culmination of an 8 week website that launches with the TV show.
For those of us that have a life: Big Brother.

The site has come together really well, with just a few minor issues in integration.

I sit here in the office preparing the first load of data to go into the system and stretching my fingers for when things need to be tweaked.
The largest hurdle to get over with this site is the large number of users that will be hitting the site. We think that we have got the site as lean as possible. There will be an initial hit when everyone has to download the css, js and images; but after that it should be smooth sailing.

If anyone is interested in what I know about the house: the answer is nothing.
As developers: they never released any real data to the dev site.
I have no interest in following BB.

Seems like the site has been completed (for launch). Pity I didn’t get the girl (probably needed to look for one if I wanted that to happen. Had to work hard to see the site launch)

Monday, March 19, 2007

Secret Projects and Tight Timelines

Probably something I should put in two posts. Since I haven’t had the time to update this clog though, if I don’t write them, one of them may get missed.

Currently working on a project that is not allowed to leave the confines of the office. I have usually been able to generalise the problem when I’ve pasted code before, but this time it would seem like I could give something away. I shouldn’t find any "interesting" code examples anyway since I only have time to work on my parts and my parts should contain no flaws :).

The next issue is the looming pressure of a very hard release date on the project that didn’t have the right amount of time to get it done in the first place. Everyone that works in IT knows that this is just a huge red alarm, attached to a bomb that is waiting to go off.

To me it is just a challenge that may be possible to meet. My current problem is that I’m the only one that wants to try to impress the customer. It would seem that everyone else is just coding at a standard pace. They know that the original timeline is a shocker and that is not their problem.

I was able to get a little bit of time into the challenge that mark pointed out but only got the layout right. My creativity this weekend was 0.

-= Comments
1. Jonathan | March 19th, 2007 at 10:52 am
Well, just remember that all bombs get stopped one second before they explode. And then he gets the girl.

You might not get the girl, or even the bomb, but good luck anyway.

On review, this sounds very much like a horoscope. Vague, meaningless, but can be applied to every possible situation.

Saturday, February 24, 2007

Simple Code - percentages

I was trying to work out a percentage of one value against another:
(int)((double)num/den*100)
Lots of conversion just to get an int value representation of a percentage.
Simplified:
100 * num / den
Solved.

Friday, February 23, 2007

Go Beryl

My clog has been missing pictures, so here are some which show off my current desktop (FC6).
The reason I took the first one is that I thought it was funny the way xmms was behaving when I applied water effects to the window.
This inspired me to take some more screen shots. The “cube”
And my burning effects on close window:
When I closed this screen shot, I thought the double burning effect was also cool, so I took another screen shot:
And what is the result of having all these effect you ask? 1/3 the battery life and a reason to show off.

-= Comments
1. Xavier | February 23rd, 2007 at 4:28 pm
Dammit, I haven’t been able to get Beryl working
Granted, I haven’t tried too hard, but I’m not keen freezing up my gnome session too often.

Wednesday, February 14, 2007

Java Thread Stack performance

The question came up at work the other day on how to solve problems with threads ‘losing’ resources. In particular, I think that threads aren’t release holds on database connections (bad). Basically at some point we run out of connections to use and everything goes to hell.

So, since we have access to the thread objects, I thought that it might be worth while finding where these threads are up to.
Strike 1.
Only Java 1.5 has Thread.getStackTrace(). We are running in 1.4

Well, what would be the performance of doing such a thing anyway.

One way of getting the stack is:
[java]try
{
throw new RuntimeException();
} catch(RuntimeException re)
{
result = re.getStackTrace()[0].getMethodName();
}

Java 1.4 via throw and catch method:
Execution length:1376
Execution length:1258
Execution length:1278
Execution length:1295
Execution length:1285

Java 1.5 via same method:
Execution length:1295
Execution length:1233
Execution length:1238
Execution length:1252
Execution length:1229

Good start: There is little difference between using 14 or 15.

But use:
[java]Thread.currentThread().getStackTrace()[0].getMethodName()
Java 1.5 via Thread.getStackTrace()
Execution length:15938
Execution length:16308
Execution length:12004
Execution length:16804
Execution length:17009

Definitely room for improvement.

Each of the stack elements was queried 100,000 times.
This test was done 5 times end to end.

This test does not answer a tougher question like "if the stack trace is deeper, would it become slower?".
The slower method is the only way (I know of) to access the stack of a thread that is not driving the current code though.

Friday, February 9, 2007

Business problems

Something that I don’t think University can really teach.

It has been something I’ve been observing more and more as my managers start to see me as more than just a programer.

Business A wants Feature B.
Estimate (in $$$) is more than Business A wants to pay.
Business A requests that they really want the Feature.

I know in my life, if I can’t afford a 24″ monitor, I simply won’t have it.
I am aslo very concious of my purchases. If I want a 24″ monitor, I will wait till I have the capital for 2 because I know that there is the possibility of the first one breaking down.

Obviously a business can’t justify this sort of reasoning.

Why would Business continue to persue something that they can’t have without meeting the requirements?

-= Comments
1. Gatesy | February 13th, 2007 at 10:28 pm
"Why would Business continue to pursue something that they can't have without meeting the requirements?"

Because the dudes in management either:

1) underestimate the complexity of the feature they’re asking for

2) miscalculate the supposed benefit of the feature they’re requesting

Personally, I would have thought that if there was such a pressing business case for such a feature, then they should either bite the bullet and pay for it, or ask the developers to leave hooks for future expansion. That way, everybody’s happy: if the developers do a good job there should be repeat business, and the client can phase their system in to suit their cash flow.

But then, I’m only an IT student - what would I know about business?

Thursday, February 8, 2007

Projects and their growing towers

<vent>
I’ve been put back on a project that I thought I was clear of. I’m not particularly fussed about being on it. But they have no viable plan to get the system to where it needs to be. This is not good for me.

A couple of issues have been building up and I am afraid of them just blowing up in someones hands.
* Build Scripts
* Documentation
* Change management

The build scripts are old. Everyone in the software industry knows that most things change, including the way things are built. I’m sure the build scripts were perfect for the initial stages of the system but they haven’t changed since. The problem is that the Owners (notice I’m trying to be generic?) of the project won’t spend any time (and money) cleaning up the outer edges of the project.

The documentation hasn’t really been kept up to date, but since the software hasn’t changed that much it hasn’t caused much of an issue. The problem is managing the documentation. Commiting OO documents to CVS makes it difficult to see changes between versions. It also makes it difficult (if not impossible) to merge documents. I asked around at work and the common answer was wiki. Wiki is good but we would lose things like table of contents (and page numbers), branding, levelled numbering and simple things like bookmarking. I tried to suggest the !boom thing on one of the blogs on byteclub that combines css and html to produce PDF but the overhead of time would probably be too great.

With regards to change management, this is more of a niceity that may come in handy at some point. There is no solid record of what has change and/or why. Since there has been none to start with, it is kind of hard to work out what I should do about it. If I had more motivation coming from the Business behind the project, I might be more interested: but this is not the case.
</vent>

Thursday, January 11, 2007

Recovery (Not Data Recovery)

Monday we were hit by a car (more a truck) and I have spent the last few days getting over the ‘injuries’. Mostly just a sore neck now, but I had sore knees at the time.

Our Car:
The car that his us:
And because we were hit so hard, the car we ran into:

Not the way I had envisaged ending a game of minigolf, but what am I to do. The rest of the family is ok: mum is a bit shaken and coming to a stop a lights will not be an easy thing to do for a while.

I guess I better describe a little of what happened. We were driving down Cantebury road, 5 minutes from home, when we slowed to a stop a fair distance from the lights. There was either an accident up ahead or a truck doing a slow U turn that had cause the traffic to build up. Once we came to a stop, we heard a load screeching coming from behind us. The next thing I know we were slammed forward. I don’t know how long it was before we crashed into the car in front but dad pulled hard left to get out of the traffic. We hit the car in front of us about half a meter from the driver side of the car: we almost missed it. The guy driver the F100 that hit us was an elderly gentleman, that I guess was not quite paying attention and didn’t slow down.

I was hoping to look at setting up my server for CVS that evening and formatting my computer yesterday or today. What I have managed to do is just sit relax and do some stretching. I still need to format my laptop so that it is nice and fresh for when I go back to work on Monday :(

-= Comments
1. Andrew B Coathup | January 11th, 2007 at 10:33 pm
Glad you are all ok. Though you should keep an eye on the whiplash.

You must have been hit pretty hard as F100’s don’t tend to dent easy.

What is the etiquette on displaying someone’s car registration on the internet? I am juggling it in my mind. Still undecided. There isn’t a publicly accessible database that I know of for looking up owners details based on registration.

2. pimaster | January 12th, 2007 at 12:16 pm
I thought about it at the time and I wasn’t very concerned. I have now fixed it up.

3. Matthew Delves | January 12th, 2007 at 5:18 pm
Good to hear you are okay. I would suggest doing a Murcotts ( http://www.murcott.com.au/ ) defensive driving course which is always good. Though would be more applicable to the elderly gentlemen rather than you (or any member of your family). Hope you recovery is swift and you get back on the road quickly.

4. Clinton | January 15th, 2007 at 10:07 am
Yikes - that’s some major energy. Nobody wins when cars start acting like dodge-em’ cars… :( It’s good to hear you and your family are okay - may you never have to blog on this topic again!

5. Joshua Hayes | January 24th, 2007 at 8:56 pm
Being in a car accident is never nice. I remember when my brother got T-boned by a Grey 4-wheel drive at about 90km/h that ran a red light. It wasn’t pretty. The passenger side of the car was pressed into about where your hand break is. The windows imploded, and the windscreen was cracked just about cracked in half. Luckily enough he only came out of it a bit shaken up and a few scratches and bruises.

I’m glad nobody in your family was injured. Oh yeah and Matt I agree, the old man should go for some driving courses :)

Sunday, January 7, 2007

Slow move to linux - Resolving computer names with wins

For a while know I have wanted to make a greater move to linux. My fear has been being stuck without a usable computer (either the replacement would be too slow or the machine would not be in a stable state). Running my laptop on Fedora Core 5 for the past ~9 months has been rather good for testing the waters. I need to reformat the laptop because of issues within the package management ( I tried to get wireless working before it was introduced into the repository, so had to compile from source, also tried to compile alsa from source, not sure why any more ). Fedora Core 6 is also out so I thought I would try to start with a clean slate.

One thing that troubles me is updates are all of the net. If I want more than one computer to be on the same distro and I want to play around with the distro more often, then I need a closer copy of those repositries.

Step 1. Setup Box with those repositries.
I setup a box a while ago ( can’t believe I didn’t blog it ) as a potential server. I’ve setup apache and copied the installers off of the cd into a directory.
The box will update itself from its own server.

Step 2. Connect to the box from another machine.
I have had various problems with this. It is always easy to ping the ip address, but I don’t won’t to be that simple. Enabling samba and wins support in linux is easy enough.
To get samba running you just need to set it as a startup service. There is a services menu item in fedora.
To get wins support in samba, I had to edit /etc/samba/smb.conf ; find ( or add ) wins support = yes

That’s fine. I can do a nmblookup to find the computer name, but why can’t I ping it. I turned on a Windows box and it can ping it, obviously the machine doesn’t know that it can use wins to resolve names.
/etc/hosts is a file to hardcode computer names to ip addresses.
/etc/resolv.conf is a file to specify nameservers
/etc/host.conf I though would hold the answer. Mine has a line “order hosts, bind”. I found out that hosts refers to the hosts file, and bind refers to a DNS lookup. I thought that if I added in there wins I would be set. But it is an invalid entry.

There is another file which took my a while to find (samba doc): /etc/nsswitch.conf. In it is the line “hosts: files dns”
Adding wins in there saved the day (had to restart network services before it was affected of course). I know have the ability (knowledge) to ping the box by machine name. Hazzar. It only took me 2-3 days. Next I think will be CVS. I have set it up before, but need to setup it up on a real machine. Then it will be getting a good sync process happening for the packages (core updates and extras)

-= Comments
1. Jonathan | January 8th, 2007 at 6:54 pm
Oh, cool. I’ve been looking to setup a machine with fedora (that is what you have on the server) and I’ve got one with RedHat (Think it’s called RH EL 4.3)
Remember to tell us how you set it up for CVS!

2. Wireless Networking | July 13th, 2008 at 1:09 am
Good article, keep em coming