Skip to content

David Turvey's Blog

All About Development

Archive

Category: Uncategorized

Google released a new programming language named Go recently, by the sounds of it they are hoping it will solve developer woes and make development easier. I don’t agree with their reason for creating it to start off with, from the Go FAQ page: “Go was born out of frustration with existing languages and environments for systems programming. Programming had become too difficult and the choice of languages was partly to blame.” Personally I don’t find programming difficult but maybe that’s just because I’m looking at a different set of problems than the guys behind Go.

Before I continue let me just make it clear that I’m a .NET developer (I was a Delphi developer many years ago) and a fan of the Microsoft development environment so what I have to say is influenced by my experiences with Microsoft tools and languages.

While I think it’s admirable that Google wants to simplify programming, I personally don’t see anything enticing about the language to make the move to it. These are my problems with the language in it’s current form, who knows maybe future versions will be better :)

  • No generics – I understand that it must be difficult to include generics in a compiler but come on, generics are so useful! (link)
  • No exceptions – This I don’t understand! Come on, there are meant to be some sharp guys working on this project – how can they not include exceptions?! (link)
  • No type inheritance – Now this is the one point that makes me think this language isn’t much better than VBScript. (link)
  • No overloading of method or operators – This isn’t a big deal but it would be nice. (link)

So those are my main dislikes about the language, but there are some other problems too. I thought I’d give it a try even though I wan’t keen on it so I went to the download page and you have to download the source and compile the compiler, that’s where I lost interest in Go! How hard is it to provide binaries for the most common platforms! I’m assuming that it is just a command line compiler and that there is no IDE, which is another negative.

There are two things that they have done that are cool; one is that they have build in some clever support for concurrency using CSP, and the other is that Go will be available in Chrome and as a plugin for other browsers. This could be where Go finds its niche, personally I’d like to see a language more powerful than JavaScript in the browser.

I must also mention that Go is an experimental programming language so I’m probably being a little harsh :)

It looks like Google Street View is finally coming to South Africa, my dad spotted this Google car driving past his house in Midrand the other day – driving around a gated community I might add :)

Google Street View Car in Midrand, Gauteng, South Africa

Google Street View Car in Midrand, Gauteng, South Africa

My dad managed to stop the driver and have a chat with him, apparently Cape Town and Pretoria are done, and there are 4 teams working the Johannesburg area. No mention when it’s going live but I guess the driver wouldn’t know that.

Google Maps for South Africa has gone live though; check it out at http://maps.google.co.za/

For those that are interested here are some of the RSS feeds for the blogs that I follow:

  • Channel 9
    Channel 9 is the MSDN video website for all things dev related.
  • dotnet.org.za
    Not a create site and most of the blog just rehash posts from other blogs but once in a while it has something useful.
  • Eric Lippert’s Fabulous Adventures In Coding
    This is a blog I love, this guy works on the .Net Framework and posts some awesome goodies. If you want to be a good dev you should understand the framework’s internals and this blog will help with that.
  • InfoQ (go to the site to create a custom feed)
    A lot of the stuff on here is high level, you won’t find many coding examples etc. But it has some great posts and the range of articles is very broad.
  • Microsoft StyleCop
    This is just so that I know when StyleCop is updated.
  • Mike Taulty’s Blog
    This blog pretty much focuses on SilverLight and Mike Taulty has a number of webcasts on SilverLight if you need to get going with it.
  • Microsoft Architecture Center
    Just as the name says, Architecture related articles, some interesting, some boring.
  • Mythical Man Moth
    A blog I discovered by another South African, I haven’t gone through all his posts yet but there are some interesting ones.
  • rohland.co.za
    Another South African blog I discovered just a few days ago, I’m still going through the posts.

Then some blogs by various developers, I’m not going to comment on them, I’m sure you probably know most of these blogs already:

If you’re frustrated and need a good laugh plug into this feed ;)
ICanHasCheezburger

So after my little discovery of IEnumerable on the string type I thought I’d see what other interesting interfaces I’ve missed, and I thought I’d start off with the interfaces that exist on the .NET primitive types. First off, IConvertible.

The .NET documentation describes IConvertible as “Defines methods that convert the value of the implementing reference or value type to a common language runtime type that has an equivalent value”; basically it’s an interface that exposes methods to convert the implementing type so all the available .NET primitive types. This interface is implemented by all the .NET primitive types, i.e. string, int, bool, etc.

The IConvertible interface consists of the following:

  • bool ToBoolean(IFormatProvider provider);
  • byte ToByte(IFormatProvider provider);
  • char ToChar(IFormatProvider provider);
  • DateTime ToDateTime(IFormatProvider provider);
  • decimal ToDecimal(IFormatProvider provider);
  • double ToDouble(IFormatProvider provider);
  • short ToInt16(IFormatProvider provider);
  • int ToInt32(IFormatProvider provider);
  • long ToInt64(IFormatProvider provider);
  • sbyte ToSByte(IFormatProvider provider);
  • float ToSingle(IFormatProvider provider);
  • string ToString(IFormatProvider provider);
  • object ToType(Type conversionType, IFormatProvider provider);
  • ushort ToUInt16(IFormatProvider provider);
  • uint ToUInt32(IFormatProvider provider);
  • ulong ToUInt64(IFormatProvider provider);

Now you’re probably think but hey I’ve never seen ToInt32() as a method on a string, and you’d be right. It is there, it just isn’t exposed, the method ToInt32 is not public but it is explicitly defined for the interface so you can only get to the method if you cast string to IConvertible. So doing the following would give you an int with the value of 123:


string input = "123";
int output = ((IConvertible)input).ToInt32(null);

All that String.ToInt32() is doing in the background is calling System.Convert.ToInt32():


int IConvertible.ToInt32(IFormatProvider provider)
{
    return Convert.ToInt32(this, provider);
}

Which it turn calls int.Parse():


public static int ToInt32(string value, IFormatProvider provider)
{
    if (value == null)
    {
        return 0;
    }

    return int.Parse(value, NumberStyles.Integer, provider);
}

Anyway, I hope that’s useful for you.

I discovered something cool about strings the other day, and I must admit it is incredibly obviously and I do feel a rather stupid for not knowing this. I’ve never seen any code using this technique to enumerate through the characters in a string, maybe you have?

So normally developers would usually do something like this to enumerate through the characters in a string:


char[] charArray = "Hello World".ToCharArray();
foreach (char ch in charArray)
{
    // Do something (with ch)
}

Or maybe:


string value = "Hello World";
for (int index = 0; index < value.Length; index++)
{
    char ch = value[index];
    // Do something (with ch)
}

Or some other technique.

So I wanted to see if string implemented IFormattable, don’t ask why, it was a random thought going through my head and I discovered string implements a number of interesting interfaces, namely:

  • IComparable
  • ICloneable
  • IConvertible
  • IComparable
  • IEnumerable
  • IEnumerable
  • IEquatable

The most interesting being IEnumerable because it allows you to do the following:


foreach (char ch in "Hello World")
{
    // Do something (with ch)
}

And you can do LINQ queries directly against the characters in a string:


var ordinalValues = from ch in "Hello World"
                    select (int)ch;

Which I think is pretty cool :)