August 2008 - Posts

I’ve been waiting for this update for VS 2008 SDK for VS 2008 SP1.  The link I got fro ma msdn blog post was wrong, so here’s the link to the download page.

http://www.microsoft.com/downloads/details.aspx?FamilyID=59ec6ec3-4273-48a3-ba25-dc925a45584d&DisplayLang=en

Enjoy.

with no comments
Filed under: , ,

Davy Brion posted about how events can keep object references alive.  In C# to rid yourself of this issue you have to manually unwire any event handler you wired.  In VB, it is a lot easier, all you have to do is use WithEvents and set the variable to nothing. This code is the VB version of Davy’s sample:

 

Public Class Publisher

   Public Event MyEvent As EventHandler

 

   Public Sub FireEvent()

      RaiseEvent MyEvent(Me, EventArgs.Empty)

   End Sub

 

End Class

 

 

Public Class GoodSubscriber

   Implements IDisposable

 

   Private WithEvents _publisher As Publisher

 

 

   Public Sub New(ByVal publisher As Publisher)

      _publisher = publisher

   End Sub

 

 

 

   Private Sub _publisher_MyEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles _publisher.MyEvent

      Console.WriteLine("the publisher notified the good subscriber of an event")

   End Sub

 

 

 

   Public Sub Dispose() Implements IDisposable.Dispose

      _publisher = Nothing

   End Sub

 

End Class

As long as the variable is declared as WithEvents any event wired up via declarative event handling will be unwired when the variable is set to Nothing.

This is yet another subtle but important example of how declarative coding styles can lead to more robust code.  The above example is minimal, but when you get many events and many objects raising events, the cleanness of the VB way of handling it becomes even more important.  Or in other words in C# you have to make sure you unwire each and every event, in VB you use declarative events syntax and VB handles it for you ;)

with 1 comment(s)
Filed under: , , , ,

 

Via Nancy’s blog, I saw the link about Apple’s claim for accessibility features on the iPhone.  Have a look at this picture of their claimed “Giant font for Mail messages


 

Maybe they could have made the picture a bit bigger, but if you have good eye sight you might notice that it appears you have to scroll to read each line then scroll back.  That’s just plain shameful design .

with no comments
Filed under: ,

In case you haven’t seen it, Microsoft is releasing tools for WPF out of cycle as part of the WPF toolkit. Current release includes a CTP of a Data Grid, and a Date Picker and Calendar is planned.

with no comments
Filed under: , , , ,

As I looked out the window this afternoon I spied a young joey out of the pouch.  They’re like puppies, full of energy.  Of course by the time I grabbed the camera and went outside he was back in the pouch (no-where to be seen). Definitely does seem early this year compared to last year.

Hopefully I will get some photos of him/her soon.  Oh, and when I walked towards the roos today, the buck got mighty defensive, standing up tall on his tail.  I was so focused on taking a picture of the joey I didn’t even think to take of picture of that.  I’m kind of hoping he doesn’t do that next time ;)

with no comments
Filed under:

Check out the msdn subscriber homepage.  S

 

P1 for Visual Studio 2008 English is about 830 MB… downloading at present

 

:)

 

Then I can install SQL 2008 :)

with no comments
Filed under: , , , ,

Lucian has kicked off the conversation on generic variance in VB , so I thought I’d write a few posts outlining my perspectives on the subject… the first of which is this one, and what better place to start than to question whether or not it is really needed……

Generics came to .NET after the base framework and languages were implemented.  It was very much a bolt-on approach.  As such there was and still is an impedance mismatch between conventional concepts of polymorphism and generics. As I posted previously, I had raised this is issue with Anders and other language experts back at the 2003 PDC (at which time Anders suggested using a language other than VB or C# <g>). Fast forward to today, and this issue is now being looked at, but now I find myself questioning if it is really needed, or is the fault the mismatch of the original framework. 

Let’s take Lucian’s example :

Dim args As New List(Of ConstantExpression)
args.Add(Expression.Constant(2))
args.Add(Expression.Constant(3))
Dim y = Expression.Call(instance, method, args)

 

This code fails because the Call method is defined as :

 

   Public Shared Function [Call](ByVal instance As Expression, _
                                 ByVal method As MethodInfo, _
                                 ByVal arguments As IEnumerable(Of Expression)) _
                                 As MethodCallExpression

 

But if it was defined as follows then the code would work:

 

   Public Shared Function [Call](Of T As Expression) _
                                (ByVal instance As Expression, _
                                 ByVal method As MethodInfo, _
                                 ByVal arguments As IEnumerable(Of T)) _
                                 As MethodCallExpression

 

 

So where exactly is the problem ?  The simple rule is if you want polymorphism (read as “generic variance”) in your code, then you need to expose the types as generic parameters not as concrete types.

That is, the above is solved by better API design and some simple refactoring.  This in fact solves 90% or more of all the cases I have seen.  The one place where you can’t do this is when the type is late bound and defined only as Object (more on this in a future post no doubt ;))

with 5 comment(s)
Filed under: , , , , ,

This post has been sitting in my drafts for a while, so I thought I should post it, mainly because I want to talk about this and generic variance and arrays in more detail in the days ahead.  The reason this post was put on hiatus was I was waiting for my article on arrays to appear in Visual Studio Magazine, as that deals with many of the details as to why this works ;)

 

Have you ever wanted to cast a List(Of Customer) to a List(Of BusinessBase), where Customer Inherits BusinessBase, only to find that you can't... well you can ;)

 

This extension will return an IList of BusinessBase for an input of a List(Of Customer).  Be aware it is the underlying array, so you will need to get the actual count from the original input.

 
   <Runtime.CompilerServices.Extension()> _
   Function ToIList(Of T, TBase)(ByVal list As List(Of T)) As IList(Of TBase)
      Dim fi = GetType(List(Of T)).GetField("_items", Reflection.BindingFlags.Instance Or _
                                                      Reflection.BindingFlags.GetField Or _
                                                      Reflection.BindingFlags.NonPublic)
      Return CType(fi.GetValue(list), IList(Of TBase))
   End Function

 

 

And a quick test:

 
 
Module Module1
 
   Sub Main()
      Dim myApples As New List(Of Apple)
      myApples.Add(New Apple With {.Name = "Golden Delicious"})
      myApples.Add(New Apple With {.Name = "Red Delicious"})
      myApples.Add(New Apple With {.Name = "Granny Smith"})
 
 
      Dim fruits As IList(Of Fruit) = myApples.ToIList(Of Fruit)()
 
      For i = 0 To myApples.Count - 1
         fruits(i).Name = "Fruit : " & fruits(i).Name
      Next
 
      For Each a In myApples
         Console.WriteLine(a.Name)
      Next
 
      Console.WriteLine("finished")
 
      Console.ReadLine()
 
   End Sub
 
 
 
   <Runtime.CompilerServices.Extension()> _
   Function ToIList(Of T, TBase)(ByVal list As List(Of T)) As IList(Of TBase)
      Dim fi = GetType(List(Of T)).GetField("_items", _
                                         Reflection.BindingFlags.Instance Or _
                                         Reflection.BindingFlags.GetField Or _
                                         Reflection.BindingFlags.NonPublic)
      Return CType(fi.GetValue(list), IList(Of TBase))
   End Function
 
End Module
 
 
 
 
Class Fruit
 
 
   Private _Name As String
 
   Public Property Name() As String
      Get
         Return _Name
      End Get
      Set(ByVal value As String)
         _Name = value
      End Set
   End Property
 
 
End Class
 
Class Apple : Inherits Fruit
 
End Class
with 5 comment(s)
Filed under: , , , , ,

If you have Visual Studio 2008 installed, you can’t install all of the SQL 2008 bits because of shared components for Visual Studio 2008.  SQL 2008 wants to use Visual Studio 2008 SP1 components and that might/will break your Visual Studio 2008 setup.  Good news is SP1 for Visual Studio is said to be available on MSND subscriber downloads after August 11th.

This COM based dll hell though surely has wider implications.  What of those who developed for Visual Studio Extensibility and have their own Visual Studio shell  ?  Oh the joys of shared COM components. ;)  Memories ……

with no comments
Filed under: , , ,

I downloaded the SQL 2008 Upgrade Advisor. When I tried to install it I got this :

 image

 

It says a “Windows service pack” , yet Windows Update tells me my system is up to date.  Well it might help if I read the download’s system requirements ;)  What I needed to do was install windows Installer 4.5

Strange it isn’t listed on Windows Update/

Apologies to all as I have been slack in filtering out the spam, and replying to comments.  Hopefully I’ve caught up now :)

with no comments
Filed under: ,

 

Although it’s the midst of winter, some of the fruit trees are already in blossom (wild pear above).  I still have a LOT of pruning I should try to get around to.  I’ve also decided that I will try to plant one or two new fruit trees every year, to help build diversity, plus it’s a lot easier than do mass plantings all at once.  This year I bought two peach trees, an Elberta and a Red Noonan. While I was at it I grabbed a Valencia and a Navel orange tree.  It’s pretty marginal here for oranges, but I couldn’t resist ;)

 

The veggie patch is pretty quiet. Celery, silverbeet, carrots, beetroot for the harvest at present, broad beans still promising to have some pods, but nothing yet.  I planted some garlic which is growing well, and will plant potatoes soon.

This is one of the flowering climbers I planted this year, with it’s first flowers.  Hopefully, eventually it will cover the wire fence :)

 

 

Elsewhere in the garden, the proteas are coming into bloom:

 

This one is one of the first I planted:

 

This is the first flower I have seen on this little plant I planted a couple of years ago. It struggled through the drought, but is doing well now.  Only one flower on it this year:

 

The Drynandra is also in bloom, and making a great comeback. The giant yellow tail black cockatoos almost stripped the plants completely last year.  Seems they did a great job mulching them, and no doubts they’ll visit again this year ;)

 

Another paler pink protea is also in flower:

and has lots more about to open:

 

The wattles are getting even more intense (see last month’s photos) .  There’s seas of yellow across the countryside. Here, the tree lucerne is also in bloom, adding a snowy effect :

 

As I took these photos today I also caught a few of the local birds.  You’ll need to look at the larger versions fro the little birds. This is a Spotted Pardalote. Hard to get a good photo of:

 

And this guy is a Red-Browed finch.  Click on the photo to see the large version:

 

And of course the Crimson Rosellas had to get in the photo :

And the magpies are pretty active at present.  I think they may be breeding:

There were plenty of other birds as well including Kookaburra, what is probably a Satin Bower bird, some other finches and robins I hope to get some photos of in the coming months :)

 

The weather has been mixed. Some nice days, a few heavy frosts and some decent rains.  July was good for rain, but we are still way down for the year.  I glanced at some historical figures, and the closest pattern I noticed was 1937, which ended up having heavy rains around the end of the year, instead of the usual mid-year rains (more tropical than temperate).  More rain would be good.

Oh, on a site I check for weather reports I noticed it said only 60 or so more days till day light savings begins again. :)

with 2 comment(s)
Filed under:

It seems apparent that with computers as we currently know them, processors are now set to scale out not up.. that is, clock speeds aren’t rapidly growing, and certainly not doubling every year or two, instead the number of processors on a chip is.  As a case in evidence, 2 or 3 years ago, my PC’s were all single CPU, then a bit over a year ago I bought my new desktop PC and it was a dual core.  And as of a few days ago I swapped that dual core out for a quad core.  For me, the number of cores/CPU’s is clearly doubling every year or two, but clock speed itself isn’t that much faster.

So what that means for computing is the emphasis is on parallel or concurrent computing. As such, we need to look at the fundamentals and see if they are designed for the task.  Iterators don’t look like they are.

If you consider an iterator primary task of getting the next element, then look at how it does it, you should observe a major design flaw… the operation is not atomic. An iterator’s implementation is IEnumerator or IEnumerator(Of T), and IEnumerator require you to first call MoveNext then read the Current property.  If you allow multiple threads to use the same IEnumerator, then you could get a call sequence such as MoveNext, MoveNext, Current, Current, which would skip one item and repeat the next one.  So IEnumerator is not well designed for threading.  This is a known design limitation, but rather than address that, languages like C# have implemented their iterators to be a different iterator per thread.  That is they not only recognise the limitation but they also enforce it.

Going forward, perhaps we need a new IEnumerator class.  In the good bad old days that would be called IEnumerator2(Of T).  IEnumerator2 would make iterating a single method call that would return a Tuple(Of T, Boolean).  It could extend IEnumerator, but it would be difficult to enforce thread safety to the IEnumerator interface. The problem that language like C# would then face is do they risk breaking existing code by returning the same enumerator to different threads ?  Well no they would have to provide an IEnumerable2.GetEnumerator as well, so it would be possible to have the same class used for both single instance per thread and shared class across threads.  As such, then the code that calls the iteration, the For Each loop, would then have to indicate whether it wants to do so using parallel or single threaded.. this would probably surface in the languages such as the For Parallel instruction on a loop.

So maybe iterators aren’t fundamentally flawed, they just currently have a lot of limitations which can and hopefully will be addressed  as we venture more into the world of multi core :)

with 4 comment(s)
Filed under: , , , ,

Today I bought an Intel Quad Core Q6600 to replace my old Dual Core.  I was amazed at how easy it is to swap processors.  The box I was upgrading was an old Dell Dimension E520 .. when I say “old” I mean more than 12 months and hence out of standard warranty <g>  

First step is to identify if you can upgrade. I searched the web for my model along with Q6600 and found success stories on Dell’s forums.  I then checked the Intel site where you can select multiple processors and compare the chipsets and all looked good. So I bought the Q6600, which are pretty cheap at the moment :)

The Dimension E520 has a better heat sink and fan combination than what came with the Intel Q6600, so I kept my old heat sink, giving the base a wipe over and a clean with isopropyl alcohol.  Removing it for cleaning was a breeze, only two screws holding it onto the motherboard then it hinges off the processor. I also gave the case and heat sink a blast of compressed air to remove the dust that was in there. 

Removing and swapping the processor is really easy… you just push the wire clip out and up, and the retaining brackets lifts off the processor chip. The chip just lifts out, no prying or tools needed. It’s so easy I feel ashamed I haven’t done it before ;)  (but then again I generally replace systems, not parts).  A quick squirt of heatsink gunk, slap the heatsink back on, and everything was done.  A quick check with SIW.exe showed the temperatures are good too :)

And now the fun begins !!  With 4 cores I can start playing more seriously with parallel (concurrent) programming.  2 cores wasn’t enough really, and although 4 is just the start, it should be enough to run basic tests :)

with no comments
Filed under: , ,