Tuesday, April 01, 2008
This is the first in what I hope will become a series on the new language features in C# 3.0 used in .NET 3.5 / Visual Studio 2008.

One thing I am not intending to cover is LINQ.  Just because the blogosphere has been buzzing with LINQ articles since the early days of "Orcas".  And with good reason I hasten to add!

Where I am starting is with the var keyword.

VB6 veterans will remember the Variant type.  A Variant could contain anything, even Object.  While this was sort of useful, my memory of it is as a synonym for:  I can't be bothered, lets just stick it in a Variant and deal with it later.

There was also a performance impact of using the special Variant type, they were large in memory and have an overhead of extra runtime checking that added up; like when assigned inside a loop for example.  They were also a special case in their un-assigned form, taking on the value Empty (test with IsEmpty()) vs Nothing (test with Is Nothing). 

So when I saw var added to C# I raised my eyebrows in the way a Fed might, when the beagle sits quietly next to your suitcase at the airport.

Most of the time you see it in the samples, it is used when returning an Anonymous Type from a LINQ query.  And this is the clue!  var is not itself a type, but instead it is a signal to the compiler to infer the type of an operation, and substitute in the required type.  It does not even have to be an Anonymous Type.  Consider the following simple example:

var result = 10 / 2.0;
Console.WriteLine(result.ToString());

By the time this code is compiled, var is replaced with double.  In fact, the Intellisense on result will be correct for it being a double.

To confirm this, looking at those lines of the assembly in Lutz Roder's Reflector show the following after disassembly:

double result = 5.0;
Console.WriteLine(result.ToString());


OK, so var can be used independant of Anonymous Types, but why would you want to be less explicit in typing your variables?  Consider the following fictitious example:

DatabaseRequestService req = DatabaseRequestService.CreateFrom(value);

And compare it with the equivalent line using var:

var req = DatabaseRequestService.CreateFrom(value);

Here, var leads itself to much more readable syntax with the same typing, Intellisense, and everything else!

Listening To:  Róisín Murphy

Tuesday, April 01, 2008 9:25:00 PM (AUS Eastern Standard Time, UTC+10:00)  #    Disclaimer  |  Comments [0]  | 
 Tuesday, March 25, 2008
I just wanted to add a note before my next posting to acknowledge that I know this blog has been slow of late.

This isn't because I am bored of it or anything, but it does relate to my own personal rules for blogging, and this might be a reasonable time to mention them :-)

Rule Zero:  Keep it interesting.  Believe it or not, I try and keep this blog interesting.

Rule One: Don’t blog about blogging.  The blogosphere can be one huge echo chamber at times.  If you must inform the world that someone else made a great blog post, consider Twitter.

NB: When I do post linkage I put it in the MLP category, which owes its name to the MLP (a.k.a Mindless Link Propagation) section on the internet culture stalwart Kuro5hin (i.e.  “corrosion”)

Rule Two:  No proprietary information.  This is what I’m talking about today.

Recently, I started a company, and have been working on some IP in the multitenant and SharePoint space.  These are really interesting to me, but there has been a bitlot of business strategy & architecture stuff, and that has to stay internal.

Hope this makes sense, and I really welcome comments on this topic if anyone feels like they have something to share.

Listening To: Ani DiFranco, Canon
Tuesday, March 25, 2008 9:57:46 PM (AUS Eastern Standard Time, UTC+10:00)  #    Disclaimer  |  Comments [0]  | 
 Wednesday, March 05, 2008

One of the things I miss from my Unix/Linux days is Grep.  Previously I have tried things like Cygwin, but was never quite satisfied.  I am quite excited about PowerShell and am always trying to get more PS> in my life :-)

I'm using Powershell almost daily to replace Grep.

To start, this is all based on the Get-ChildItem cmdlet.  The best way to think about Get-ChildItem is it does what the Dir command did in DOS.  One important difference is it is not just for files, and can be used to return all items in a location - and it is up to each provider to decide what a location & item means to it!

For the PowerShell n00bie, you can just use cd around the filesystem and when you type dir, you are really running Get-ChildItem.  In fact when you type cd you are really running Set-Location.  For a full list of aliases for common commands, run Get-Alias.

To search in file names:

The following command searches for .aspx & .ascx files in the current directory that have the word "metro" in the filename.

PS > Get-ChildItem -Include *metro*.as?x

To search inside text files:

The following command searches inside .aspx & .ascx files in every subdirectory that have the word "metro" in the filename, and has the word "train" inside the file.

PS > Get-ChildItem -Recurse -Include *metro*.as?x | Select-String -Pattern train

You are also able to add the -CaseSensitive parameter to the end of the Select-String command, by default it will search case insensitive.

NB:  I have used the full names of the parameters of the commands.  This may look clunky, but:

  1. I wanted the examples to be clear, because this is a blog :-)
  2. The Tab-Completion feature works for parameter names so they are not hard to type
  3. You can use the smallest number of letters that identify a parameter.  For example, if a cmdlet accepts a -Recurse and a -Record param, you would only need to use -Recu and -Reco respectively.

Update: A lot of parameters accept an array as input.  The syntax for listing these is as a comma seperated list.

An example where this applies to our example is searching through multiple file types, i.e. .aspx and .cs.

The following example searches both .aspx/.ascx files and .cs files with the word "metro" in the filename.

PS > Get-ChildItem -Recurse -Include *metro*.as?x,*metro*.cs

Listening To:  Wicket Beat Sound System, Inner Styles

Wednesday, March 05, 2008 10:25:19 PM (AUS Eastern Standard Time, UTC+10:00)  #    Disclaimer  |  Comments [0]  | 
 Friday, February 15, 2008

Out of the blue I got this message from iTunes today:

iTunes has detected an iPod in recovery mode.  You must restore this iPod before it can be used with iTunes.

Fair enough, foo happens, life goes on.  Or so I thought.  When you restore your iPod and reboot it, the same message comes back!  Over and over.

The solution, it turns out according to the collective wisdom of the blogs, is to change the drive letter of your iPod in Computer Manager.

Mine had, for reasons not yet understood, changed from J: to H: - which was in use as a network-mapped home drive.  This conflict was being reported in iTunes as an iPod in Recovery Mode.

It seems like all I do these days is download iTunes updates, and the messages are not getting any better when it goes belly-up.

Apple, this is turning into a one way relationship!

Listening To:  Zephyr Timbre, Absrtakt Fusion

Friday, February 15, 2008 12:57:52 PM (AUS Eastern Standard Time, UTC+10:00)  #    Disclaimer  |  Comments [2]  | 
 Tuesday, February 12, 2008
Previously I had been using the (formally "Katmai") SQL Server 2008 CTPs that were distributed through MSDN as VHD files ready for Virtual PC.  But today with the arrival of the November CTP (CTP 5) DVD I actually got around to the installation.

I had no problem with the hardware requirements and the install went successfully.  I screen caped the interesting bits as I went...

The Launcher.  First up there are some improvements to the install launcher with all the important stuff easy to find.



The Configuration Check screen is as you would expect based on SQL Server 2005.



An interesting thing to note about the Feature Selection screen is as you add and remove features the remaining steps adjust accordingly



I've skipped the Instace Configuration screen because it is just as you would expect, however the Service Accounts page has been improved with some secure defaults and it guides you towards secure choices. 



Again I have skipped the Instance Configuration because it is much as you would expect.  The Database Engine Configuration screen is again good at guiding you towards good choices.  Interestingly TempDB location is included which is nice.  Always good to have TempDB on seperate IO if possible.



Analysis Services Configuration is much the same as Database Engine Configuration, but nice to see SharePoint integrated mode is available on the Reporting Services Configuration step.  Historically this use to be some black magic.  I'm looking forward to testing out this option in Katmai in greater depth later.



The rest of the steps are much as you would expect based on SQL Server 2005 and not too interactive, so I have saved you the bandwidth. 

And there you have it!  Play time again for me :-)

Listening To: Air - Premiers Symptomes

Tuesday, February 12, 2008 9:44:24 PM (AUS Eastern Standard Time, UTC+10:00)  #    Disclaimer  |  Comments [0]  | 
 Thursday, February 07, 2008

Sydney had some very heavy storms today, on the back of what is an unseasonal string of storms.  The drains outside my new home office were at capacity for the first time and with the rain coming down…

It flooded

However by and large things went well.  First thing was to cut mains power to the room as a puddle was forming under my rack.  A laptop was on hand and the LAN infrastructure was on power protection, so all the machines that matter shut down cleanly. 

What did I learn?

  • My SQL Server (Proliant ML530, 2x Xeons, 3Gb, Ultra3 RAID) takes the longest to shut down so should be shut down first.  Tacitly I knew this, but didn’t connect the dots at the time (with the UPS ticking away)
  • Power packs, in fact mains power in general should be off the floor.  I am gonna make a policy about this.  Again it could have been a lot worse but it was a distraction with the clock ticking.  Command hooks are cheap and I will be making some CapEx 3M’s way shortly.
  • The floor is a bad place to stack paperwork.  Nothing important was lost but Rob and Coronel has a date with the hair dryer
  • One of my UPSes goes Red with plenty of juice to spare.  Might need to do more testing.

 

Thursday, February 07, 2008 5:46:14 PM (AUS Eastern Standard Time, UTC+10:00)  #    Disclaimer  |  Comments [0]  | 
 Wednesday, January 23, 2008

Lots of people are familiar with obtaining and installing SSL Certificates for hosting secure web sites, but the area of code signing seems less cohesive. I’ve compiled some notes I have on the process together in this blog post.

Yes, but who are you?

Reputable publishers of code signing certificates require some evidence that you are authorized with respect to the organization you wish to have named on your certificate. In my case, being able to produce the ASIC registration for my company was enough, YMMV.

This is subtle, but important.

  1. My company rego papers are credentials a Root CA (e.g Comodo, Verisign, Thawte, USERTrust etc) uses to trusts me.
  2. The user (implicitly) trust the Root CA by using an OS with their Certificate installed.
  3. Ergo, the user (indirectly) trusts me.

Macro projects in Microsoft Excel/Word/Visio/Access/etc

Once you have obtained your certificate, you are able to sign Macro projects in Office document templates by choosing Tools -> Digital Signature.

Your newly purchased certificate will appear in the list and by saving the project your template is signed. The difference is now the user is asked to trust you (as verified by the CA) and your code, rather than being asked to enable all macros.

Software distributed MSI packages

Signing MSI packages and CAB files is more visible than ever before in Windows Vista. This I think is a good thing, however I do worry that because there are a lot of unsigned installers out there that users may get the message that it’s not that important.

Once you have got your certificate from a CA, the process couldn’t be easier. There are a couple of ways to get signtool.exe, I usually have the Windows SDK on my machines which ships with it.  The command to sign ClassLibrary1.dll for example is: (assuming signing from a pfx, not the local cert store)

C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\signtool.exe sign /f My_Code_Signing_Cert.pfx /p L0ng5ecr3tp@ssw0rd /d name /du http://www.MyCompany.com /t http://timestamp.verisign.com/scripts/timestamp.dll ClassLibrary1.dll

The time stamping is important here, in that certificates expire. An external time stamp ensures that the assembly was signed while the certificate was valid.

.NET Assemblies

Technically, signing an assembly is not unlike signing an MSI. On one hand it is easier because you can do the signing from inside Visual Studio’s project properties

On the hand there is the concept of delay signing, where the actual private key is not available to the developer on a day-to-day basis.  This added security adds a layer of complexity that is frankly beyond the scope of this post. I will come back and dedicate a whole post to it some time :-)

Windows Logo Certification / WinQual

This is the only case I can think of where the vendor of the certificate matters. A certificate from VeriSign is required to prove your identity in the WinQual program, which is required for a Windows Logo certification. VeriSign has special pricing is on offer for members of Windows Quality Online Services site.  The $99 cert from VeriSign is required for WinQual membership, and is all you need if you already have a code signing certificate. The $399 cert is valid for both code signing and WinQual membership.

Wednesday, January 23, 2008 3:26:10 PM (AUS Eastern Standard Time, UTC+10:00)  #    Disclaimer  |  Comments [0]  | 
 Monday, January 14, 2008
So looking forward to another year in Visual Studio, and this year in Visual Studio 2008 no less! 

I thought I'd open 2008's blog posts with a note about what is in my toolkit at the moment for developing in VS2008.  So in no particular order...

What is in?

  • Visual Studio 2008.  I played with it since Beta1, and blogged about it a bit too.  Living in the RTM now and quite liking it.
  • Refactor! Pro and Coderush from Developer Express are still on my list.  There is a new version (3.0.5 at time of writing) out that has some cool new improvements.
  • Aptana Studio.  I heard about this Eclipse-based IDE on the Hanselminutes podcast and had to check it out.  There are some good features in there for CSS and JS.  Worth having around and they cram a lot of IDE into a tiny space!
  • The PowerShell Visual Studio Templates.  Powershell is getting more and more use in my life, and I love the idea of rolling your own cmdlet (pronounced:  "command-let") to manage your own apps.  The page says they are for VS2005 but they are good for VS2008 as well.
  • NMock.  I know there are plenty of mocking frameworks out there each with their own style.  I just happen to like NMock.


What is out?

  • The notable exclusion from my 2008 dev environment is NUnit.  I have been a fan and user of NUnit for some time, but am going with the MSTest-based unit testing framework that is built in to Visual Studio 2008.
  • NAnt is on thin ice in my environment too in favour of MSBuild.  This is largely for pragmatic reasons, there is project information kept in both the VS Solution and in the NAnt file and my preference is to maintain it in one spot only.

And that's it!  I like to keep it light.  For Continuous Integration I am using CruseControl.NET.

I'm still searching for the perfect XPath/XSLT environment.  Visual Studio is OK for the moment, but I have a feeling that the perfect tool may just be Eclipse based :)
Monday, January 14, 2008 10:45:38 PM (AUS Eastern Standard Time, UTC+10:00)  #    Disclaimer  |  Comments [0]  |