Wednesday, November 7, 2007

Soma introduces VS2008 Release at TechEd

Microsoft has committed themselves to delivering a release of their Visual Studio 2008 product family in November 2007. Read the press release here! Jibbeee!

Suddenly my VS2008 Beta2 VPC problems don't feel as grave as they felt yesterday!

The .NET Framework 3.5, this is the .NET Framework 2.0SP1, adding the new C# 3.0 features, support and assemblies and the .NET Framework 3.0 assemblies, will be released with the VS2008 but will also be available to end-users through Windows Update (it's an optional download to start with?!).

Tuesday, November 6, 2007

My VS2008 Beta 2 expired!

I was in the middle of developing a little sample using my Visual Studio 2008 Beta 2 VPC, which I got from Microsoft this summer as a Beta tester, when suddenly a dialog opened up and said something like This version of Windows 2003 Server that you are using will expire in 24 hours and will stop working (or something like that, this is from memory).

Frustrated, but I still went into the Microsoft Beta program again and started downloading the ISO image of the Visual Studio 2008
Professional Beta 2
(note, I'm not downloading the VPC again).

Anyways, the file has an extension of .img and now I just have to get it opened somehow so that I can install it (project of tomorrow). Anyways, I also noticed that ScottGu wrote about this a couple of days before the end of last month, in his Important Notice: VS 2008 Beta2 VPC Images Expiring on Nov 1st weblog.

Sunday, November 4, 2007

C# program formatter for weblog

I was looking for a way of formatting my C# code and I finally found it. This is a webpage that allows me to copy my source code into a textarea and get back a nicely formatted HTML to paste directly into my weblog. It's pointed out by Scott Cate where he refers to an online c# code format site. So I'm trying it out. What do you think?
public class MyClass
{
public string this[int index]
{
get
{
return m_Names[index];
}
protected set
{
m_Names[index] = value;
}
}
string[] m_Names;
//Rest of the class
}
06/11/2007 author added: I have now converted the last couple of weblogs and reformatted the code snippets using the above mentioned formatter. It works ok, but a few times I had to manually change the resulting HTML for it to work correctly. Especially if a line ends with a // comment that contains a couple of quote-marks. I also noticed that the formatter doesn't recognize 'var', 'for', 'select' and other C# 3.0 keywords - otherwise, it works fine and will probably support the new keywords as time goes by.

Saturday, November 3, 2007

Things you might not know about C# 2.0

When writing my Yet another C# 3.0 new feature listing... and browsing the web I ran into the following interesting things I had not realized about C# 2.0. Thought I might share them with you.

a) Delegate inference

Did you know that the C# compiler can infer the delegate type? This means that you can write code like this:
SomeDelegate del = SomeMethod;
and the 'SomeMethod' is inferred to be of type SomeDelegate.

So you don't have to write it the old-style:
SomeDelegate del = new SomeDelegate(SomeMethod);
...saves a few keystrokes.

b) Property/Indexer get/set visibility

You can easily make indexers in C# and even make a getter more visible than a setter, like this sample shows:
public class MyClass
{
public string this[int index]
{
get
{
return m_Names[index];
}
protected set
{
m_Names[index] = value;
}
}
string[] m_Names;
//Rest of the class
}
Just remember that the get/set visibility can only narrow the visibility of the actual Property/Indexer.

c) yield return in IEnumerable

When writing IEnumerables you can use the 'yield return' statment to simplify your coding, as shown in this sample:
public class CityCollection : IEnumerable<string>
{
string[] m_Cities = { "New York", "Paris", "London" };

public IEnumerator<string> GetEnumerator()
{
for (int i = 0; i < m_Cities.Length; i++)
{
yield return m_Cities[i];
}
}
//Rest of the class
}
The code will continue running from the 'yield return' point when the return value has been used and the next item of the IEnumerable is required.

We use the IEnumerable like this:
CityCollection cityCollection = new CityCollection();
foreach (string city in cityCollection)
{
Console.WriteLine("City: " + city);
}
Could be helpful to know!

d) suppress compiler warnings inline

If the compilation of your code always returns a warning and you would like to suppress it, but not all such warnings, then you can use 'pragmas', like this:
// Disable 'field never used' warning
#pragma warning disable 169
public class MyClass
{
int m_Number;
}
#pragma warning restore 169
However, after the 'warning restore' statement you may still get the warning. Could be convenient.

more stuff...

See more cool stuff at Create Elegant Code With Anonymous Methods, Iterators, And Partial Classes

Yet another C# 3.0 new feature listing...

I blogged about .NET 3.0, .NET 3.5, VS2008 "Orcas", C# 3.0 and more in my .NET Framework 3.0, Implicitly typed local variables and the Extension Methods weblogs.

There are many sites that have collected information and written about the new features of C# 3.0, like developer.com, Wikipedia and most notibly Scott Guthrie in his New C# "Orcas" Language Features weblogs: part-1, part-2 and part-3. If you haven't read Guthries, you should!

Anyways, from all of these weblogs and sites (and even more than those mentioned above) I have compiled the following descriptions of each feature. I have created my own samples but also copied some from the sites above, so if you require more information on any of the samples or features, please read the references above.

a) Automatic Properties

...which allows you to create simple properties without
declaring the storage variables and the simple (and futile) getters and setters.

Sample:
// Automatic Properties
public class Person
{
public string ID { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
public int Age { get; set; }
}
public class Address
{
public string Street { get; set; }
public int Number { get; set; }
public string City { get; set; }
public string Country { get; set; }
}
The compiler will automatically generate a private instance variable and the appropriate getter and setter.

b) Object initializers

...allowing the construction of objects and members using
the default constructor and appropriate member setters in one easy go.

Sample:
// Object initialization
Person p1 = new Person
{
ID = "P0001",
Name = "Davíð",
Age = 39,
Address = new Address
{
Street = "Bakkagerði",
Number = 2,
City = "Reykjavík",
Country = "Iceland"
}
};
This syntax is a lot simpler to write than using the default constructor and then all the necessery setter method calls.

c) Collection initializers

...now made as simple as array
initialization, without any additional programming.

Sample:
// Collection initialization
List<Person> persons = new List<Person>
{
new Person { ID="P0002", Name="Alfred", Age=39,
Address=new Address { Street="Seilugrandi" } },

new Person { ID="P0003", Name="Aðalsteinn", Age=38 },
new Person { ID="P0004", Name="Sveinn", Age=38 },
new Person { ID="P0005", Name="Eymundur", Age=43 },
new Person { ID="P0006", Name="Markús", Age=39 },
new Person { ID="P0007", Name="Guðmundur", Age=38 },
new Person { ID="P0008", Name="Bjarni", Age=38 },
new Person { ID="P0008", Name="Richard", Age=20 }
};
You can use this syntax for all classes that implement the IEnumerable interface and has an Add method. For example, instead of MyList list = new MyList(); list.Add(1); list.Add(2); you can now write MyList list = new MyList { 1, 2 };. Simple and convenient.

d) Implicitly typed local variables

...which permits the type of local variables
to be inferred from the expressions used to initialize them.

Sample:
// Inferred variable types
var txt1 = "Implicitly txt becomes a 'string'";
string txt2 = "Same as above";
var i = 7; // Implicit declaration of an integer
int j = 7; // Same as above
This does not make C# anything but a stronly type language because you can only use this feature for local variables and each variable is always of the same type. This feature was necessery for it is required for the declaration of anonymously typed variables (coming below).

e) Implicitly typed local arrays

...are a form of array creation and initialization
that infers the element type of the array from an array initializer.

Sample:
// Inferred array types
// Same as int[] intArray = new int[]...
var intArray = new[] { 10, 9, 4, 7 };
var txtArray = new[] { "a","sldkj","oowu","9837","ls" };
Nice new feature, also necessery as mentioned for implicitly typed local variables above.

f) Anonymous types

...allowing classes to be automatically created, behind the scenes,
when you require a storage for a set of data instead of a single element of data.

Sample:
// Anonymous types
var h = new { hair="black", skin="green", teethCount=64 }
var u = new { Name = "James" }
The instantiation new { ... } will be construct a new class that is created behind the scenes. This class is unknown to the programmer so its name obviously can't be written out in the declaration of the variable, hence the var keyword as mentioned for implicitly typed local variables above.

g) Extension methods

...which allows developers to add new methods
to existing class without having to extend it or compile it. This is done by including the this keyword in the first parameter of a method on another static class.

Sample:
// Simple Extension Method
public static bool IsValidEmailAddress(this string s)
{
Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
return regex.IsMatch(s);
}
This method extends all strings because the 'this keyword parameter' is of type string. The implementation of the method simply checks if the content of the 'this' string is in the format of an email address.

The usage:
// Simple Extension Method Usage
string email = "alfred@ruedenet.is";
// Prints "True"
Console.WriteLine(email + " is an email? " +
email.IsValidEmailAddress());
// Prints "False"
Console.WriteLine("alfred@ruedenet is an email? " +
"alfred@ruedenet".IsValidEmailAddress());
It's as simple as that.

Sample:
// Another Extension Method
public static bool In(this object o, List<Person> c)
{
foreach (object i in c)
{
if (i.Equals(o))
{
return true;
}
}
return false;
}
This method extends all objects because the 'this keyword parameter' is of type string. In addition, the extension method requires a single parameter of type List. The implementation checks if the 'this' object is contained within the list provided as parameter.

The usage:
// Another Extension Method Usage
Console.WriteLine("Davíð is in persons? " +
"Davíð".In(persons)); // Prints "False"
Console.WriteLine("Guðmundur is in persons? " +
"Guðmundur".In(persons)); // Prints "True"
Now, for your information the string "Davíð" is not in the list of persons, however "Guðmundur" is. So, the two lines above will print out 'False' and 'True' in that order.

When you have Extension methods some may think that C# is stretching a bit too far into Duck typing land. This is understandable because with Extension methods the use of a type becomes a little more about what methods an object exposes and little less about what type the object is.

Don't get too defensive, C# is still strongly typed and Extension methods are just another shortcut programming. What I mean is that the 'IsValidEmailAddress' method above could also have been written as an old-style 'public static' method like this:
// Simple Static Method
public static bool IsValidEmailAddress(string s)
{
Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
return regex.IsMatch(s);
}
Note that all I did wat take the 'this' keyword out and we have a regular old-style 'public static' method as we have all done them through the years.

Now, instead of doing "alfred@ruedenet.is".IsValidEmailAddress() - as I did above using the Extension method - I would simple do IsValidEmailAddress("alfred@ruedenet.is"). IMHO, this old-style simply doesn't have the elegance introduced into C# with the Extension methods! Also, the old-style doesn't show the 'IsValidEmailAddress' method in the IntelliSense autocompletion drop-down, but Extension methods do! ...and that is cool!

h) Partial methods

...allow us to create partial classes that contain methods that may
or may not become part of the public interface of the class - this depends
on whether some other partial class will actually override it.

There are a few comments on using partial methods: 1) they are only allowed in partial types; either classes or structs, 2) they always return void and 3) forget it, there are no other kinds of partial members (no partial variables, no partial properties, etc. :-)

File1.cs:
// MyPartialClass
public partial class MyPartialClass
{
public void DoA()
{
LogA("A-Begin");
// Do something
LogA("A-End");
}
public void DoB()
{
LogB("B-Begin");
// Do something
LogB("B-End");
}
partial void LogA(string txt);
partial void LogB(string txt);
}
Note the two partial methods at the bottom. Without anything else, if we simple instantiate this 'MyPartialClass' and call the 'DoA' and 'DoB' methods, nothing will happen because 'LogA' and 'LogB' have not been implemented. The compiler will simply remove the declarations of the methods and all usages of them. The compiler can actually allow it self to do that because partial methods never return values.

However, if we add the following second file:File2.cs:
// MyPartialClass
public partial class MyPartialClass
{
partial void LogA(string txt)
{
Console.WriteLine(txt);
}
}
All we have don't is add the 'LogA' method to the class. Now the compiler wont remove the calls to this method. Now, if we instantiate the 'MyPartialClass' and call the 'DoA' and 'DoB' methods, 'DoB' will continue to do nothing, but 'DoA' will call the 'LogA' method twice and therefore print a couple of text lines.

It took me a little while to get used to the idea of partial types (introduced in C# 2.0) being necessery to simplify the development tools generation of the GUI designer classes. I'm still not completely at ease with this approach and I still think it can be, and should have been, solved using good old inheritence. So I guess it will take me a while to get use to the idea of partial methods :-)

i) Lambda expressions

...are an evolution of anonymous methods that provides improved
type inference and conversions to both delegate types and expression trees.

There are many places that can give you good descriptions of the Lambda functionality in C# 3.0. A very good introduction would be the Lambda Expressions and Expression Trees: An Introduction feature on The Code Project website. But you can also continue reading below before jumping to the references :-) Lets start with a delegate example:

Sample using delegates:
// Declare the AFilter delegate type
public delegate bool AFilter(string str);

// Define a user of the AFilter delegate type
public string findFirstMatch(List<string> list,AFilter filter) {
foreach(string str in list) {
if (filter(str)) return str;
}
return null;
}

// Define an anonymous delegate of the AFilter type
AFilter myFilter=delegate(string str) {
return str.StartsWith("A");
};

// Define a list of values
var strings = new List<string> {
"John", "Kane", "Krugman", "Andrea", "Hornby"
};

// Prints "Andrea"
Console.WriteLine(findFirstMatch(strings,myFilter));
This is the old-style, without lambda expressions.

Sample using Lambda-style:
// Defining an anonymous delegate of the AFilter type
AFilter myFilter = str => str.StartsWith("H");
And now I can use the 'myFilter' anywhere that the AFilter delegate is required.

In addition the C# 3.0 compiler can infer the translation of Lambda expressions to either strongly-typed function delegates (as above) or strongly-typed expression trees.

Expression sample:
// Defining the same filter as an expression
Expression<AFilter> filtExpr = str => str.StartsWith("J");

// Prints "str"
foreach(ParameterExpression param in filtExpr.Parameters) {
Console.WriteLine(param.Name);
}

// Prints "str.StartsWith("J")"
Console.WriteLine(filtExpr.Body);
Console.WriteLine(findFirstMatch(strings,
filtExpr.Compile())); // Prints "John"
This constructs the 'aFilterExpression' into an Expression object that can't be sent directly into the 'findFirstMatch' function above but can be used to, for example, make SQL syntax. How this works is that the C# 3.0 compiler actually knows about the Expression class (part of System.Linq.Expressions) and can handle it specifically to compile our source code into a data structure as well as a function. The last line of code above calls the 'Compile' method of the expression to get the function pointer and sents it into the 'findFirstMatch' method, which uses the compiled expression to print out "John".

This new feature of the C# 3.0 compiler, to compile into a data structure is not that new and has been available in LISP for a long time. To learn more about that see Ian Griffiths take on C# 3.0 and LINQ - Expression Trees. Ian also talks about how to use these Lambda expressions to make code on the run, see his Generating Code with LINQ weblog.

j) Language Integrated Query (LINQ) expressions

...provideS a language integrated syntax for
queries that is similar to relational and hierarchical query languages such as SQL and XQuery.

I think Linq is propably the reason for most of the new features mentioned above. Linq is an extensive add-on the language with it's SQL-like syntax and features. Below I will be making three samples to explain the overall concept but the whole thing would be way to long for this weblog so I will start by referring you to the LINQ Introduction features at The Code Project website: Part 1, Part 2 and Part 3.

Linq is a collection of extensions methods that can be used to make queries on specific classes. We will start by looking at queries on normal classes stored in lists, then we will look at making Linq queries on XML documents and end by looking at making queries on traditional database structures.

Sample 1, Object queries:
// Linq queries on the persons list initialized earlier
IEnumerable<Person> young = persons.Where(p => p.Age<39);
Console.WriteLine("How many persons are younger than 39? " +
young.Count()); // Prints "5"
Console.WriteLine("The oldest person is how old? " +
persons.Max(p => p.Age)); // Prints "43"
Console.WriteLine("What is the average age of all persons? " +
persons.Average(p => p.Age)); // Prints "36,625"
var allAlfredHomes = persons.Where(p =>
p.Name.Equals("Alfred")).Select(p =>
new { p.Name, p.Address.Street });
foreach (object h in allAlfredHomes)
{
Console.WriteLine(h); // Prints "Seilugrandi"
}
Allows queries directly into the object structure of your program.

Sample 2, XML queries:
// Linq queries on the following XML document
XDocument people = XDocument.Parse(""+
"<people>"+
"<person age='32'>"+
"<firstname>Scott</firstname>"+
"<lastname>Guthrie</lastname>"+
"</person>"+
"<person age='32'>"+
"<firstname>Susanne</firstname>"+
"<lastname>Guthrie</lastname>"+
"</person>"+
"<person age='50'>"+
"<firstname>Bill</firstname>"+
"<lastname>Gates</lastname>"+
"</person>"+
"</people>");

// All persons whos names start with "S"
IEnumerable<XElement> sElements =
people.Descendants("person").Where(p =>
p.Element("firstname").Value.StartsWith("S"));

// Prints "Scott" and "Susan"
foreach (XElement p in sElements)
{
Console.WriteLine(p.Element("firstname").Value);
}

// All persons whos names starts with "S", more info returned
IEnumerable<Person> sPersons = people.Descendants("person").Where(p =>
p.Element("firstname").Value.StartsWith("S")).Select(p =>
new Person { Name = p.Element("firstname").Value + " " +
p.Element("lastname").Value,
Age=Convert.ToInt32(p.Attribute("age").Value) } );

// Prints "Scott Guthrie (32)" and "Susan Guthrie (32)"
foreach (Person p in sPersons)
{
Console.WriteLine(p.ToString());
}
The interesting thing here is that the Linq XML feature requires you to use the System.Xml.Linq.XDocument but not the System.Xml.XmlDocument.

Sample 3, SQL queries:
// Linq queries into a database
BankAccountsDataContext bankAccountsDB = new BankAccountsDataContext();
IEnumerable<BankAccount> bankAccounts =
bankAccountsDB.BankAccounts.Where(p =>
p.Name.StartsWith("B"));

foreach (BankAccount b in bankAccounts.AsEnumerable())
{
Console.WriteLine(b.Name+" "+b.Balance);
}

// Prints "900,0000"
Console.WriteLine("Min:" +
bankAccountsDB.BankAccounts.Min(p => p.Balance));

// Prints "1000,0000"
Console.WriteLine("Avg:" +
bankAccountsDB.BankAccounts.Average(p => p.Balance));

// Prints "1100,0000"
Console.WriteLine("Max:" +
bankAccountsDB.BankAccounts.Max(p => p.Balance));
The simplest way of getting the 'BankAccountsDataContext' created is to use the new VS2008 feature of adding a "LINQ to SQL Classes" (DBML) project item to your project.

k) The new LINQ syntax

...allows us to write our queries without using the 'Where' and 'Select' extension methods used above.

Extension-style:
IEnumerable<Person> sPersons =
people.Descendants("person").Where(p =>
p.Element("firstname").Value.StartsWith("S")).Select(p =>
new Person {
Name = p.Element("firstname").Value + " " +
p.Element("lastname").Value,
Age=Convert.ToInt32(p.Attribute("age").Value)
}
);
Can be converted to the following.

Query-style:
var sPersons2 = from p in people.Descendants("person")
where p.Element("firstname").Value.StartsWith("B")
select new Person {
Name = p.Element("firstname").Value + " " +
p.Element("lastname").Value,
Age = Convert.ToInt32(p.Attribute("age").Value)
};
Isn't that cool!?

Sunday, October 28, 2007

My Wireless Network Connection was not visible in my VPC on my Windows XP host

I have been using Microsoft Virtual PC (MSVPC) for a long time now and have a lot of virtual machines (VPCs) configured for different purposes and reasons. Lately I have been moving my VPCs between hosts and ran into the following problem on one of those.

I had installed MSVPC on this new computer, but everytime I opened one of my VPCs I got the message "The emulated ethernet adapter not available..." or something of that sort. On the Network Settings of my VPC I couldn't see my Wireless Network Connection so I really had no way of telling the VPC to use that for networking. So...




...after searching the web for a while I found this discussion on my issue and the fix is "Not even that complicated". So I thought I would share it with you...

...simple right-click on your "Wireless Network Connection" under "Control Panel" > "Network Connections" and select "Properties" (see snapshot on the right). Just make sure the "Virtual Machine Network Services" is selected. If it isn't, select it and try changing your VPCs Network Settings again. My guess is, now your Wireless Network Adapter will be in the drop-down.

Hope this helps someone else...

Thursday, August 2, 2007

Lok sumarleyfis

Jæja, þá er sumarfríinu lokið. Fjölskyldan lauk því með að keyra hringinn á tæpri viku, púúhh.

Við byrjuðum á því að taka á leigu fellihýsi á miðvikudaginn fyrir viku, fylla það af dóti og þrusa okkur af stað snemma á fimmtudeginum. Fyrsta málið með fellihýsið kom strax á leiðinni þegar við áttuðum okkur á því að það var búið að opna sig um allt að hálfan meter. Við þurftum því að stoppa á þjóðvegi eitt og loka því.

Ætlunin var að ná í giftinguna hjá Unnari og Hannah, vinum okkar frá Jersey, í Akureyrarkirkju kl. 16. Það rétt slapp að koma börnunum til systur Hjördísar og manninum hennar, og skoppuðum við inn í kirkjuna rétt fyrir klukkan fjögur. Þar sátum við svo í hátt í hálftíma og biðum, ásamt brúðgumanum, eftir brúðinni fram til tuttugu mínútur yfir, gott hjá henni. Svo var bara þessi frábæra veisla á eftir, langt fram á nótt.

Á föstudeginum var keyrt í Ásbyrgi og eyddum við þar tveimur nóttum í fellihýsinu og systir Hjördísar, maðurinn hennar og yngsti sonur í þeirra fellihýsi. Skemmtilegur tími og okkur tókst að lenda í önnur vandræðin með fellihýsið. Þegar verið var að pakka saman hélst þakið uppi öðru megin (vitlaust uppsettar öryggisstangir) og það tók nokkuð langan tíma og nokkrar hringingar til Reykjavíkur áður en það var komið rétt saman.

Sunnudagurinn fór svo í að keyra frá Ásbyrgi til Atlavíkur í Hallormsstaðaskógi og komum við þar nokkuð seint að kveldi og börnin orðin nokkuð þreytt. Fellihýsið upp. Börnin í bólið. Við í bólið. Það voru allir þreyttir þetta kvöld en morguninn eftir voru allir í góðum gír og morguninn var frábær. Gott mál enda löng ferð fyrir höndum þennan dag. Allir fóru í sund og svo var keyrt af stað og ekki stoppað fyrr en í Skaftafelli.

Við komum á kvöldmat á mánudeginum og ákváðum að vera þar í tvær nætur. Þegar við mættum í Skaftafell komumst við að því að við vorum búin að vera svo lengi á leiðinni og ísskápurinn að halda köldu með því að eyða rafmagninu af 12V geyminum á fellihýsinu (af hverju ekki að draga rafmagnið frá bílnum á meðan hann er tengdur?). Við vorum semsagt rafmagnslaus, þriðja vesenið með fellihýsið, sem þýddi ekkert ljós og engan hitablástur um nóttina (föttuðum ekki að kaupa 220V tengingu fyrr en daginn eftir). Við undirbjuggum okkur því undir kalda aðfararnótt þriðjudags, en svo reyndist hún ekki vera svo köld.

Skaftafell er með gott tjaldstæði, góða þjónustu og auðvitað með margar skemmtilegar gönguleiðir en við fórum bara í eina stutta upp að Skaftafellsjökli. Þessi þriðjudagur sem við eyddum í Skaftafelli var eini dagurinn í allri ferðinni sem rigndi. Dagurinn var samt mjög góður og endaði með að við fengum tvo vini í kvöldmat, partý og næturgistingu.

Á miðvikudeginum, þegar vikan var liðin, þurftum við að bruna í bæinn og skila fellihýsinu fyrir klukkan 16. Það tókst vel en þegar við vorum að skila því af okkur tókum við eftir að auka-gaskúturinn sem ekki var tengdur hafði fokið af á leiðinni ásamt grindinni sem átti að halda honum. Ekki tókum við eftir því. Hann var svo til tómur og hefur líklega skoppað beint út í móa, ég held að við hefðum orðið var við hann ef hann hefði farið undir fellihýsið. Allaveganna. Fjórða og síðasta vesenið með fellihýsið.

Við áttum semsagt góða ferð þrátt fyrir vesen með fellihýsið en lærðum líka mikið, um fellihýsi, á þessu. En nú er komið að því að snúa sér aftur að alvarlegri málefnum. Við stefnum nú samt að því að stunda hestaferðir fyrir vestan næstu vikur og enda hestaárið með því að taka þátt í leitum í lok september. Ég mun líklega blogga eitthvað um það á íslensku. En almennt séð þá er líklega samt komið að því að bloggið frá mér verði aftur eitthvað tengt tölvumálum og þá á ensku.

Sunday, July 8, 2007

Sumarfrí í Danmörku

Ég er ekki búinn að skrifa neitt í nokkrar vikur nú og er ástæðan fyrir því sú að við Hjördís fórum með fjölskylduna til Danmerkur í miðjum júní og vorum á norður Jótlandi í um tvær vikur. Á sama tíma voru bæði mamma og pabbi, og bróðir minn með fjölskylduna sína, á sama stað. Öll vorum við þar í sumarleyfi og til að hitta dönsku fjölskylduna okkar og heimsækja heimabæ mömmu, Hals. Þetta var frábær ferð og náðum við að heimsækja Danmörk í þokkalega góðu veðri rétt áður en rigningarnar hófust, sem náðu hámarki á sama tíma og tónlistarhátíðin í Roskilde stóð yfir og allir hafa auðvitað fylgst með í fréttum.

Við komum heim þann 29. júní og í framhaldinu tók við vika af vinnu en elsta dóttirin var heima með hinar tvær dúllurnar. Vinnan var blanda af bæði að slökkva tæknilega elda og þessi venjulegu mánaðarlegu störf í rekstri hvers fyrirtækis. En að þeirri viku lokinni var ég kominn í frí og ætla mér að reyna að halda því til streitu út mánuðinn.

Saturday, July 7, 2007

Introduction to new links

I have added a few new links that may need introduction.

First there is Joel on Software, the blog by Joel Spolsky, CEO of Fog Creek Software, expert on software development and other stuff too. I read absolutely everything he writes and more often than not I like it. If you are not reading Joel you should.

Then there are a few Microsoft gurus:

First there is S. "Soma" Somasegar, head of Microsoft's Developer Division who has been at Microsoft since the eighties and is now the most important blogger on MSDN. An interesting read is an interview with Somasegar in RedmondDeveloper since November last year.

Then there is Scott Guthrie, or ScottGu, who runs the teams at Microsoft that build IIS, ASP.NET, Atlas, CLR, Compact Framework, Windows Forms, Commerce Server, Visual Web Developer and the Visual Studio Tools for WPF.

And Joe Stegman, lead PM (Program Manager) on Windows Forms team (now known as Silverlight) and finally Mike Harsh, Microsoft WPF/E PM.

As I quite frequently read articles in the RedmondDeveloper and on Channel 9 I decided to add those to the list as well.

Surface and StarTrek

In the end of May this year Microsoft introduced a new way of computing, namely surface computing. Their new product, Microsoft Surface, supports this way of computing but is essentially just a table with a 30 inch computer display mounted into it. You turn it on and this monitor is your computer.

When using it you don't use a mouse and keyboard, you mainly use it like any other touch-screen but with a little twist. It can recognize multiple contacts at once, so many people can be using it at the same time or you can use both hands, for example resize a picture in two directions at once.

Also, it actually recognizes objects that you place on the table, for example if you place your (wireless) digital camera on the surface the computer will interact with it seamlessly, fetch all your pictures from it and display them on the screen for you to interact with them. It can also recognize things like mobile devices, phones, cup of coffee, credit cards and more.

This is pretty cool but currently Microsoft is only making a handful and only for hotels and such. So for the average Joe, this is nothing more than a fancy demo, but still a nice introduction to a cool future of computing.

When I was looking at the introductions on the Microsoft Surface web site and then the Microsoft Surface Parody joke on YouTube I came to think of StarTrek because we have seen them using surface computing for many seasons, maybe this is where the idea came from.

This is not the first time I get the feeling that by making movies and television shows, like StarTrek, the entertainment business and Hollywood is actually forming the future, telling us what our future should look and feel like. So, what is coming next? Ask Hollywood.


For more techy StarTrek stuff just key "StarTrek" into Google and you can continue to read for decades, quite a lot of stuff about this actually. The best way to get to know what is coming is see the episodes :-)

Wednesday, July 4, 2007

Silverlight and popfly

I have been reading about new development things at Microsoft. Things have surely be happening, especially with the Silverlight project.

Silverlight is the new name for the Windows Presentation Foundation (WPF), which is part of the .NET Framework 3.0. Not only can you develop applications, based on Silverlight, that run on the Windows client but also deploy them using a browser plug-in. This allows you to develop media experiences and interactive applications for the browser (like Flash apps!?)

For more information take a look at the official Microsoft Silverlight site. Silverlight is still in Beta but you can use it and even develop for it using the Visual Studio "Orcas" version. This is cool stuff :-)








Also, there is a the very cool Silverlight implementation called Popfly where users can share their Silverlight remixes. The Popfly Explorer is currently in alpha version shows great potential as a new way of developing and sharing Silverlight experiences. You can also read Somasegar's blog on this issue.

Monday, June 11, 2007

Fórum með Hestana vestur


Við fórum með hestana vestur um helgina. Ég hef víst ekki nefnt hestana okkar áður en þeir eru Póló frá Miðjanesi og Nóra frá Njarðvík. Það verður að bíða betri tíma en einhvern tímann verð ég að setja niður á blað eitthvað um þessa frábæru hesta okkar.

Saturday, June 2, 2007

Extension Methods

C# 3.0 introduces a new feature called extension methods, which allow us to extend the functionality of an existing type without extending it's class. At times, extending a type's class can be difficult or even impossible, especially if a class is abstract, virtual or even sealed. Even in these cases extension methods will allow you to add a method to the type.
public static string Add(this string me, string stringToAdd)
{
return me+stringToAdd;
}
then a call...
Console.WriterLine("This is it".Add(", isn't it?"));
results in...
This is it, isn't it?
Caution required?

Because extension methods can be declared anywhere in the project, I can imagine maintaining another programmer's code, seeing a method that I find curious and wanting to know more about it. Now if the method is not declared in the type's class, then where is it? Who knows, could be anywhere in the project or even in any of the referenced assemblies. Could be difficult. But still a nice new feature.

Want more information?

Microsoft C# Future Versions

Implicitly typed local variables

C# 3.0 introduces a new construct called var that results in the compiler inferring the type of the variable from it's initializer, which is therefore obviously required.

Sample usage:
int a=3;
var b=7; // int is inferred from the '7' literal

string c="Stuff";
var d="Something"; // string is inferred from literal
C# is still strongly typed

Don't confuse implicit variable declarations with variables of scripting languages where a variable can hold different types of values throughout the execution of the program. A C# variable declared with the var construct is still a strongly typed variable that can only hold the same type of values as the initializer.

Complex and anonymous types

The var construct obviously simplifies instantiation of complex types (especially in the case of anonymous classes) and is therefore extremely important when it comes to LINQ (a feature to be discussed later).
// co1 and co2 of same type but co2 more readable?
Map<customer,arraylist<orders>> co1 = new
Map<customer,arraylist<orders>>();
var co2 = Map<customer,arraylist<orders>>();

// anonymous class - discussed in later posting
var co3 = new {
Id="0032",
Name="Alfred",
Home="Reykjavik"
};
However, I wonder if in some cases the var construct will make the program more difficult to read, in contrast to the sample above where the program is obviously easier to read as a result of using var. Can you think of such a situation?

Want more information?

Microsoft C# Future Versions

.NET Framework 3.0

As you may have noticed .NET Framework 3.0 has been installed on your machine!

What is this .NET Framework 3.0?

First of all, version 3.0 is not an upgrade from version 2.0 like version 2.0 was an upgrade from version 1.1, which was an upgrade from version 1.0. Actually, when version 3.0 is installed the installer starts by checking if .NET Framework 2.0 is installed, if not then version 2.0 gets downloaded and installed and then version 3.0 is installed. The reason is that the .NET Framework 3.0 is not really a framework!? :-)

What is it then?

In reality, .NET Framework 3.0 is a new set of APIs to be distributed with future versions of the .NET Framework. This collection used to be called WinFX but last year it was renamed to .NET Framework 3.0. That renaming didn't happen quietly as can be read at the WinFX MSDN blog site.

The new APIs coming with .NET Framework 3.0 are these:

  1. Windows Communcation Foundation (WCF)
  2. Windows Presentation Foundation (WPF)
  3. Windows Workflow Foundation (WF or WinWF)
  4. Windows CardSpace, a.k.a. InfoCard

These APIs are nice and it's good to have them installed but there are currently no applications that use them and I can't develop anything using them. Why install them?

How to develop for .NET Framework 3.0?

So, being a developer and all, I'm waiting for .NET Framework 3.5 (currently out in Beta 1 and expected to be released in the end of 2007). Why am I waiting for .NET Framework 3.5? It will contain the necessary tools to support the above new APIs. These tools are included in the up and coming Visual Studio Code Name "Orcas".

What about the new C# 3.0, is that in "Orcas"?

This new version of Visual Studio also comes with C# 3.0, or C# Orcas, which also comes with a set of new features that are just as interesting as the .NET Framework 3.0 APIs mentioned above. From the C# 3.0 Specification, these new language extensions include:

  1. Implicitly typed local variables, which permit the type of local variables to be inferred from the expressions used to initialize them.
  2. Extension methods, which make it possible to extend existing types and constructed types with additional methods.
  3. Lambda expressions, an evolution of anonymous methods that provides improved type inference and conversions to both delegate types and expression trees.
  4. Object initializers, which ease construction and initialization of objects.
  5. Anonymous types, which are tuple types automatically inferred and created from object initializers.
  6. Implicitly typed arrays, a form of array creation and initialization that infers the element type of the array from an array initializer.
  7. Query expressions, which provide a language integrated syntax for queries that is similar to relational and hierarchical query languages such as SQL and XQuery.
  8. Expression trees, which permit lambda expressions to be represented as data (expression trees) instead of as code (delegates).

Confused about all this?

Anyway, if you are still confused about .NET Framework 3.0 and all the new stuff coming from Microsoft right afer Vista why not read about Julia Lerman trying to explain it all!

Saturday, May 26, 2007

Líka á íslensku

Ég hef ákveðið að skrifa bæði á íslensku og ensku eftir því hvort tungumálið mér þykir betur henta hverju viðfangsefni. Enska hentar mér augljóslega betur þegar kemur að því að blogga um tækni en íslenska betur þegar kemur að því að blogga um samfélagið sem ég bý í, Reykjavík á Íslandi 2007. Ég vona að þið takið þessu vel og að ég fari nú að blogga meira fyrir vikið.

Publishing-large-post-problem fixed!?

Something has happended. Now the long-post problem mentioned earlier seems to be gone. I can now use the Blogger again. Thank you, whoever at Google that fixed this.

Sunday, April 1, 2007

Publishing-large-post-problem

I'm having the same problem with the Blogger as many others - it is not easy to blog large posts. In short, often when posting blogs using the new Blogger (and others have reported similar problems with the old one as well). I get a page saying that the connection has been closed. This is very annoying when I have just written a large post and all is gone!

When searching the 'net for a solution I ran into several suggestions, even one that suggested I should decrease the MTU on my router. Isn't that just going a bit too far? Some will suggest anything but Google having a problem with their Blogger.

I continued my search and I finally found the usenet-post Connection reset when publishing 'large' post...? by skilef that describes the problem very well. It also has a simple work-around in a skilef reply to him-/herself.

There are others posts that describe this as well, like the thread Publishing/viewing cookie problem? by Case and ScooterTex. Admit it, there is a problem with Blogger!

I use the work-around but it is really not good.

OWA on Vista

I used to have access to Outlook Web Access (OWA) before we realized it was too open and making our network highly vulnerable. Now we have set this up again, with the appropriate certificates, and all is working fine, or is it!? Well for most users it is working fine, but for my access of OWA, using my Internet Explorer 7.0 (IE7) on my new Vista machine at home, it is not working fine. I can access it but I can't do the simplest things, imagine, I can't compose e-mails. What you say? Yeah, believe it. Why is it that since I got my new Vista machine it seems like all my Microsoft products are failing me? Like the new Messenger and now OWA. What is this? What kind of an "improved" version of Windows is this? This is ridiculous!

Anyways, let's fix it. I found someone else that had this problem, see "Cannot Compose or Reply to Messages and Other Errors in Outlook Web Access in Windows Vista" by My Digital Life. Well, it wasn't the suggestion of installing an update2for the Exchange server that first intrigued me but the first comment by angler, who suggested that there were a simple install on my IE7 that would solve the problem. To make a long story short, the suggested updating of S/MIME didn't help at all.

So, I ended up downloading and (trying to) install the Exchange server update from KB 911829. However, that didn't work either, when trying, the installer replies that my Exchange was too old, must be SP2. I then use Windows update and it wants to update my Windows Server 2003 for Small Business Server to SP2, intereseting!? After that, upgrading Exchange to SP2 solves the problem. How long do you think that took?

Can you imagine all that, just to access OWA using Vista!

That Vista thing is one h... of an upgrade.

Sunday, February 18, 2007

Microsoft OneNote

I was introduced to OneNote a few months ago, if not a year ago. The guy who showed it to me had one of those Tablet PC machines and I thought it was cool but I didn't think I would be using it on my PC as I didn't have the cool drawing and writing capacity of the Tablet PC. I thought if I was to be using it with only keyboard typing that would be making OneNote into just a different Microsoft Word. I was wrong...

Now, months later, I have installed it on my home machine to give it a chance. I have been trying out OneNote now for a few days and I think it is very helpful. Especially as I do a lot of researching on the web on my home machine during evenings and OneNote will surely help me organize my thoughts and results. I'm even doing brainstorming on designs in there now and I can imagine a lot of other stuff I will be using OneNote for...

Maybe you should give it a try too!?