Archive for the ‘computing’ Category

I’ve joined the Google Analytics fan club

Wednesday, April 5th, 2006

After having my name on the waiting list for Google Analytics for a good 3 or 4 months, I got an email this morning inviting me to sign up. And 15 minutes later I was up and running!

Plenty has been written about Google Analytics, much of it in a breathless “Wow!” sort of tone. And, I’m afraid I’m yet another one! The thing that gets me is the sheer depth of information. I’ve just spent the last 15 minutes discovering that (in the first few hours of stats collection) that:

  • Most of my audience has a screen resolution of 1280×1024
  • About a third of my audience is using dialup
  • All of my audience has Java enabled (well, this is a rather small sample at this stage ;) )

In addition, of course, there’s the more “standard” stuff – where in the world your clicks are coming from (although this is down to the State level, which is rare for us Aussies – plenty of tools give you US state info, but not Australian), which pages are most popular, etc.

Up till this point, I’ve been using AWStats in a static configuration – stats are generated in the form of static pages once per day. A great tool that gives me a lot of good summary information, but it just can’t touch the depth of Google Analytics stuff. That said, I’ll still be keeping it. AWStats runs on my PC, so I can always access it, even if I lose Net access. And, being static pages, its blindingly fast.

(Google Analytics is no slouch, by-the-by. I think we’ve all come to expect good performance from Google, be it search, mail, whatever, so this is probably no surprise. But there are noticeable pauses from time to time – only 2-3 seconds or so – as you navigate around)

Anyway, it looks like I can say goodbye to another 30 minutes of my life each day. So many graphs, so little time! :)

Javadoc-driven development

Friday, March 17th, 2006

Its the new development methodology thats taking the developer-world by storm…. ;)

Well, not really.

Just a cute phrase that occurred to me today when chatting to a colleague. We’d just spent 15 minutes discussing the desired behaviour of a system I was working on. Usual stuff – at first blush it seems straightforward, but plenty of edge cases, historical behaviour requirements, and other nastiness.

So we got it figured out, and its 11:45. Lunch booked at 12:00. No way am I even getting 10% of the code done in that time. But its just enough time to do the Javadoc.

So, 15 minutes later, my code has the 2 method signatures I need and around 40 lines of Javadoc describing the code’s behaviour, exceptions, and assertions. And after lunch, I was able to get straight into coding, all details of my discussion safely preserved.

And as an added bonus, when it comes time to rework it, I (or the next guy) will have some great doco to get started.

Not rocket science. Certainly not worthy of its own buzzword-esque title (although it does roll off the tongue :) ). And probably something everybody should be doing anyway as part of their actual methodology. But its a neat little anecdote worth telling!

How did I miss this? java.util.Collections

Monday, March 13th, 2006

Well, they say you learn something new everyday. And given the size of the Java API, thats not too hard to believe ;)

After doing serious Java programming for at a least a few years, and having dabbled for a few years more (all the way back to the 1.0 days!), I’m pretty happy with my breadth of Java knowledge. Until a co-worker today mentioned using Collections.shuffle() to randomize a list.

“Pffffft”, says I, “Surely you jest”, says I. “No such thing.”

Well, there is. java.util.Collections (not Collection, note – theres an “s” on the end!). A nice, chunky class, full of juicy, static methods just waiting to save you from having to re-invent the wheel when it comes to operating on Collections. There’s the obvious stuff – shuffle() and sort() to randomize and sort, for instance. And small, but useful stuff – min() and max(), swap(). And some real useful stuff, like synchronizedList() (which returns a thread safe version of your list).

Many’s the time I’ve done my own “max()” routine. Each time, I trawled through the Collection interface looking for one and was mildly surprised it didn’t exist. And I never thought to look any further afield. I’m guessing that there may be one or two Java guys out there who are in the same boat (How many library classes are there now in Java?). Seeing as my co-worker doesn’t have his own blog…yet (come on H! Get your act together! ;) ), I’m doing this posting for the other people like me!

Of course, I’ve always got the excuse for my ignorance that its a relatively recent addition. I mean, its only been around since Java 1.2….. *grin*

Will Wright’s “Spore”

Thursday, March 2nd, 2006

Came across this link on digg for a 30 minute video demonstration of the upcoming game “Spore”.

Wow!

I gather the game is the brainchild of Will Wright (of “The Sims” fame). The demo blew me away – it is sooooo open-ended. I won’t try to do it justice here – for one thing the scope seems huge, and for another, this was just a demo, so the finished product could be wildly different. In short though, you guide a species’ evolution to a certain stage, then switch to a kind of SimCity/RTS type game to build up their civilisation, then switch to a kind of “God” mode where you can fly to other planets and do it all again.

Reading over that last paragraph, it doesn’t really do justice to what the demo showed. For instance, you seem to have complete flexibility in designing your creatures – the computer figures out how they move/eat/etc based on their body architecture. And the creations of different players are made available (asynchronously) to your own universe – while exploring the universe, you might encounter a planet that has been copied from some other player.

I really recommend setting aside the time to watch the video. Its been over 2 years since I bought a computer game, but I can’t wait for this thing to be released.!

(btw – there’s a good article on the Wikipedia on “Spore” which goes into a little more detail, for those that are interested)

Being too secure with a CGI script

Monday, February 27th, 2006

Oooops. I mean, it seemed like such a good idea, right?

While working on the new Asman IT Consulting website a couple of months ago, I wrote a new “Contact Us” CGI script. I often work in the IT Security space, so I always have the security angle high on my list of priorities. So, I did the usual things:

  • I made sure that it wasn’t too flexible. Case in point – While chasing down a spam problem for a client, I discovered they had used a well known “Contact Us” script that was widely available that let you set the “to” address, such as the website administrator, as a hidden field. It worked well, until the spammers realised they could override that in their POSTs and use your Contact Us page as a spam relay…!
  • I sanity checked all fields to make sure only legal characters were present. Not, by the way, the common mistake of checking for illegal characters. Seems so tempting, as there are far fewer illegal characters to check for….. right up until you discover that you overlooked a dangerous character!
  • I checked that the script was only accessed from my “search” web page. Anything else would suggest some automated tool randomly accessing it directly
  • And a host of other checks and practices for things like rate of sending, data size, logging improper use, etc, etc

So far, so good. A few tests showed things working fine. And 2 months later the number of malicious hacking attempts made through it numbered exactly 0.

Exactly as many legitimate “contact us” messages I’ve received, as it happens. ;)

A look through the logs showed the problem. And it was all because of that second-last point.

Turns out I’ve had a few people try to send me messages this month. But a number of the more tech-savvy users (and I’m flattered they’re among those accessing my site!) turn off the “Referrer” facility in their browsers. The “Referrer” field normally allows a site to see where visitors have come from. With this disabled, my “Contact Us” facility refused to process their message as it looked like they had bypassed the appropriate web page within the Asman IT Consulting site.

All fixed now, and my apologies to those who were rejected up till now! But an interesting example of the “Security” vs “Ease of Use” balancing act that comes up time and time again. There was nothing intrinsically wrong with my initial approach. And there is nothing intrinsically wrong with people choosing to configure their browsers in that fashion. Everyone needs to pick a security stance that suits their particular situation.

And, based on their experiences and changing needs, amend that stance as required.

Java coders have it easy – crashing constructors

Friday, February 10th, 2006

I came across this entry while scanning Java Blogs yesterday about how to handle exceptions within a constructor. The essence of the article is how do you handle the situation where you couldn’t instantiate your object?

So, if the user passes invalid parameters, do you throw an exception? And, slightly more subtly, if your constructor encounters an exception during object setup, how does it handle this?

Interesting article and well worth the read.

But it struck a bit of a chord with me – I recently bought a Nokia N70 phone, and have been cruising the net looking at how you can code for these things. The N70 is a Symbian phone, and while it has J2ME support, the hardcore stuff seems to be done in C++. Now, C++ is an … interesting language, but is not really known for its in-built protection against memory leaks, and when you’re running a program on a device with limited memory, where your app may well run for the order of days or months this suddenly becomes a big deal.

OK, so you just code, really, really carefully. ;)

Well, turns out that constructors are a special case in terms of memory leaks. Symbian doesn’t use standard C++ exceptions, but it does have an analagous concept called “leaving” grafted on. And not being a C++ guru, I couldn’t tell you what difference there is between normal C++ exceptions and the Symbian variety. In any case, the issue when writing Symbian programs appears to be this:

  1. Constructor called
  2. Constructor initialises an instance variable that points to some new object
  3. On the next line, the constructor encounters an error and leaves

So, we now have allocated memory for some new object (step 2 above), but the object that owns it no longer exists – it crashed during construction. And because the object never fully formed, the destructor wasn’t run on it and so couldn’t free up the memory. Ladies and gentlemen, we have memory leak…. :(

Turns out that Symbian programs have an accepted idiom on how to handle this stuff. Objects that can suffer this way have a static construction method (like the whole getInstance() idiom you see in Java). This static constructor creates the object using a constructor that only performs trivial operations that won’t crash, then once the object exists, calls an instance method on the new object that performs 2nd-phase construction. If things turn to jelly, there is at least a concrete object in existence, so the destructor will be called as normal.

Pretty neat. And pretty eye-opening as to the kind of issues you can be exposed to without garbage collection.

(Which is not to say that Java doesn’t have its own issues with memory leaks, but thats a whole other blog post… :) )

Great site – lifehacker.com

Friday, February 3rd, 2006

www.lifehacker.com. Bookmark it. Add it to your aggregator. Print out the URL, frame it, and put in on your bedside table (marginally behind the picture of your “Significant Other” – you don’t want to go too far….)

You get the idea… ;)

I can’t even recall how I found this site now – some random google or another, I think. But I’ve subscribed to the feed for the last few weeks and I’m hooked. What is it? Well, I think they describe it best:

Computers make us more productive. Yeah, right. Lifehacker recommends the downloads, web sites and shortcuts that actually save time. Don’t live to geek; geek to live.

In the last couple of weeks, they’ve posted short reviews and links to cute Firefox plugins and Mac OS X apps, links to stories on hybrid cars, and a number of really interesting links to stories on personal organisation and time management. So far, I’ve been seeing around 10 – 20 posts a day, of which I find at least 75% are worth the read.

Kind of ironic – despite their mission statement, I’ve just lost 5-10 minutes of my life each day to their website! Here’s hoping thats offset by the efficiencies I’ll no doubt gain….. :)

End of rave. We now return you to your regularly scheduled programming…

Yet another Eclipse / NetBeans comparison

Sunday, January 29th, 2006

A week or so ago, I downloaded NetBeans 5 RC2 specifically to play with the mobility pack, but figured I might as well explore its capabilities as a J2SE IDE.

For those of you who like their blog posts short and snappy – “Neat, some cool stuff in there, but I’ll be sticking with Eclipse for now”. For those who can handle a couple more paragraphs, read on…. :)

To start with, can I join the crowd and say “Matisse rocks!”? Matisse is the visual editor for Swing apps, and it is fantastic – in 90% of cases it does what you mean: you put an object right on the left border, and it figures that that object should be anchored to the left. You place one button next to another and it keeps them together and snaps them to be level. I played with Eclipse’s Visual Editor in a recent small project, and it has a ways to go to catch up to this.

But (and there’s always a “but”, right?), the killer for me was that “90% of cases” phrase – its the other 10% that comes back to bite you. For instance, I wanted to do a a little “cross” of buttons – and up, down, left and right, laid out in a diamond. After having been spoilt with the editor doing what I meant for the rest of the UI, I found it a bit jarring when I was doing “free form” component layout – buttons were slightly off, by a pixel or two and it kind of “looked” wrong.

There’s probably a hidden “layout in a cross” option I missed :) . And I could have added a panel, set it to GridBagLayout and done it that way (Matisse has good support for GridBag). And how often do you want to have buttons in a bizarre shape like that anyway? But it kind of broke the spell for me in a way. I’m a big believer of being “in the zone”, development-wise, and switching between IDE modes (code and visual) is a real context switch for your brain – to compensate, I think I need almost perfection from the Visual Editor. Matisse is soooooo close, but isn’t quite there for the fiddly cases. (How would I have liked Matisse to handle my peculiar layout requirement? I have no idea!).

Matisse is the big ticket item – the rest of the IDE is good, but not compelling from where I sit. There are some winners, though. I love the idea that the IDE is ant based – take your development directory, zip it up and give it to someone else, and they can compile, test, build, etc. Ant seems to be the one big constant across teams – it makes so much sense to have it as the backbone of your development processes. And the fact that a test folder is created when you start a new project is a little nicety, but a good one.

On the downside, on my machine (2 Ghz with a ridiculous 512Mb of RAM), NetBeans is noticeably more sluggish than Eclipse – maybe this is an SWT thing? (I hope not, I’m one of those Swing fans ;) ). And the plugin environment for Eclipse seems so much richer at the moment – I even have a VI plugin for my Eclipse for when I’ve been doing a lot of Unix work and keep on putting the letter “i” throughout my source code (you Unix guys will know what I mean)!

So, I’m staying with my Eclipse for now. It was certainly worthwhile to check out though, and I’m still planning to do my next little J2ME project with NetBeans – I’m keen to give that Mobility Pack a proper workout.

Developer.com article on Code Reviews

Thursday, January 26th, 2006

There’s a worthwhile article on code reviews at developer.com at the moment called Effective Code Reviews Without the Pain.

Its a quick read, and the title says it all. The article’s focus isn’t so much on what your code review should cover, but how your code review should be carried out – how to make what can feel like a very adversarial, negative process into a postive, learning process. There’s tips for both the code reviewer and reviewee, with points like “Avoid ‘Why’ questions” and “Remember that the code isn’t you”.

Good, common-sense stuff. Its rare to find a development area that doesn’t use code reviews nowadays (even if only intermittently! ;) ), so it should be worth a read for most developers.

Comment on Slate Article – “Keeping Secrets”

Wednesday, January 25th, 2006

I’ve just read an interesting article at Slate called “Keeping Secrets“, where the author, a Professor Tim Wu makes some interesting points:

  • We have to assume that the US Government (and others) will one day succeed at getting at Google’s search data (which includes semi-identifying information like a searcher’s IP address)
  • While this identifying information has some value in improving the quality of search, that does not outweigh the potential privacy implications
  • Seeing as there is little hope in reforming the Government’s attitude towards protecting freedom, the public should demand this protection from Google and ask them to stop storing the information.

(This isn’t a complete summary by any means – I encourage you to read the full article to get the complete context)

Its an interesting argument, but overall, I’m not convinced. The point that jars me the most is the last one, which he puts thusly:

Recent events suggest that relying on the present administration to protect such basic freedoms may be, shall we say, unpromising. Other governments are just as bad if not worse. That’s why the public’s demand must be of Google—not the state.

That really strikes me as back to front. Democratic Governments are our representatives. Their job is to represent us. If they are behaving in a way that goes against our wishes, then we get to fire them (come the next election). In this age of massive election campaigns, spin doctoring and presentation over substance, that concept may seem a little idealistic – nontheless, that is the principle on which most Western systems of government are based. (I happen to be an Australian, not an American, but the same principles apply).

I’m also not convinced of the argument that the disadvantages of storing the data outweigh the advantages. While Google (and the other search companies) are doing this purely out of self-interest, I’m the one who eventually benefits – I get to find what I’m looking for quicker and more efficiently, in an increasingly disorganised Internet. If you like, I’m trading – “you get to see where I’m going, in return for you providing me with better service”. And importantly, if I decide that I don’t wish to do that trade (some, or all of the time), there are third party services (anonymising proxies) that will let me keep my identity cloaked.

Just my idle thoughts on a pretty weighty topic….