22 Feb 2007

The Evolution of a Programmer

1 Comment Uncategorized

I just found this today out on the net, it seems to have many forms so the author is Anonymous.

High School/Jr.High

  10 PRINT "HELLO WORLD"
  20 END

First year in College

  program Hello(input, output)
    begin
      writeln('Hello World')
    end.

Senior year in College

  (defun hello
    (print
      (cons 'Hello (list 'World))))

Read more

21 Feb 2007

Understand C#: Proper use IDisposable and using keyword

4 Comments Uncategorized

The System.IDisposable interface is a very useful interface to understand if you are concerned about performance in your application. Microsoft says the following about the IDisposable interface:

The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used, however, it is not possible to predict when garbage collection will occur. Furthermore, the garbage collector has no knowledge of unmanaged resources such as window handles, or open files and streams.

Most System.Data, System.IO and System.Windows.Controls objects use the IDisposable interface, as well as many others, to free up unmanaged resources that may have been created when the object was initialized. Unmanaged resources are any calls that are made outside of the .NET environment, this can be GDI+ calls, SQL Driver calls, Disk IO calls, or basically anything that cannot be accounted for by the Garbage Collector.

Often times you will see database connection code that looks like this:

SqlConnection conn = new SqlConnection("{connection string}");
SqlCommand command = new SqlCommand(conn);

command.CommandText = "select * from SomeTable";

// ... some more code to use the command

conn.Close();

However there are a problem with this code, the unmanaged resources for the SQL connection have not yet been destroyed in memory. The correct way this code should have been written is the following:

using (SqlConnection conn = new SqlConnection("{connection string}")) {
	using (SqlCommand command = conn.CreateCommands()) {

	command.CommandText = "select * from SomeTable";

	// ... some more code to use the command

	conn.Close();
	}
}

And if you were to look at this code under a microscope the following code is actually what is happening:

SqlConnection conn;
SqlCommand command

try {
	conn = new SqlConnection("{connection string}");
	command = new SqlCommand(conn);

	command.CommandText = "select * from SomeTable";

	// ... some more code to use the command
} finally {
	conn.Close();
	command.Dispose();
	conn.Dispose();
}

So essentially even if an exception is thrown from your code, the unmanaged code is still cleaned up and you don’t have memory leaks from unmanaged code sitting around in memory waiting to be reclaimed. It is reclaimed instantly after you are done working with it.

If you would like to learn more about the code used above please see these links

20 Feb 2007

Remove Updater5 from My Documents Folder

16 Comments Uncategorized

Well I finally figured out how to remove the Updater5 folder from your My Documents folder. I have written about this problem, as well as many other people, and now here is the solution for us anal retentive people that don’t like our My Documents folder cluttered with application artifacts.

Follow the couple steps I have outlined below and the Updater5 folder will be out of your life forever.

  1. Go to C:\Program Files\Common Files\Adobe\Updater5
  2. Run AdobeUpdaterInstallMgr.exe and wait for the progress bar to finish and show you the following screen.
    Adobe Updater Window
  3. Then click Browse button and change it to any directory you want as shown below.
    Adobe Updater Preferences Window
  4. Now click the OK button and you are done.

And now you should never see the Updater5 folder in your My Documents folder ever again. This solution has worked both on my Windows XP as well as Windows Vista boxes that I have tried it on. For Mac users you can try hunting down the same updater program and going through the steps however I don’t have a step-by-step guide for you.

This solution seems a little more elegant than many of the other solutions I have seen floating around on the net. So pass this around and thank the stars that Adobe made this configurable, even thought it is hidden away and should have never been defaulted to the My Documents folder in the first place.

Update: Many people have been asking me if they can offer me anything for getting rid of the annoying Updater5 folder. Honestly the answer is no, I do this because I enjoy doing it, and I hope the readers will come back to check out my other content. But if you would really like to do something for me, please visit one of the sponsors to the right or the left. They are how I support this site and keep it running.