Monday, March 29, 2010

Crossing the Causeway

This photo was taken around 10 years ago during a four wheel drive trip. It is the view from a causeway on Tiri Road, Knorrit Flat NSW.

Sunday, March 7, 2010

Programming or Configuration?

A recent post over at the Reinvigorated Programmer highlighted an interesting point about the nature of the programming that many modern coders do. The post discusses the difference between creating an application from scratch and coding much of the functionality yourself or using frameworks and libraries to create much of the code.

As a VB5/6 programmer who has recently started coding in JAVA I have found that the choice of libraries available both in the standard class libraries and in third party libraries was very large and it is sometimes difficult to know if you are creating something from scratch that may already be available in the standard libraries. Every day I find myself searching the libraries to ensure I am not re-writing the wheel.

Another point the blog post touched on is the widespread use of frameworks in modern coding. These ready built code bases are used to simplify the coding of applications by hiding the underlying code and allowing the user to configure the system with very little actual programming.

Overall, the use of these frameworks is a good thing as they do minimize the production of a lot of code that is common from one application to the next. My biggest gripe with frameworks is that there are so many of them and more are being created every day. Especially in the Java world it is difficult to determine what is the best choice amongst the hundreds of frameworks. However, once selected it can be difficult to change frameworks without considerable work.

From a learning perspective the large number of libraries and frameworks can be daunting and given the communities willingness to create new libraries and frameworks on a rapid basis I guess I will be learning a new library or framework most of the time. 

Thursday, March 4, 2010

JAVA - Writing a StringBuffer to a File

During some recent development work I was using a StringBuffer to hold a large string (>400K characters). This string was built using a variety of methods based upon data being read in from a CSV file.

Once the StringBuffer had been created I was going to write the StringBuffer out to a file. This is where I had an issue. For some reason I thought that stringBuffer included a method to write the information to a file. It doesn't.

I then went looking for an easy way to write the contents of the StringBuffer to a text file. After looking at a few forum posts I managed to determine the simplest way to write the StringBuffer to the file.

StringBuffer output = new StringBuffer();
// Get the correct Line Separator for the OS (CRLF or LF)
String nl = System.getProperty("line.separator");
String filename = "output.txt";
output.append("Write First Line to StringBuffer");
output.append("Write Second Line to StringBuffer");

try {
  BufferedWriter out = new BufferedWriter(
                       new FileWriter(filename));
  String outText = output.toString();
catch (IOException e)

The interesting parts of this code is the use of System.getProperties to get the correct line separator for the OS the code is running on and the use of the BufferedWriter in conjunction with a FileWriter to write the StringBuffer to the file.