Using "var" to simplify code and avoid redundancy

You've probably already heard of the new "var" keyword that you can use to declare variables in your .NET code. I wanted to clear up some quick myths and give a quick overview of when it's most valuable.

If you haven't heard of it, you can now use this syntax:

var c = new Cat();

Instead of this:

Cat c = new Cat();

As Jeff Atwood mentioned, it's a great way to avoid redundancy. It's obvious that you're creating a "Cat" object, why do you have to say it twice?

The most important thing to realize, is that it's NOT a var like in JavaScript or other languages (DIM in VB). It really is 100% a "Cat" object, complete with intellisense. The generated IL would be no different than specifying the type when you declare it. It's simply a compiler trick.

Another important thing to remember is that you the assignment must be combined with the declaration. If that wasn't the case, readability would be very poor.

var myName = "Jason"; //Allowed
var yourName; //Not allowed
yourName = "Bob"; //Glad you can't do this

What are some really good examples of when it ideally should be used:

List<Dictionary<int, string>> customers = new List<Dictionary<int, string>>(); //Yuck!
var customers = new List<Dictionary<int, string>>(); //Yay!

OrderRepository orderRepo = (OrderRepository)ctx.GetObject("orderRepository"); //Yuck!
var orderRepo = (OrderRepository)ctx.GetObject("orderRepository"); //Yay!

string name = "Jason Young"; //Kinda yucky
var name = "Jason Young"; //Kinda better

As you can see, those examples have obvious redundancy. Using the "var" keyword increases readability, and makes it easier to change if needed.

There are certainly times when its use is questionable. In the following example, I'm calling a function that returns some data. Since I'm not explicitly defining the type that is being returned from that function, I have to do some digging to figure out the type being returned. In this case, you'll have to define the correct way to handle it in your coding standards.

var data = GetData();

Another potential readability issue comes up in the following case. You might not want to use the "Circle" specific methods (Circle inherits from Shape).

Shape s = GetCircle(); //I see what you're doing
var s = GetCircle(); //Do you want a shape, or a circle?

Aside from a couple of decisions that need to be made in your organization, I think this is a great addition, and should make our lives as developers a little bit easier. It's just another tool for our tool belt. With great power comes great responsibility

Like this post? Please share it!

See a mistake? Edit this post!

Using an army and luck to reach critical mass

This post is going to explain the importance of your product reaching critical mass. When I say "product", I mean an actual product you're selling, or simply a website or blog. When I'm talking about critical mass, I'm describing the point at which your product becomes viral, sometimes known as the network effect. This should be a lesson to anyone thinking of creating their own product or service.


Above, you'll see the typical technology adoption bell curve. What you need to realize is that you're starting on the left, and you're trying to get up the hill. Do you think it's easy? Well, judging by Youtube, twitter, milliondollarhomepage, Digg, or myspace, it must be easy!

The truth is, you should have a path to success. Here are just a couple of paths that have worked for other products:

  • Create a product that is leaps and bounds better than anything your potential customers have ever seen - An example is Google, which was originally created by students in college. The brilliance of the algorithm and its implementation were the start of a massive company.
  • Have an army of followers that listen to your advice - A great example is Steve Jobs. Before he even makes a new product announcement, people line up at Apple stores. People trust that he'll make cool stuff, so they listen to whatever he says. You can bet that if Steve Jobs mentioned your product, you would people lining up at your door to buy it.
  • Get lucky - It happens time and time again. Multiple products are released at the same time, all with similar features and price. Sometimes one of them gets lucky, and the others die. An example is the VHS vs Betamax format war. VHS was considered the inferior product, yet it went on to become the de facto standard.
  • Create a product that is viral by nature - Twitter and Myspace come to mind. Once one person joins, they're begging their friends to use if. If they don't, the service is useless. The result is that you get an army of free advertisers talk to your key demographic.
  • Spend a ridiculous amount of cash to bombard users with advertising - infomercial's and those annoying "we'll double the offer" commercials come to mind. Hopefully I'm making the situation look difficult. I couldn't find any concrete numbers, but you can be sure that more than half of online businesses fail within the first couple of years. That includes well-funded businesses. If you expect to start the next Fog Creek Software while working part time in the evenings, you need to have a plan.

The best advice I can give you is to do whatever it takes to get your product into the hands of as many people as possible. It might mean making partnerships with someone of influence, or it might mean creating a viral marketing campaign. It might also mean that you'll have to give your product away for free, build up your army of followers, and then invent another great product. If you already have a product with a good user base, you're probably already in good shape. If you are just starting out, don't think that people will magically find you, unless you're counting on the "lucky" path I described.

Like this post? Please share it!

See a mistake? Edit this post!

DreamHost disallows use as a backup service

I just received this email from DreamHost:

Dear Jason,

Our system has noticed what seems to be a large amount of "backup/non-web" content on your account (#xxxx), mostly on user "xxxx" on the web server "xxxx".

Some of that content specifically is in /home/superjason/Backup (although there may be more in other locations as well.)

Unfortunately, our terms of service ( state:

The customer agrees to make use of DreamHost Web Hosting servers primarily for the purpose of hosting a website, and associated email functions. Data uploaded must be primarily for this purpose; DreamHost Web Hosting servers are not intended as a data backup or archiving service. DreamHost Web Hosting reserves the right to negotiate additional charges with the Customer and/or the discontinuation of the backups/archives at their discretion.

At this point, we must ask you to do one of three things:

  • You can delete all backup/non-web files on your account.
  • You can close your account from our panel at: (We are willing to refund to you any pre-paid amount you have remaining, even if you're past the 97 days. Just reply to this email after closing your account from the panel.


  • You may now enable your account for backup/non-web use!

If you'd like to enable your account to be used for non-web files, please visit the link below. You will be given the option to be charged $0.20 a month per GB of usage (the monthly average, with daily readings) across your whole account.

We don't think there exists another online storage service that has anything near the same features, flexibility, and redundancy for less than this, so we sincerely hope you take us up on this offer!

In the future, we plan to allow the creation of a single "storage" user on your account which will have no web sites (or email). For now though, if you choose to enable your account for backups, nothing will change (apart from the charges).

If you want to enable backup/non-web use on this account, please go here:

If you choose not to enable this, you must delete all your non-web files by 2008-06-29 or your account will be suspended.

If you have any questions about this or anything at all, please don't hesitate to contact us by replying to this email.

Thank you very much for your understanding,
The Happy DreamHost Backup/Non-Web Use Team


Admittedly, the primary reason I chose them was because they're a great backup solution. I didn't realize that it was against their terms of service, in fact, there is a ton of information out there about using rsync to backup your files to them. I've been doing it for well over a year now, and I've been recommending the service to others.

I had heard many bad things about DreamHost, but they were working great for backups. Now you can't use them for that, what do they have going for them? I can't imagine many users have 400GB+ websites that their hosting. If they are, I have a hard time believing they're using cheap shared hosting!

Now I'm looking into other backup solutions, and it's looking pretty grim. Since my server and laptop both run Windows 2008, there aren't many solutions available. For example, Mozy requires you to use their business version, which is ridiculously expensive.

Another option is JungleDisk, which uses Amazon's S3 service. I would be looking at paying $30/month to backup around 200GB.

Does anyone have other ideas? The solution has to be automatic, so that I don't have to count on remembering to do it. It also has to be off-site, because I don't want to lose all of our photos of our house burns down.

Like this post? Please share it!

See a mistake? Edit this post!

Jason Young I'm Jason Young, software engineer. This blog contains my opinions, of which my employer - Microsoft - may not share.

@ytechieGitHubLinkedInStack OverflowPersonal VLOG