Sotomayor not fit to be a Supreme Court Justice?


After receiving a few emails expressing outrage over the “liberal” nominee for the Supreme Court, I decided that I needed to read up a bit on the issues that were brought up by various talking heads, emails, etc. Here is my two cents on a couple of issues I have seen raised.

The "Latina Women are better than White Men" comment

Looking at the actual snippet, the comment is far less inflammatory than is being expressed.

I would hope that a wise Latina woman, with the richness of her experiences, would more often than not reach a better conclusion than a white male who hasn’t lived that life

The above comment was part of a speech given at the University of California, Berkeley for  a conference entitled Raising the Bar: Latino and Latina Presence in the Judiciary and the Struggle for Representation. Given the context, I am not overly concerned with the comment, as it was specifically tailored for a particular group and was given in response to the comment “a wise old man and wise old woman will reach the same conclusion in deciding cases”.

Do questions need to be asked about her feelings on racial issues? Certainly, as the answers the questions may, in fact, reveal that the above comment is part of her overall feelings on Latina women versus white men and may cloud her judgment on issues. But, it should be only to establish her thoughts on this issue and then taken as part of the entire line of questioning. Extended focus on this particular comment is ridiculous. I would certainly hope this does not become the major focus of the upcoming dog and pony show, as it distracts.

The New Haven Fire Department Fiasco

I agree with the sentiment being expressed over this one, but it is not Sotomayor’s fault. Title VII states that discrimination is illegal when it comes to hiring practices. It, unfortunately, does not iterate what discrimination is, leaving plenty of room open for interpretation. Specifically, it does not iterate what disparate discrimination is, or when there is unintentional discrimination.

The sad part is the New Haven fire department heads knee jerked when they found 60% of white test takers passing and only 30% of black and hispanic takers passing the Lieutenant’s and Captain’s exams. The knee jerk was further justified by looking at the passing candidates and whether they would actually get one of the slots. No black individual would have been promoted, due to the number of slots. The first legal precedent is Griggs v. Duke Power Company, where the company stopped overt racist practices, but added a high school diploma and IQ test to the requirements for higher positions. The decision was further spelled out in Albemarle Paper Co. v. Moody, which concluded their tests unfairly excluded blacks from higher paying jobs, and Washington v. Davis, which concluded the Washington DC police force’s verbal tests were failed disproportionately by black applicants. The nail in the coffin was Connecticut v. Teal, which found that adverse impact at any stage in a promotion process constitutes discrimination.

The crux of the law is it is illegal to have a process that has disparate impact on hiring and promotion unless one can prove the process is a "reasonable measure of job performance".

The main argument I can see against Sotomayor’s decision is whether or not she correctly decided against the plaintiffs as precedence allows for adjusting scores of minority applications and not throwing out the results of an exam altogether. If this is the worst this woman has done, it seems like thin ice to me.

Summary

The best two arguments against Sotomayor, at this point, are rather trivial, unless one can show evidence that they shows a trend in favoritism against the majority. At present, this is not firmly evident.

Peace and Grace,
Greg

Twitter: @gbworld

How to do simple recursion (XCopy in C# (and VB))


Yesterday, I saw the following question in the C# NNTP group
(microsoft.public.dotnet.languages.csharp):

I need to get a listing of all folders and subfolders paths using C# .net
2.0.
such as .folderAsubfolderBsubfolderC
            
.folderAsubfolderD
             .folderAsubfolderDsubfolderE
Any
ideas, examples?

Simple recursion problem. The writer wrote back and stated he want to copy
all files from a CD, using C#, into an equivalent directory structure on the
drive. Now, I might choose to solve this by making a P/Invoke call to the API
method that does xcopy or wrap XCopy in a Process object, but we can also solve
this through simple recursion. Here is the follow up:

Ok, so I’ve got a CD that has folders and files on that media.  I’m
creating
a small app that will basically copy from the Cd to the hard drive
and
maintain that same folder structure found on the CD.  I’m
thinking
the easiest way to such as task, is to create a string array with
the folder
paths on the CD, then create that folder structure on the hard
drive, then I
can copy from source to destination.

Now, suppose we create a simple class library with a single class to do this
move. I will leave the method as static, as it really does nothing more than
read the directory, move files and then check for subdirectories. The entire
class is represented below (this is a rough draft, of course):

using System.IO;

namespace GBWorld.RecursiveCopy.Business
{
    public class DirectoryCopier
    {
        public static void CopyDirectory(string originalDirectory, string newDirectory)
        {
            MoveDirectory(originalDirectory, newDirectory);
        }

        private static void MoveDirectory(string originalDirectory, string newDirectory)
        {
            //Ensure new directory exists
            if (!Directory.Exists(newDirectory))
                Directory.CreateDirectory(newDirectory);

            DirectoryInfo oldDir = new DirectoryInfo(originalDirectory);

            //Copy files
            foreach (FileInfo file in oldDir.GetFiles())
            {
                string oldPath = file.FullName;
                string newPath = newDirectory + "\" + file.Name;
                File.Copy(oldPath, newPath);
            }

            foreach(DirectoryInfo dir in oldDir.GetDirectories())
            {
                string oldPath = dir.FullName;
                string newPath = newDirectory + "\" + dir.Name;
                MoveDirectory(oldPath, newPath);
            }
        }
    }
}

The yellow highlighted part is where we are using recursion. The orange highlighted section helps this work, as it ensures the new directory is created. And the green highlighted section copies the files from the directory.

To call this, you can do something as simple as this console application:

using GBWorld.RecursiveCopy.Business;

namespace GBWorld.RecursiveCopy.UI.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            string oldDir = "C:\temp\test1";
            string newDir = "C:\temp\test2";

            DirectoryCopier.CopyDirectory(oldDir, newDir);

            System.Console.WriteLine("Done");
            System.Console.Read();
        }
    }
}

Pretty Simple, eh? There is definitely more that can be done here for a production app. I should, for example, check if the original directory exists. I might also break down the new directory and make sure parent directories exists, as a call to create c:temptest2 will fail if c:temp does not exist. And we could add some instrumentation and logging to help when things fail. But, this is just a simple example.

BTW, this is a layered app. The UI is completely separate from the "business" code that holds the actual behavior. If you read this blog often, you will find I like to do this, as it makes it easy for me to change out user interfaces without rewriting application code. Here is how the projects look in the entire :application":

For those of you who are into VB, there is an easier way to copy directories using the My object. But, here is the recursion exercise in VB, with the same highlights (I copied this from Reflector rather than rewrite it):

Public Class DirectoryCopier

Public Shared Sub CopyDirectory(ByVal originalDirectory As String, ByVal newDirectory As String)
DirectoryCopier.MoveDirectory(originalDirectory, newDirectory)
End Sub

Private Shared Sub MoveDirectory(ByVal originalDirectory As String, ByVal newDirectory As String)

Dim oldPath As String
Dim newPath As String

If Not Directory.Exists(newDirectory) Then
Directory.CreateDirectory(newDirectory)
End If

Dim oldDir As New DirectoryInfo(originalDirectory)
Dim file As FileInfo

For Each file In oldDir.GetFiles
oldPath = file.FullName
newPath = (newDirectory & "" & file.Name)
File.Copy(oldPath, newPath)
Next

Dim dir As DirectoryInfo

For Each dir In oldDir.GetDirectories
oldPath = dir.FullName
newPath = (newDirectory & "" & dir.Name)
DirectoryCopier.MoveDirectory(oldPath, newPath)
Next

End Sub

End Class

Reflector is not as concise, so feel free to edit as needed to make it cleaner. I was not interested in writing VB code right this second, so Reflector made things easier for me.Wink

Peace and Grace,
Greg

Twitter: @gbworld

Visual Studio Beta 1 For Everyone


Even if you do not have an MSDN subscription, you are in luck. Visual Studio 2010, beta 1, is now available on Microsoft download. Here is a list of public links I was sent just recently. The downloads are all on Microsoft download. You will also want to join Microsoft connect for feedback.

VS 2010 Beta


· VS2010 Download page

· VS2010 Walkthroughs

· MSDN Library: What’s New in Visual Studio 2010

· VS2010 Connect

· Forums: VS, VB, C#, F#

· Samples: VS, VB, C#, F#

· Language specs: VB, C#, F#

· IronPython 2.6 CTP for .NET 4.0 Beta1

SKU/download page

Format

Size

Download page fwlinks

Visual Studio 2010 Shell (Integrated) Beta 1 Redistributable Package

exe

521 MB

http://go.microsoft.com/fwlink/?LinkId=147419

Visual Studio 2010 Shell (Isolated) Beta 1 Redistributable Package

exe

593 MB

http://go.microsoft.com/fwlink/?LinkId=147418

Visual Studio 2010 Professional Beta 1 – Web Installer

Bootstrapper

5 MB

http://go.microsoft.com/fwlink/?LinkId=147408

Visual Studio 2010 Professional Beta 1 – ISO

iso

1.2 GB

http://go.microsoft.com/fwlink/?LinkId=150591

Visual Studio Team System 2010 Team Suite Beta 1 – Web Installer

Bootstrapper

5 MB

http://go.microsoft.com/fwlink/?LinkId=147407

Visual Studio Team System 2010 Team Suite Beta 1 – ISO

iso

1.3 GB

http://go.microsoft.com/fwlink/?LinkId=150592

Visual Studio Team System 2010 Test Load Agent Beta 1 – DTEA

exe

185 MB

http://go.microsoft.com/fwlink/?LinkId=147420

Visual Studio Team System 2010 Test Load Agent Beta 1 – DTEC

exe

599 MB

same as above

Visual Studio Team System 2010 Team Foundation Server Beta 1

iso

2.3 GB

http://go.microsoft.com/fwlink/?LinkId=147412

Microsoft Visual Studio Lab Management 2010 Beta 1

no package

 

http://go.microsoft.com/fwlink/?LinkId=147413

Visual Studio Team System 2010 Lab Agent Beta 1

exe

427 MB

http://go.microsoft.com/fwlink/?LinkId=147414

Microsoft .NET Framework 4.0 Beta 1 – x86

exe

78 MB

http://go.microsoft.com/fwlink/?LinkID=147415

Microsoft .NET Framework 4.0 Beta 1 – IA64

exe

146 MB

same as above

Microsoft .NET Framework 4.0 Beta 1 – x64

exe

149 MB

same as above

Microsoft .NET Framework 4.0 Client Profile Beta 1 – x86

exe

35 MB

http://go.microsoft.com/fwlink/?LinkID=147417

Microsoft .NET Framework 4.0 Client Profile Beta 1 – x64

exe

73 MB

same as above

Visual Studio 2010 SDK Beta 1

exe

14 MB

http://go.microsoft.com/fwlink/?LinkId=147422

Microsoft Visual Studio 2010 Remote Debugger (Beta 1) – x86

exe

4 MB

http://go.microsoft.com/fwlink/?LinkId=147421

Microsoft Visual Studio 2010 Remote Debugger (Beta 1) – x64

exe

8 MB

same as above

· Channel 9 Video

· Product Survey

· Samples

· VB 2010 Resources page

· Visual C# 2010 Resources page

· F# Dev Center

This is great news for those of you who like to stay on the bleeding edge of technology. Thus far, I have enjoyed playing with the beta. It is still a bit slow, especially in a VPC environment, but far less so than the betas of Visual Studio 2008, so I am happy. I will be posting some tutorials soon, so you can learn how to use the new technology.

Peace and Grace,
Greg

Twitter: @gbworld

More About Recruiters


I posted yesterday 7 Things Recruiters do That Irritates me. I then got a call from Scott Gordon (one of my recruiter friends in Nashville) asking if he could use my blog post on his site, the Anti Pimp. I am sure I will see it some time today (he had some questions and we have not yet linked up).

In terms of value, it goes like this:

  • Professional Recruiter: Does his homework to match candidates with positions. Generally gets a sale, as he has properly figured out client needs and vetted candidates. You might argue that his request of 20%+ of the first year’s salary is too high, but you cannot accuse him of adding no value.
  • Run of the Mill Recruiter: The primary thing this recruiter does is introduce people. He still holds some value, as he knows a lot of people and can introduce candidates to employers. It is very easy to argue this recruiter is overcharging.
  • Lazy, unprofessional recruiter: This guy is just in it for the money and gives everyone a bad name. His total claim to fame is he knows how to use the search page on Monster, Dice and Career Builder and he can use a telephone. He does not deserve to be paid for lining up candidates and I am hoping the United States Congress passes the hunting season bill for this waste of human flesh. 😉

The idea behind professional recruiting is this:

  1. Professional Recruiter goes to client and finds out the clients needs. This is a fact finding mission so he can add value to the proposition by only sending people that fit the qualifications. As many employers do not know what they need, the recruiter must know enough about technology and people to determine the proper match.
  2. Professional Recruiter goes to talent pool and finds the individual(s) that fit the position. This comes from having a relationship with the talent and understanding their skills, as well as their desires.
  3. Professional Recruiter matches talent and position and gets interviews set up.
  4. Professional Recruiter gets paid for setting up the right person for the job.

The above is the professional recruiter, who earns his paycheck. But, like any field, someone comes along and tries to find ways to maximize profit, while minimizing work. This is what the lazy idiot did yesterday. Here is how this works:

  1. Lazy Recruiter does searches to find companies wanting to hire, or gets req in his inbox
  2. Lazy Recruiter calls company and gets approval to send candidates (if he subscribes to reqs, this step is optional)
  3. Lazy Recruiter circles buzz words in req
  4. Lazy Recruiter does buzz word search on circled buzz words
  5. Lazy Recruiter SPAMS every developer on Monster, Dice and Career Builder (and perhaps a few others)
  6. Lazy Recruiter makes phone calls to same developers

The problem here is the lazy recruiter ends up calling numerous times and sends out numerous emails to each candidate. He offers no value to the company, as he is not really screening candidates. He is also wasting a lot of everyone’s time. And he gives all recruiters a bad name, as he paints the picture of recruiters being lazy, non-professional asses.

The guy who called me numerous times in a row yesterday was a lazy recruiter, if we can call “pond scum” a recruiter. He then emailed me three times for the same position, as he is too lazy to even see if he is SPAMMING the same candidates on the three boards. But, he does not care.

What makes it worse is when the lazy recruiter speaks marginal English at best, as this guy did. And, to make things even worse, many of these jerks are rude on the phone. I think they truly believe they are doing me a favor wasting my time on low paying positions. Just in case you have not bought a clue lately: You are NOT helping me out; you are just driving up my cell phone bill.

For those of you who are professionals, keep doing what you are doing. For those of you who are human search engines spamming the world, I suggest spending some time and getting to know the business or get out. You are making the guys who treat recruiting as a career look bad and ticking so many of your potential customers off.

Peace and Grace,
Greg

Twitter: @gbworld

Visual Studio 2010 Beta 1 on MSDN


Microsoft released Visual Studio 2010 Beta 1 on MSDN yesterday. If you have an MSDN account, you can find the following on your subscriber downloads:

  • .NET Framework 4 Beta 1
    • IA64 – 145.95 MB
    • x86 and x64 – 157.84 MB
  • .NET Framework 4 Client Profile Beta 1
    • x86 and x64 – 71.40 MB
    • x86 – 34.27 MB
  • Visual Studio 2010 Professional Beta 1
    • x86 – 1,164.30 MB
  • Visual Studio 2010 Remote Debugger Beta 1
    • x64 – 8.27 MB
    • x86 – 4.05 MB

If you have a Team Subscription, you will also find team Foundation Server beta 1 (x86 – 2,272.80 MB), Team Suite beta 1 (x86 – 1,258.76 MB), Test Load Agent beta 1 (x86) – 181.59 MB and Test Load Controller beta 1 (x86 – 584.97 MB).

Peace and Grace,
Greg

Twitter: @gbworld

7 Things Recruiters Do that Irritate Me


Before getting into this post, I think I should state that there are recruiters I truly respect and like and recruiters that I do not respect and probably would not like even if I knew them. This post is about the later category, which I feel are the lazy recruiters who add no value to the candidate-employer relationship.

I got a call today from a recruiter who I would have loved to strangle, if it was only possible to do so over the phone. So here is my list of the top things that irritate me, which I am sure also irritate others. The first three come from my caller this morning, who I will affectionally call Mr. Lazy so i do not post his name here.

  1. Ringing my phone over and over again until I answer – This was the issue number one when I talked to Mr. Lazy this morning. If you are going to call my line seven times in a row, my house had better be on fire. I realize this may seem like an emergency to you, but it is not my emergency.
  2. Being rude to me on the phone  – This was issue number 2 with Mr. Lazy today. I know saying “no, you have to listen now” might be polite talk in India or Pakistan or wherever you are from, but it is consider rude in the United States. It is consider ultra-rude in the south, where I current reside. I am sorry I hung up on you today, which was also rude, but when I tell you I don’t have time to talk, send me an email or give me a call back later. Do not assume your time is more important than mine and I have to listen to you this moment. The message it sends to me is you are smiling and dialing for dollars and not trying to add any value to the proposition.
  3. Being rude to my wife on the phone – Once again, I realize you might come from a country where you can beat your wife whenever you want, but it does not mean you can beat mine up. Of course, she is perfectly capable of giving you a tongue lashing and then hanging up on you, so feel free Mr. Lazy. And, yes, this HAS happened in the past.
  4. Emailing me numerous times for the same position  – This was issue number 3 with Mr. Lazy. I know it takes a little bit of time, but when you go from Monster to Dice to Career Builder, check and see if you already sent me an email. Otherwise, you are showing me how lazy you are and I would rather talk to a recruiter I know and trust about the position than you. NOTE: I can generally figure out who the company is by looking at your req; if not, I will call someone I trust and ask them if they can figure it out. I am NOT going to call YOU.
  5. Not reading my resume – When you call me or email me based solely on buzzwords, chances are you have something wrong. Yes, I know you have a lovely entry level .NET position you need to fill, but I am not going to work for $25 an hour 1099 or corp-to-corp. Don’t waste my time.
  6. Not reading my location preferences – yes, I realize that there are jobs that are too good to pass up, no matter where they are located. In general, these jobs have a greater than $250k/year salary ($500k/year for California ;->), moving allowance, and no cost health benefits. Yes, I am being a bit ridiculous, but I am not moving for $45 per hour 1099 or corp-to-corp. I can make that here without any headaches. Now, if you have that $1 million per annum, plus bonus, plus moving expenses, plus no-cost benefits, I might even be interested in going to Greenland for a few years.
  7. Having me do your job for you – I am far along in my career, I should not have to spend an hour answering email questions for you to send my resume to your client. You should be able to do the work to figure out if I am the right person to talk to.

On point #7, the email today had the following questions and answers, most of which can be determined by READING my resume.

  1)       Full Name:

  2)       Present location:

  3)       Contact Details:

  4)       INS Status:

  5)       Availability:

  6)       Total IT Experience:

  7)       Total US Experience:

  8)       Ready to Relocate (Yes / NO):

  9)       Expected Compensation:

10)     Comfort levels (on a scale of 1[Least] to 10[High])

        §  OO Design and Analysis

        §  .Net

        §  C#

        §  SharePoint

        §  Silverlight

        §  Web Services

        $  Messaging Framework

        §  PL/SQL (Oracle)

        §  UML

        §  Design Patterns

11)     Interview Preferred Timings :

12)    Do you bear the needed years experienced

        §  OO Design and Analysis               5

        §  .Net (C#, Sharepopint)               3

        §  Silverlight                          1+

        §  Web Services & Messaging Framework   2

        §  PL/SQL (Oracle)                      2

        §  UML                                  2

        §  XML                                  2

BTW, this is not the worst one I have seen. I had one that actually read like a job application (in bad english, of course) and would have me copy almost my entire resume into the email. Do I look desperate?

I was asked by a friend, who is a recruiter, why so many developers hate recruiters. I told him it was because recruiters were not earning their keep. This is not true of all of them, but there are some who are absolutely wasting my time, and the time of others, to try to make a quick buck. If you want to place me, and do not have a dream job, then you should at least take a few minutes to figure out if I am even qualified or would be remotely interested.

For the recruiter friends I have in the Nashville area (and some outside the area), I am not talking about you here. Yes, there are some developers that view all every recruiter as scum, but you know I am not one of them. I do have a problem, however, with recruiters that are nothing more than human search engines, as they take way too much of my money for no added value.

Peace and Grace,
Greg

Twitter: @gbworld

Announcements from TechEd


As always, Microsoft likes to wait until conferences to make big announcements. This year, at Tech Ed, the news is:

  • Office 2010 is the next version of Office. Tech Ed attendees will be one of the first to see the new office product, with an invitation-only Technical Preview starting in July of this year.  The countdown has begun. Check it out at http://www.office2010themovie.com/. If you are not at TechEd, you can get “waitlisted” for the preview here.
  • A technical preview of SQL Server 2008 R2, formerly SQL Server 2010, aka Kilimanjaro (or tallest mountain in Africa), will be released later this summer. You can register for notification here, if they actually have it working now.

I am more interested in SQL Server at this point in time, although the spec sheet does not show a huge amount that I am likely to get overly excited about right now. Here are the new features;

  • Support for more that 64 logical processors – I am sure some DBAs are salivating, but I’ll pass for now
  • Server Management additions – Great for DBAs
  • Integration with Visual Studio – Okay, this one has my attention, as I hate having to switch tools
  • Master Data Services – Like the idea, more DBA than I am now
  • Self-Service Analysis – Whether you use Excel or SharePoint, end users can now do their own reports against the Enterprise data store. Great idea, but if DBAs cannot control this, it has the potential to be a nightmare.
  • Self-Service Reporting – All users to create their own “grab and go” reports in Reporting Services. I am a bit skeptical, as I have yet to see self-service work; on the other hand, I get paid to fix things people muck up, so maybe this is a good idea. 🙂

Peace and Grace,
Greg

Twitter: @gbworld

Star Trek Review


I just got back from watching Star Trek, aka Star Trek 2009, aka Star Trek Reboot. In many ways, I think Reboot is the most proper name of the three. Perhaps that is why so many sites are using that word.

The movie starts out in a manner very similar to Lethal Weapon 3. Very few credits and right into the action. In the first few minutes, an interesting plot device allows Abrams to both respect and reinvent the Star Trek universe. I am certain this will be the first film in a set of films and I would be happy to see them continue the story line. I firmly believe this film has finally broken the curse of the odd numbered Star Trek films.

The film starts out with the childhoods of both Kirk and Spock. As you have most likely seen the trailers for the film, these moments will contain very few surprises. Kirk, a troubled youth, is the genius repeat offender of small town Iowa. Spock, the child of human a Vulcan parents, is an outcast. A sense of duty and a bar fight send them off to Starfleet Academy and starts the ball rolling. Thus ends act 1.

One by one, familiar characters are introduced, from the paranoid Doctor Leonard “Bones” McCoy to the “pull it out at the last second’ engineer Montgomery Scott, we have characters that are familiar and yet new. And each, in his own way, stays true to the character, at least enough old style Trekkies will enjoy the movie, and adds their own take on the characters. Each character has a pivotal moment in the film where their unique skills provide much needed aid.

For fans of the old show, there are plenty of one liners in the film. I found myself laughing out loud at some of the lines, much to the chagrin of the twenty-some-odds sitting near me. Perhaps they have not purchased the DVD set?

One tragedy of the film is it never allows Nero, the Romulan character played by Eric Bana, to fully explore the character. While it might have made the film a bit longer, I think the film could have been better allowing a bit more depth to his character. It would have also been nice to give a bit more depth to the character of Scotty, played by Simon Pegg, who delivers some of the best one liners of the movie.

The film is a nice blend of action and character development. I think it will play well with audiences that are fans of the original series, as well as those who have never experienced it. I give credit to the screenwriters for pulling this off.

Grade? I would give the movie a solid B, perhaps even a B+. With a bit more development of the bad guy, and a bit more time spent on the conflict facing Scotty in his first scene, I would have given it an A. When it is finally released on DVD, I will definitely purchase a copy. Here’s to the hope that removing the curse of the odd Star Trek films does not come back with the next even film.

Peace and Grace,
Greg

Twitter: @gbworld

Windows 7 RC for Everybody


Microsoft is banking on an RC now. As I mentioned last week, the RC was made available for TechNet and MSDN subscribers. On Tuesday, Windows 7 RC was made available for download for everybody. Click here for the info.

The RC will expire on June 1, 2010, so you have time to play before it expires. You can download from now until some time in July of this year, so there is no need to rush.

If you are unsure of whether Windows 7 is for you, I have a taste here.

Peace and Grace,
Greg

Twitter: @gbworld

The C# using statement


I had a talk with a colleague today about the using statement. It had come up in a job interview and he was thinking about the using statement at the top of the file. If I were asked about using, I would probably answer “you mean try … finally with a Dispose”.

The following code is nearly identical, when taken from an IL standpoint:

Code sample 1:

private static void GetData(string connectionString)
{
    SqlConnection connection = new SqlConnection(connectionString);
    try
    {
        connection.Open();
    }
    finally
    {
        connection.Dispose();
    }
}

Code sample 2:

private static void GetData(string connectionString)
{
    using(SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();
    }
}

Need proof?

When reverse engineering file 1 to C#, you end up with the following:

private static void GetData(string connectionString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
}
}

Looks just like example 2.
And here is the IL produced when you run this through Reflector (black lines are the same in both files, blue lines are from file 1 and red lines are from file 2):

.method private hidebysig static void GetData(string connectionString) cil managed
{
    .maxstack 2
    .locals init (
        [0] class [System.Data]System.Data.SqlClient.SqlConnection connection)

    .locals init (
        [0] class [System.Data]System.Data.SqlClient.SqlConnection connection,
        [1] bool CS$4$0000)

    L_0000: nop
    L_0001: ldarg.0
    L_0002: newobj instance void [System.Data]System.Data.SqlClient.SqlConnection::.ctor(string)
    L_0007: stloc.0
    L_0008: nop
    L_0009: ldloc.0
    L_000a: callvirt instance void [System.Data]System.Data.Common.DbConnection::Open()
    L_000f: nop
    L_0010: nop
    L_0011: leave.s L_001d
    L_0011: leave.s L_0023
    L_0013: nop

EXTRA LINES:
   
L_0014: ldnull
    L_0015: ceq
    L_0017: stloc.1
    L_0018: ldloc.1
    L_0019: brtrue.s L_0022

    L_0014: ldloc.0
    L_0015: callvirt instance void [System]System.ComponentModel.Component::Dispose()
    L_001a: nop
    L_001b: nop – MISSING FROM FILE WITH USING STATEMENT
    L_001c: endfinally
    L_001d: nop
    L_001e: ret
    .try L_0008 to L_0013 finally handler L_0013 to L_001d
    .try L_0008 to L_0013 finally handler L_0013 to L_0023
}

When do you use using and when do you use a try?

  • If there is ever a chance of having a catch added, use a try instead of using
  • If not, the choice is yours, but the using statement requires less typing.

Peace and Grace,
Greg

Twitter: @gbworld