Last listened to The Ricky Gervais Show 2002-02-09 by Ricky Gervais, Stephen Merchant & Karl Pilkington (on 25 Aug 2010, 16:00)

Git workshop at NNUG Trondheim

I did a git workshop at NNUG Trondheim last week, after Håvard Stranden did a demo and went through the theory beforehand.

I covered: installing msysgit, initializing a repository, creating a .gitignore file, adding to the staging area, comitting to a local repository and (if our Internet access held out) we would have pushed our local repositories to github.com.

Git Workshop alue="always" />

The slides were based on Jason Meridth's excellent 3-part git tutorials.

MonoTouch app: NDC 2010 iPhone app in the App Store now

My first iPhone app is available now in the App Store: NDC 2010. It displays information about each of the 120+ sessions at this years Norwegian Developers Conference. It lists the sessions by day and time, it lists the speakers and contains their bio, and it displays the latest talk on Twitter by following the #NDC2010 hashtag. If the latest version I submitted to Apple gets approved in time, it will also have the ability to plan your own schedule.

It was written in C# using MonoTouch. It is also an open-source app, so you can not only download and use it at this years NDC 2010 conference directly from the App Store, but you can also freely browse and use the source code in any way you want.

Here are some screenshots of the app.

I hope someone finds it useful.

A guide to Twitter that even your dad will understand

My dad just asked me to explain to him how Twitter works. He wanted a short intro explaining what all of the # and @ symbols mean, and how to get "those short URL's". His opinion of Twitter is like many peoples: "I'm not interested in what people are eating for lunch or when they are going to the bathroom". I used to think the same, but that's because I didn't understand it and how to make it a useful tool. Twitter has become useful for me to keep up to date with technology, other software developers, for me to share info, help others and get help from others. It is useful for sharing interesting links with other people. I use it (almost) exclusively for programming and technology. I don't use it for personal stuff. I use Facebook for that. If someone uses Twitter to tell the world pointless drivel about what clothes they are wearing, then I don't follow those people and hence can't see their tweets.

The first thing I recommend is using a Twitter client for Mac/Windows. I use TweetDeck. Without a proper Twitter client, you can never get the most of Twitter. The website is limited, and so are some of the mobile clients, but the desktop clients bring Twitter to life.

You can see from the screenshot above that there are four columns visible, and they all show me different things. In order from left to right, here is what each column shows me:

  1. All tweets from all of the people I am following.
  2. All tweets where people have mentioned me.
  3. All direct messages to me (private messages).
  4. Finally, the last column shows all tweets where people have mentioned a specific keyword I am interested in: the "MonoTouch" keyword.

Followers

When you find a friend, celebrity or just an interesting person, and want to hear more of what they say, you should "follow" them. When you follow a person, they are now on the list of people you follow, and their tweets will show up when you go to Twitter or, for me, in the first column of my TweetDeck. But just because you follow a person and can see all of their tweets, that doesn't mean they follow you and can see yours. If it's a friend of yours, they will probably check which people are following them, see your username and follow you back. If it's a famous celebrity or just some stranger, they might not follow you back.

An @ mention

The second column in my TweetDeck are my "mentions". My Twitter username is alex_york, but if someone who I don't follow said "hello, alex_york" I would never know about it. If they said "hello, @alex_york" then regardless of who they are, where they are, or if I am following them or not, their tweet would show up in that second column. That's how strangers can talk to each other, and that's the whole beauty of Twitter. I could say "hello, @JohnCleese, have you seen Manuel lately?" and he would see my message. He might not reply to it though! In short, it's how you get someone's attention.

A #hashtag

The last column in my TweetDeck is where I follow a keyword that I am interested in: the "MonoTouch" keyword. On Twitter, these keywords are known as "hashtags" because the tag/keyword is preceded by the # symbol. If I were to tweet "I love writing iPhone apps using MonoTouch" then only my followers could see it, but if I said "I love writing iPhone apps using #MonoTouch" then many people around the world might be watching the #MonoTouch hashtag and suddenly my tweet would have a much wider audience. Use a hashtag in your tweet when you want to reach a wider audience than just your followers, and keep a track of hashtags that you are interested in. There are no definitive list of hashtags, they can be anything you like, such as #ClimateChange or #iPad.

Hashtags are really interesting when it comes to timely information. The moment that Apple announced the iPad, on Twitter it was fun to watch what everyone was saying about it by following the #iPad hashtag. When Tottenham Hotspur play, I noticed that a lot of people were talking about the game using the #COYS hashtag (come on you spurs!).

Short URL's

Finally, because you can only have 140 characters in a tweet, when you want to share a link with someone, you will want to shorten it down. Some popular URL shortening services are TinyURL and bit.ly. You can go to their websites and do it manually. But that's no fun! Luckily, TweetDeck will shorten URL's for you automatically. There is a button that you can click to enable the auto-shortening of URLs.

Once enabled, you just paste a long URL in there and a few seconds later it will replace it with a short one. Easy! Your link is now ready to be shared on twitter leaving you lots of space to tell people what the link is.

Happy tweeting ;-)

This post has been removed by the author.

Check out this similar post by Paulio: Creating a very simple MonoTouch application without the Interface Builder.



Understanding the C# var keyword

In recent weeks I have been helping my boss to recruit for new C# developers by sitting in and asking the candidates some technical questions. One of my questions was:

Can you explain to me the C# 'var' keyword?

The var keyword was introduced in C# 3.0 several years ago, so this question wasn't considered to be a modern or difficult question (such as asking for an explanation of the more recent dynamic type) - but I was surprised how many developers didn't get it right. Plus, while browsing a MonoTouch article recently, I felt compelled to reply to an ill-informed comment where someone said "var is overused. You should strongly type your variables instead." This, along with an answer a candidate gave me in a recent interview when he said "isn't the var keyword slower?" prompts me to write this post.

I would sum it up as follows: the var keyword is a shorthand way of allowing the compiler to infer the type for you - to save your fingers some work.

Some things need to be made quite clear:

  • Using var doesn't make your variables "weakly typed". All variables declared as var are strongly typed! (C# is a statically typed language - everything is strongly typed!)
  • var isn't a type. The actual type is figured out at compile-time.
  • Due to the fact that the actual types are resolved at compile-time, the var keyword cannot be "slower".
  • It sometimes increases code readability.
  • It sometimes decreases code readability.
  • It is sometimes optional, but sometimes required.

The var keyword is not a type. System.String is a type. Int32, decimal and object are types, but var is not a type. The actual type is resolved at compile-time: it is inferred based on the right-hand-side of the equals sign. Here, the variable i is strongly typed as an integer:

var i = 3;

It is identical to typing this:

int i = 3;

In both of those examples the variable i is strongly typed as an integer. Due to that fact, this will not compile:

var i = 3;
i = "foobar";

That's right, it's not a bug, it's not "sloppy coding", or an explosion at runtime: it's a compilation error. Due to the fact that the keyword var is inferred at compile-time, this statement will not compile either:

var i;

Nor will this:

var i = null;

The last one couldn't possibly compile: what if I wanted i to be an integer, then assigning null to it doesn't make sense, it would be equivalent to this statement (which also does not compile):

int i = null;

I mentioned that there are times when the var keyword can increase code readability, but also decrease it. I think there is no need for it on the first line of code in the sample below, compared with the equivalent second line:

var i = 3;
int i = 3;

My variable i is an integer, but I haven't saved myself any keyboard strokes or saved the reader some time: I think I have slightly decreased the code readability by using var. But in the example below I think that I have increased code readability on the first line, in comparison to the equivalent second line:

var config = new List<KeyValuePair<string, string>>();
List<KeyValuePair<string, string>> config = new List<KeyValuePair<string, string>>();

In the previous two examples the use of the var keyword is optional. Whether using it results in more or less readable code is a choice that the programmer must make. Using the var keyword in the example below is not optional, it is required:

var query = customers.Select( c => new { Name = c.Name } );

That was a LINQ lambda expression returning an anonymous type. The same can be expressed using LINQ's comprehension syntax:

var query = from c in customers
select new
{
Name = c.Name
};

In both of those examples, an anonymous type is being returned from the LINQ expression. Don't be fooled though: even an anonymous type is strongly typed. It is another kind of "shorthand" - instead of saying (as with the var keyword) I know the type, but I'm too lazy to write it out, with anonymous types you are saying "I know the type, but I'm too lazy to create the type myself - so I'll let the compiler do it". Due to the fact that the compiler will create the type for us, we have no option but to use the var keyword to create the type.

With a new version of C# looming - developers risk falling behind the pack if they aren't even up to speed with the current version of C#.