Visual Studio 11 ALL CAPS

The following is my response to the VS blog post about the design for all caps in top level menus:

First off, why would you want to add *EMPHASIS* to menus when the design philosophy stated for the new look of VS was it didn’t distract from the content we are creating?

Second, the examples provided of Bing, Azure portal and Zune are complete mismatches.

Bing doesn’t add top level menus in ALL CAPS, quite the opposite: they are all in proper case. What you see in Bing is all caps used for pane titles. This difference is very important. Bing was more like the first beta of VS 11, not the latest bits. Also note the use of all caps is only about four or five items over the entire screen. VS top level menu is **SEVENTEEN** distinct items!!

Zune uses lower case at top level (quickplay, collection, marketplace), and all caps at the individual pane level, again not totalling more than 5 distinct items on any pane.

Azure portal on the web does use ALL CAPS for the top level menu, but it is only six items and uses a LOT of white space around and between them.

From a visual design perspective the examples given show use of white space, and clarity, whereas the VS 11 menu is cramped and way too busy. You cannot relate fourteen items to designs of five items, especially when the five item designs use copious whitespace, whilst VS menu does not.

It’s great we will be able to change this, but sad so much effort is being wasted on a design implementation that really adds no value to VS, contradicts both its own design philosophy and those of windows guidelines.


Rotate your Calculator on Windows Phone

Today I has having some discussions over the right roof pitch for a car port, so I grabbed my phone, rotated it and did some quick trigonometry.  Ten minutes later I tried to do the same and I could only see HEX and BIN, not Sin and Tan et al.  I’d forgotten it all depends on whether or not you turn it left or right.

Rotate the calculator to the left for trigonometry functions.

Rotate the calculator to the right for logical/programmer mode.

I’ll try not to forget next time; was embarrassing when I had to get the laptop out to do an inverse tan calculation, after having using the phone for similar calculations just ten minutes earlier Winking smile

Visual Studio toolbar

The beta of Visual Studio 11 is causing a lot of feedback around the grey shade icons.  The use of colour or not has also brought to the forefront the UI for colour-blind people.  So I thought I’d post a picture of my toolbar, along with some links to see the page as seen by those with colour-blindness…

My toolbar:



Colour-blind filter web site:

This post on the above site:;r=;l=0;j=1;;t=p

windows 8 likes and dislikes

There’s a lot to like in windows 8 preview: it’s easy to see how windows 8 will be a hit on tablet devices; there’s massive synergy with windows phone; the built in windows live experience combined with your settings in the cloud, make it smooth to go from one device to another. But there’s other bits I’m not so fond of …

The Start Menu

Obviously the biggest change people first see is the start menu is now a start page. I like the concept but dislike the fine details on how it is implemented. At present to get to the start menu you have to move your cursor to the lower left of the screen; to see “running” apps you have to move it to the upper left then swipe down; to see all applications you need to right click to see the “toolbar” along the bottom of the screen and select all apps. It’s those details I don’t like. They aren’t intuitive, they aren’t obvious. People have to go through an initial period of disorientation: that’s a negative first taste for existing customers. What I’d much prefer to see is :

  1. Put the windows start button back: not the start menu, just the button. Call it branding if you like, but having the windows button visible always would make the experience a lot more intuitive
  2. Make the start screen a start portal, not just a start menu replacement. That is, get rid of the silly running application list on the left and instead have the start screen have three or four title style buttons along the top (similar to windows pivot app style) that would give you the choice of Favourites, Running and All. Perhaps even a Most Recent as well. The running app list at the side just doesn’t work well for me. They look too much alike, there’s no captions, and the space is limited. It’d make a lot more sense to use the whole screen for running apps, just like it makes sense to use the entire screen for the start “menu”. Currently there is a disconnect of design.
  3. When in desktop mode the start button would be there (see 1 above). Clicking on it would show you the start screen BUT not in full screen mode. Instead have the start screen appear floating: eg a 20 pixel margin all around and a drop shadow. It would make the experience feel more connected rather than the current disconnect.
  4. Allow metro apps to run in “windows”. That is you should be able to preference any metro app to run inside a window on the desktop. This should be a right click preference from the start screen, and likewise from the running app screen to move apps to and from the desktop windows experience. I think this is important for a lot of existing customers who will find themselves still on the desktop and currently experience a disconnect from the metro start screen.
  5. Better panel docking. It seems a step backwards when you can only dock as a thin pane to the side without being able to resize. This totally failed for me when I tried to have my mail on the left pane and my calendar as the main screen (try it: I couldn’t actually read the email). Panels should be able to be sized, apps need to be able to respond to that better than what’s in the preview, and most importantly you should be able to work with desktop applications (4, above would help solve this for metro and desktop apps working side by side)

Overall I kind of like windows 8: I’d like to like it a lot more but it just doesn’t feel as if it is there yet. I think the above list of changes would go a long way to bring in the new experience in a much less discordant way.

VB Quark #7 : Optional Parameters and Dates

Hopefully you already know VB has full support for Optional parameters, both declaring them and calling them, but did you know you can use Dates as Optional parameters ?

   Public Sub AddNewCustomer(customer As Customer
Optional dateAdded As Date = Nothing
If dateAdded = Nothing Then dateAdded = Now


VB has had this support for Optional parameters in place for the last decade or so in .NET and for years before that back in the COM versions of VB.

In the last release of .NET (VS 2010), C# finally got support for Optional parameters, so the above in C# would look like:

     public void AddNewCustomer(Customer customer, 
DateTime dateAdded = default(DateTime
if (dateAdded == default(DateTime)) dateAdded = DateTime.Now;


The Nothing in the VB declaration is the same as default(DateTime) in C#, which equates to the theoretical Gregorian date of 1/1/0001.

But what if you want to specify a default date ? Well because VB supports date literals, in VB you can, but in C# you can’t.  In VB you can write any date literal for the optional parameter value. For example, you might have some legacy database support, and when the date is unknown you want to use the equivalent of an OLE Date’s zero value:

  Public Sub AddNewCustomer(customer As Customer,
Optional dateAdded As Date = #12/30/1899#)


When the VB compiler compiles this, it adds a System.Runtime.CompilerServices.DateTimeConstantAttribute to the parameter information with the default value stored as an Int64 (the number of ticks). C# actually sees the optional value in the above example and will use it. That is both VB and C# can call the code taking advantage of the optional value for the date parameter, but only VB let’s you define that value.

Displaying Dates in VS 2010

From time to time there’s discussion about the way dates are displayed in the Visual Studio IDE for Visual Basic. Typically dates are shown using VB’s date literal syntax of #MM/dd/yyyy# which is the standard US format.  For people outside of the USA this can be confusing or ambiguous at times.  The good news is Visual Studio allows you to easily add your own display formatter.

Simply create a new class library project, add the following attribute to your AssemblyInfo file:

<Assembly: DebuggerDisplay(“Date: {ToString(“”s””)}   kind={Kind}”, Target:=GetType(DateTime))>

And then just copy the assembly to your Visualizers directory, eg:
  My Documents\Visual Studio 2010\Visualizers

I added the Kind property to the display so as you can easily see if the Date is a local date, UTC or unspecified.

I’ve attached a sample project.  Enjoy Smile


VB Quark #6: Date operators

The DateTime structure in .NET includes custom operators for Date comparisons such as less than, greater than, equal and not equal; but did you know it also includes addition and subtraction operators ?  There’s two subtraction operators and one addition operator defined inside DateTime:

  • date = date – timespan
  • timespan = date – date
  • date = date + timespan

Those three cases should all seem relatively obvious, such as adding or subtracting an hour from a date, or calculating how many minutes between two dates etc…

BUT, did you know VB also defines another case where you can add two dates, eg:

     Dim result = Date1 + Date2

Now if you guessed that the type of result is String, then congratulations !! Note: this operator resolution is only valid with Option Strict Off

Obviously adding two dates can’t give a valid date or timespan, so the only real options are to return a string concatenation of the date or throw an error. There are a couple of fringe cases where, depending on your system locale, the resultant string can indeed be parsed back into a date, eg:

      Dim dt1 = #1:00:00 PM#
dt2 = Now.Date
Dim dtResult As Date = dt1 + dt2

But that really is a fringe case, and would depend on the system locale formatting.

I think it’s probably fair to say this case is a quirk of a quark, probably introduced as partial legacy. I honestly can’t see any usefulness of the addition operator between two dates that returns a string. If the intent was some legacy support, it might have made sense to return a date if one of the dates was date zero with time information, but the concatenation of the date strings doesn’t seem to reliably serve any purpose.

The good news is you can only do the string = date + date operation with Option Strict Off. Guess that’s just another reason to turn Option Strict On  Winking smile

VB Quark #5: C is for Char

Can you pick the problem with this code ? :

      Dim currentChar As Char

      For i = 0 To largenumber
         currentChar = getChar(i)
If currentChar = "a" Then
            count += 1
End If


The answer of course is the literal “a” is of type string, not of type Char. Hence currentChar gets implicitly widened to a String to make the expression a string comparison expression. This means a new string is created with the contents of currentChar on each iteration, and the comparison is a string comparison which checks for null strings and empty strings and then does a compare ordinal etc. This is incredibly inefficient.

If “a” was typed as Char, then the comparison is a simple low level IL compare of the underlying values (int16’s).

You can use CChar, as in CChar(“a”), but it’s a lot easier just to add the type literal suffix c, eg “a”c

      Dim currentChar As Char

      For i = 0 To largenumber
         currentChar = getChar(i)
If currentChar = "a"c Then
            count += 1
End If

The change in this code is about 20 fold performance improvement (run as release build outside of Visual Studio). That’s a 20 fold increase just by typing one extra letter !!

This example was based on real sample code where a massive file was being parsed char by char.  There too, attention to the fine detail showed a massive performance improvement over the original code. It’s often the little things that can make a huge difference.


This VB quark was brought to you by the type literal “c”

VB Quark #4: type literals

Do you know why you can’t write this code in VB:

   Dim x = 123456789.0123456789

Answer: The IDE won’t let you Winking smile

If you try to write that code the IDE will truncate the number, giving :

   Dim x = 123456789.01234567

To include all the decimal places you need to be using the Decimal type. To do this you indicate the constant is of type decimal by adding the suffix D on the end, eg:

   Dim x = 123456789.0123456789D

The reason for this is VB treats numeric literals as of type Double by default if they have a decimal place. If there is no decimal place in the literal then the value is consider to be an Integer (Int32), or if it is too large for an Integer, it’s considered to be a Long (Int64).

If you want the literal as a type other than Double, Integer or Long you need to either convert using CType, CShort, CSng etc, or add a type literal suffix. The following is the complete list for numeric type literal suffixes in VB:

Suffix Type
F Single
R Double
D Decimal
S Int16, Short
I Int32, Integer
L Int64, Long
US UInt16, UShort
UI UInt32, UInteger
UL UInt64, ULong

In case you’re wondering, the “F” for Single is short for "Float”, and the “R” for Double is short for “Real Number”.

Here’s another example of where you should use type literal suffixes. Consider this code :

      Dim i1, i2 As Int16
      i1 = &HF0
      i2 = i1
And &HFF

If you have Option Strict On, the last line will cause a compile time error saying that an implicit conversion from Integer to Short is not allowed. So what is happening here, and why doesn’t the middle line cause the same problem ?

Well the line i1 = &HF0 compiles fine because the constant &HF0 can be evaluated at compile time, so there’s no problem there. The last line however cannot be evaluated because the variable i1 is not a constant. Try it for yourself if you like: change the declaration of i1 to a Const, and you’ll see the last line  compiles fine with Strict On.

Because VB can’t evaluate the variable expression at compile time, it uses the default type for numeric constants : Integer (aka Int32). And because a short can be implicitly widened to Int32, the expression on the right hand side becomes an Int32: hence the error.

In Visual Studio the error correction wizard will suggest converting the entire  expression to an Int16, as such :

      i2 = CShort(i1 And &HFF)

But that’s a runtime conversion that isn’t needed if you declare the &HFF constant with the correct type literal suffix S:

      i2 = i1 And &HFFS

As you can see, the code correction wizard in Visual Studio doesn’t always provide the best syntax to use, so it really is up to you to know the correct literals to use and apply them. 

Oh, you may have also noticed there is no type literal suffix for Byte and SByte. I’ll leave that for yet another quark Smile

VB Quark #3: operator differences in VB/C#

Can you spot the problem with this code:

Public Function ToColor(argb As UInteger) As Color
      Return Color
.FromArgb( _
CType((argb & &HFF000000) >> &H18, Byte
), _
CType((argb & &HFF0000) >> &H10, Byte
), _
CType((argb & &HFF00) >> 8, Byte
), _
CType(argb & &HFF, Byte


If you said it should be the bitwise And operator not the string concatenation operator give yourself a pat on the back.  The problem here is three fold:

  1. The code is a failed attempt at translating from C#, and
  2. The project must have Option Strict Off for this code to even compile.
  3. No testing or unit tests to check if the code  works at runtime.

Sadly this is all too common. The above is in fact a very real example taken from the Silverlight Toolkit samples on Codeplex .

So the steps to correct this are first be aware of the language equivalents when translating from C# to VB. See the MSDN documentation on language equivalents for a great starting point. And take note of the operator equivalents. Some of the most common operators where people seem to make mistakes are:

operator VB C#
bitwise And And &
bitwise Or Or |
bitwise exclusive Or XOr ^
Short circuited Boolean And AndAlso &&
Short circuited Boolean Or OrElse ||
equality = ==
assignment = =
not equal <> !=
exponent ^  
modulus Mod %
string concatenation & +

From the short list above you can see the ^ and & operators have very different meanings in VB compared to C#. Which leads us to items 2 & 3.

If you are unsure of VB, or are translating and hence have a lot of code that *may* be invalid you can improve catching of these kind of developer mistakes by turning Option Strict On. In the original example, the argb & &HFF000000 would have given the result of a string: argb.ToString followed by –16777216. At runtime this string would then try to be converted to a number and then shifted right, most likely failing.

So if you turn Option Strict On, you’d immediately get warnings on trying to convert the string to a long. But even once you’ve got it compiling with Strict On, you should test the code. A lot of code you can quickly query in the immediate window, or write unit tests.

Oh, and the corrected code in this particular case is:

Public Function ToColor(argb As UInteger) As Color
      Return Color
.FromArgb( _
CType((argb And &HFF000000) >> 24, Byte
), _
CType((argb And &HFF0000) >> 16, Byte
), _
CType((argb And &HFF00) >> 8, Byte
), _
CType(argb And &HFF, Byte


For a complete project that fixes the VB samples for the Silverlight Toolkit, see my blog post from last month

« Previous PageNext Page »