Archive for the 'Programming' Category

A breath of fresh air

April 30, 2007

I read with great relief: “People Hate Making Desktop Apps…” Since When!? , a post identifing an issue that I’ve been following with interest lately.

Readers of my blog will know my opinion on bringing back a desktop client/ server based approach to development, Non readers – I’m 100% for it. I believe the multitude of ‘Web2.0’ apps being developed would simply be better as desktop applications.

The reasons for this are simple – Desktop applications:

  • Have more mature programming languages available
  • Can make use of operating system calls (including via VM)
  • Run on a decent windowing system, and behave like an application should
  • Allow offline work (still very important)
  • Allow secure (and managed) storage of data (really comes down to data ownership)

This is to name a few. Of course there are exceptions to every rule – especially the last point.

I’m not completely ruling out web-based applications where required; I regularly use web-based email for example. I would much rather have a desktop based RSS reader (client/server design) than browser. This can be said for many applications that are web based. Web-services with a decent front end – That’s the formula!

I was reading a blog post at which mentioned a widget toolkit for Java. I’m very interested in trying some of these out to for a couple of apps I want to write. Will digg up the link tomorrow.

I’ll be posting more on this subject I imagine- I’d like to know what other developers think.


Torture Bill as C Code

November 1, 2006

Edit – I’ve only just realised that wordpress did not submit the entire original post, this has now been fixed. Will teach me for posting in such a rush! – 3:42 p.m. 8/11/2006 (NZ Time)
Old news I know, But I thought it was worthy of sharing as many still will not have seen it.

I finally got a change to read Bruce Schneier’s latest newsletter about a week ago which featured this small C snippet that Kevin the author felt summed up the new terrorist bill:

if (person = terrorist) {
} else {

My initial take on it was that it was a simple joke illustrating that the with the new bill anyone ‘run through’ is automatically considered a terrorist. There are no checks in place and they are punished severely. This was when I first saw the snippet over at When I saw Bruce’s latest newsletter I read his entry on the code, in particular his blog comments where people pointed out a couple of other errors:

Punish_severely() is a black hole, it takes no arguments and has no return value. Who is being punished and how is the process being gauged?

Interesting piece of political code! All in fun of course 🙂

Edit – Another policical piece, Rumsfeld resignation summarized in Mac OSX screenshot. – 11:17 a.m. 9/11/2006 (NZ Time)

Trace listeners

October 3, 2006

In my post Solutions for basic logging I gave a very brief look at some solutions for implementing basic logging in an application. One of the tools I forgot to add was Trace listeners. I decided this was by far the best solution for my particular need: I can specify if the application is to perform logging or not by changing an XML value, I can easily choose the medium of the output, and writing the trace is simple.

I’m currently outputting to a text file but this could easily be the windows event log or XML fragment for example, and writing the message is as simple as writing to the console. I will deploy the application with logging off; If any issues arise I can tell the client to change the value (or include a script that will do it) and have them send the output. Easy!

I’ve noticed my application would benefit rethinking my logic (order of events, processing methods). This is to be expected really as in my initial builds I just wanted to make it work. I now want to make it as efficient as I can.

Trace Listener resources:

Tracing in .NET and Implementing Your Own Trace Listeners

TraceListener Class

Trace Listeners

Debugging once you go live: Trace Listeners

Solutions for basic logging

September 25, 2006

The application I am creating for my project is a Windows Service, therefore I need to maintain a basic log of events in case there are technical issues. From the start I wanted to create an XML file that would hold this information, the reason for choosing XML being that it does not matter how the log file is to be used (it can be directly fed to a database, or viewed using a viewer). It’s just a simple, portable format.

The problem with maintaining an XML log is the overhead of appending a record to the file. Each time I need to append an entry the whole document must be loaded into memory and parsed. Quite alot of memory usage and processing to write a single line of text to a document!

The idea of using XML fragments seems to be the perfect balance as it allows valid XML to be appended to a file as you would with regular text. This example identifies this solution and provides an example.

Another solution, which I havn’t tried but looks very interesting is the technique identified in the post: Appending XML files and confusing disposables. This solution allows XML to be appended to an XML document without loading it into memory.

And finally, there is the log4net framework. At the moment I’m leaning more towards log4net due to the simplicity. Logging isn’t of key importance to my project so it’s important I don’t spend too much time on it 🙂 Appending to a plain text file is actually enough for me, but It’s good to evaluate the options.

My service has to read from an XML file.

Ariel for ruby and Netscape daily WTF?

September 18, 2006

Ariel was featured on the front page of today and is a ruby libary for extracting information from structured documents, for example HTML files. This looks like a very useful libary and may be the perfect motivation for me to learn ruby! From what I have seen and played round with I’m looking forward to doing more 🙂

I also found a link to the Blake Ross on Popup Suppression daily WTF, quite a funny post regarding Netscape 7.

Self-returning methods

August 15, 2006

I was reading a post titled Avoid a void at on the subject of using self-returning methods in an API. A very good and informative read (the author has quite a humorous writing style too).

There was a comment on the post linking to an article called Java theory and practice: Enable initialization atomicity at IBM developer works. This is a more detailed article on self-returning methods or ‘the self-return idiom’ complete with examples and is very well written.

Something to consider when designing methods as not only can it improve your own readability it can also be very productive as represented by the single statement examples (no temporary variables).

Java based RSS reader

August 12, 2006

As regular viewers will know I have been wanting to make a RSS reader for some time, mostly because it is something that interests and will be a great learning experience.

I have decided that I will do it in Java/Swing, and not delphi as originally intended. I want it to be as portable as possible and want to extend my java knowledge as this is the type of job I will be looking for next year.

That plan of attack is to use a JEditorPane and send a ‘chunk’ of xml (parsed) to it via a stylesheet to be viewed. For example I will have a tree on the left with the subscribed feeds, expanding a feed will display each topic in the feed, clicking that topic will then display the contents for that topic in the JEditorPane, as html via XML/XSL conversion.

This is somewhat to compensate for Java Swing’s embarrassingly lacking HTML/XML rendering components.

I read the article: Sun should Open Source Swing: what is bad for Gosling is good for propaganda over at O’REILLY, which echos my view. Very well written and informative article.

As per suggested in the article I may look for an opensouce XML rendering component at JavaDesktop instead of using the JEditorPane.
Either way, I’m looking forward to getting this up and running!

export XML from SQL

August 12, 2006

This is the next thing I need to do for an application I am working on, won’t get to try it until next week but it looks like exactly what I am after, and quite simple! Fingers crossed.


The Mozilla Active X control worked perfectly as can be seen in the screenshot above, the only problem is that it doesn’t seem to support xml? I opened my wordpress feed in the control and it outputted plain text, not the nested elements as it would if you opened it in firefox for example. This is what I wanted to use it for (xml with a stylesheet) so I think I’ll look for a control that supports this, most likely a Java/Swing combo. Python/ Ruby were close but I have more experience in Java and like using Java Swing GUI components. And having to worry about how the TK or QT frameworks work with each language is proberly not the best way to learn a new language :).

I have been having a play with Ruby and I realling love the language and the pure OO implementation. It is very similar to JADE however I think it has already got more market interest! Especially with the Ruby on Rails framework.

Java Quotes in strings

August 10, 2006

Another one of those small things that trip you up every now and then (I always seem to forget when I need it), is having a string with quotations within it in a language such as Java. Here is how its done:

To have quotations within a string use the backslash \” before the quote.

String hello = “Hello \”Hello\” Hello”;

would produce Hello “Hello” Hello.  I think this format is used across many languages but I’m not too sure on that.

Monad / PowerShell

August 6, 2006

I’ve written a bit about how much I like using the Linux/Unix CLI and how powerful it can be, not to mention ease of use for many tasks and ease of scripting, well Microsoft now have a shell and scripting technology called PowerShell. Looks like a vast improvement from the exisitng CLI interface which is somewhat lacking.

You can read about it on the Windows PowerShell MSDN Blog.

Scripting with Windows PowerShell 

How to get Windows PowerShell RC1