Monday, September 19, 2011

Windows 8–my first thoughts

Unless you are living under the rock you would know that Microsoft unveiled details about Windows 8 at the //build/ conference last week. I had the privilege to attend the conference and see it live first hand. I am also fortunate to be one of the first few developers to get my hands on a Windows 8 Samsung tablet with a developer preview OS on it. It was a busy week and Microsoft had a lot to say (there were over a 100 breakout sessions), so much so that the entire first day and a good part of the second day was just dedicated to the “big picture” keynotes. Even more details about the nitty-gritty will emerge now that the cool crowd can all talk about it but here’s my first thoughts on what I have heard so far.
Before the //build/ The buzz that Microsoft managed to create for the //build/ was amazing. Partly because of the PR strategy of only selectively sharing very few details before the conference day. Although some would argue it was not such a great strategy especially when it comes to the .Net and Silverlight developers of the world, I would say they pulled it off fairly well. The media was all over it and the space was ripe with rumors which means it had the attention. Although, being a C# developer I was a little frustrated about the “new HTML5/JavaScript” app development platform in the first video, that little agitation made sure I paid attention to what was going on and grabbed the opportunity to go to the conference with both hands. And I wasn’t disappointed. Read on to know why..
Gut check at the conference If I had to summarize the conference in word I would choose “massive”. Everything was huge about it. There were about 5000 people attending, over 100 sessions, the convention center was huge but they still had to use nearby hotels for some of the sessions and so on. The atmosphere there was electric. After the first days keynotes I talked to a few folks and I could only hear good things about what was being announced. It was a big happy crowd, myself included. I couldn’t think of anything that Microsoft could have done to make these developers happier. They had something for everyone. JavaScript/HTML Devs – Check, .Net/Silverlight/XAML guys – check, C++ – Check, H/W & drivers guys – Check, IT Folks – Check, Cloud folks – Check and to top that they gave away a developer level Samsung tablet to all the attendees. In addition, they also included a docking station and a keyboard as well making sure these devs have no excuses to start building some cool apps. The other noticeable thing to see was the focus on performance and simplicity. In a way it was not a choice if they want to run Windows on ARM based processors but still it was refreshing to see. The APIs that I have seen so far seem to be well designed and abstracts away a lot of heavy lifting the OS is doing for the developers. All in all it all felt good apart from a few minor nitpicks.
New application & development Model A really dumbed down version to summarize Windows 8 will be to say it actually packs two OS into one single image – one is a tablet OS and the other is an enhanced version of Windows 7. And that statement isn’t incorrect until you really get into the theoretical definition wars. It’s just easier to talk like Its two OS into one so that’s what I am going to do.
The “old” OS works just like you would expect. It supports all the runtimes that we all familiar with aka Win32, .Net and Silverlight. If you target this OS, not too much has changed for you apart from getting a refined Windows 7 with better performance characteristics.
The center of the show however is the new touch first metro style OS. “Fast and fluid” as they kept saying. If you have worked on a phone or a tablet platform before, this new OS should feel very familiar to you. It has all the niceties (or restrictions depending on who you talk to) of a sandboxed application environment, restricted access to the system, touch first design, crisp look and feel, app suspension model and an environment where the OS is looking after system resources (memory, battery life, CPU) for the user.
This new OS takes a lot of “inspirations” from some worthy predecessors like iOS, Android and Windows Phone. In fact if you have done any windows Phone development you should feel right at home with Windows 8. A lot of the concepts like app tomb-stoning, push notifications, declaring capabilities, live tiles, application packaging, app certification etc apply straight from windows phone with one BIG difference - the runtime. Windows phone uses a “Silverlight-like” runtime especially designed for the phone. For windows 8 however, the new metro style apps use a completely new runtime called Win RT (Windows RunTime). My first reaction to WinRT was subdued. I felt it was just one more runtime in the mix as different groups within Microsoft couldn’t sort out their politics and the consistency across platforms was “sacrificed” for the lack of better words. But it wasn’t long before I realized that WinRT was actually the touch of genius that made a lot of this possible. For instance look at diagram below describes the numerous programming models available to the developers now. Notice the WinRT as the core of the green section (the new “OS”) being used from all the different programming platforms aka C#/XAML, JS/HTML and C++/XAML. How does that happen you might ask? Well read on.. 

The magic sauce called WinRT Its no secret that If you want the ultimate performance you have to be as close to the hardware as possible. The more layers you have to go through before hitting the metal the slower you will be. I can imagine the windows team had a few choices to make when they first embarked on this new bold journey of developing the metro style OS. They could have repurposed Silverlight (the light weight runtime of choice at that time) as the windows phone team did and used it for the new OS but my guess is the performance and the scale just wouldn’t have cut it. Again, you would be a layer on top of the OS/Win32 which slows you down. Plus they wanted to support the JavaScript/HTML stack as well. So It doesn’t surprise me that they chose to go with writing a new runtime from scratch. The new WinRT is written in C++ as a part of the OS itself. Completely native to the OS, not a layer on top of win32. As far as rendering engine is concerned the story is two fold. The HTML stack uses the same rendering engine as IE10 underneath whereas XAML has its own rendering engine. Both however use DirectX and hardware acceleration underneath – no more GDI. So its written in C++? Hmm? So how do you call it from JavaScript one might ask, wouldn’t that have to be some wrappers and layers before the call hits WinRT? Well not exactly. WinRT uses metadata projections to expose all the information about the APIs in all different non c++ languages that WinRT supports aka JavaScript, C# and VB. So even though from JavaScript you are calling APIs that feel natural to the JavaScript developers you are actually calling native OS components underneath giving you the performance that would be hard if not impossible to match with any other runtime. The API call itself is an extremely light weight VTable call. That to me is the touch of genius. You are getting the best performance the OS has to offer as well as the reach to the millions of already skilled developers who can start building apps in their language of choice. Remarkable!
The rough edges So anything other than awesome? Well, It’s a developer preview OS. And there are some noticeable rough edges as to be expected. After using the device for about 5 days I have encountered a few of those and I can say the same for quite a few people at the conference. One of the most common thing the presenters said during the sessions was “the demo gods are not happy it seems” so there was a fair bit of SNAFUs happening. But I am taking heart in something that Sinofsky said during the keynote “we are driven by quality and not dates”. I hope he holds true to that. Here’s sincerely hoping that the execution engine at Microsoft delivers and they don’t release the product with some obvious rough cuts like they did in windows phone. The other noticeable void was Office. There was no mention of Office next at all neither of a metro style Office apps. That definitely is concerning.
iPad killer? One common question that circled around during the conference was not so much if W8 will kill iPad but does it stand a chance to compete in that space? My personal view is it does. It’s a bold new OS. Think of it as a OS-X and iOS bundled together and it works on a whole slew of hardware platforms including ARM based (although the ARM support is not released yet) devices. So that definitely gives an edge to Microsoft before one asks the question of the eco system. Will Microsoft be able to generate enough interest to create a good number of “quality” apps on windows platform? Notice the focus on quality. In terms of number of apps windows phone had a higher number than the apple app store when compared taking the age of the platform into account but a lot of the apps were just not up to the mark. The time will tell how the app eco system evolves but that’s just a part of the eco system story. I know its easy to focus on the app eco system given the state of the industry right now but there is the other part of the eco system which is hardware. The eco system of devices that windows has built around it is unmatched and I will not be surprised if this eco system evolves beyond anybody’s guess. Tablets that duel as an enterprise power machine when docked is a very certain reality. Even though we live in the touch first world, the power of keyboard and mouse should not be underestimated especially for enterprise applications that require a lot of text entry and precision of the mouse. Half a billion USB devices out there don’t have a port to plug-in to in the Apple eco system. Add to that the new USB 3.0 standard which I am sure will bring the next generation of devices to the market. Enterprises are complicated and convoluted they need all the openness and extensibility they can get that’s one of the reasons Microsoft has a strong hold in that space. The blowout tablet market that Apple has created is something that Microsoft could actually leverage to its advantage. To me it’s a net new opportunity and there is room for more than one players in that space. All in all, I expect some healthy competition in the years ahead.
In summary Windows 8 is a bold new step which I think is in the right direction. The idea of making the platform available to not only existing developers of Microsoft stack but also extending to the slew of web developers out there is remarkable. And its not just OS, the server and cloud, dev platforms and other groups inside Microsoft had stuff to share. As Steve Ballmer mentioned in his keynote, “If Windows 8 is windows reimagined, they are in the process of reimagining Microsoft and windows 8 is an import step towards that goal”. Lets see how it evolves!

Sunday, September 26, 2010

Combining Roles on Windows Azure

Now why would you want to do that? Azure provides a nice separation of roles in web role and a worker role – why do you want to combine those you’ll ask. Multiple reasons – saving cost being the primary. The most requested feature on the Windows Azure feature voting forum is “Make it less expensive to run my very small service on Windows Azure.” and rightly so. If you wish to host your “small service” on the cloud it makes sense to minimize the cost. Even for large scale services this can help to maximize the use of resources. Let’s crunch some numbers to see this in action.

Assume that your “simple service” consists of a simple website that provides the UI to the users. There is also a background worker for sending registration emails, sending newsletters and does some nightly batch processing of your data. Let’s say you don’t need a full blown SQL server and are happy with the semi structured data storage that Windows Azure table storage provides. These assumptions are not unrealistic for a large number of  simple websites, in fact most startup websites will start with this model and then scale out as the traffic increases and that’s exactly what Windows Azure enables you to do. So with these very realistic scenario let’s examine what will it cost to host such a service on Windows Azure. We will only focus on the compute cost as that’s what you will save on (& is the biggest cost for a small service) when you combine roles so we can safely ignore the storage, bandwidth and other costs of hosting on Azure as they are all usage based.

Here’s what the compute instances cost on Windows Azure.

  • Small instance (default): $0.12 per hour
  • Medium instance: $0.24 per hour
  • Large instance: $0.48 per hour
  • Extra large instance: $0.96 per hour

Let’s say you will use the small instances for both your roles. So your monthly cost comes out to be,

30 (days in a month) * 24 (hours in a day) * 0.12 (cost per hour) * 2 (number of instances)
= $172.80 per month

Now you are wondering the worker role is just sitting there doing nothing for most of those hours. Shouldn’t you only count the “compute hours” in which the role is actually is alive and doing work instead of the full 24 hours for a day. Well, that’s not how Windows Azure billing work. It’s pay as you go alright but not at that granularity so you end up paying as long as your have reserved the VM, even in the suspended state. May be some day Azure will be able to provide that level of billing granularity – may be we should request that feature on the forum :-) But till then the only way to save cost here will be - if we just got rid of one role entirely and still do all the work with just one role. Turns out it’s very easy to do that on Windows Azure.

To understand how to do that we first need to understand how web and worker role differs in Windows Azure. One obvious difference  is the web role will have an IIS installed on the VM and the work role will not. What else? Well, turns out that’s about it. In every other sense as far as Window Azure is concerned those roles are pretty much the same. You could potentially have your worker role listen on port 8080 and receive web traffic and your web role have a Run()method that does the background work. When you create a Cloud project in Visual studio, by default in the webrole.cs the template does not add a Run() method like it does in your worker role but there is nothing that stops you from doing that either because the WebRole class also derives from the same RoleEntryPoint which workers derive from as well.

public class WebRole : RoleEntryPoint
public override void Run()
// This is a sample worker implementation. Replace with your logic.
Trace.WriteLine("WorkerRole1 entry point called", "Information");

while (true)
Trace.WriteLine("Working", "Information");

As simple as that. Once your web role gets provisioned Azure fabric will start start IIS and deploy your application as well as start a worker which you can use to do some background processing. The thing to note that both of these processes are running on the same VM and will share the resources so this technique should not be used where a consistently high throughput is required at all the times by either your website or your background worker. But if you are able to use this technique you end up cutting your compute cost in half for your small service.

Hope that helps.

Thursday, August 5, 2010

Using SyntaxHighlighter 3.0+ on your blog

You can guess from the title that this is a Techie blog and that means I will be posting some code snippets from time to time and so I was looking into some options of code syntax highlighting and I narrowed it down to the awesome SyntaxHighlighter. I use a custom domain name but host my blog on blogger. I also use the awesome Windows Live Writer for posting.

Setting SyntaxHighlighter up was fairly easy but I did find a ton of blog posts on the web about how to do that with varying information. A lot of these posts were so old that they just misdirect you and deprive you from using the all the great features that the latest version offers so I thought I might take a moment to post the best solution that I know so far. Here goes,

Things you should know
SyntaxHighligher is a completely javscript and css based solution to syntax highlighting and it works on the client side and does not require you to embed inline styles and css. Now that is great with one drawback. Since the scripts are hosted (either on your site or somewhere on the web) and are linked on your website pages they will not make it to your RSS feed so most readers will not be able to show the highlighting. Personally, I think it is alright but if you don’t agree stop right here, SyntaxHighligher is not for you.

So How to Set it up then
As I said most of the information on the web is old so those posts tell you to link all the the brush JS on your page but from version 3.0 onwards SyntaxHighlighter has a nifty little feature for auto loading just the required brushes rather than linking all of them. Now if you don’t understand what I am talking about don’t worry, it’s even better since you don’t have to “unlearn” anything :-). Just follow the steps below to set it up for your blogger blog!

Step 1: Add the css and JavaScript links in the <head> section of your blog

<link href='' rel='stylesheet' type='text/css'/> 
<link href='' rel='stylesheet' type='text/css'/>
<script src='' type='text/javascript'/>
<script src='' type='text/javascript'/>

Now notice that Alex Gorbatchev is actually providing free hosting for the required JavaScripts and CSS so you don’t have to worry about getting a place to host them. Also you will always point to the latest version if you just point to the “Current” directory.

Step 2: Setup Autoloader for brushes by adding the following javascript function again in the <head> section of your blog

<script language='javascript'>

function path()
var args = arguments,
result = [];

for(var i = 0; i != (args.length-1); i++)

return result

Now blogger actually changes the single quotes to &#39; for you or you can post it encoded like above. Either ways it should be fine.

Step 3: Call to action – Use the JS to highlight all the sections on your blog, insert the script below just above </body> tag.

<script type='text/javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &#39;;

SyntaxHighlighter.autoloader.apply(null, path(
&#39;applescript @shBrushAppleScript.js&#39;,
&#39;actionscript3 as3 @shBrushAS3.js&#39;,
&#39;bash shell @shBrushBash.js&#39;,
&#39;coldfusion cf @shBrushColdFusion.js&#39;,
&#39;cpp c @shBrushCpp.js&#39;,
&#39;c# c-sharp csharp @shBrushCSharp.js&#39;,
&#39;css @shBrushCss.js&#39;,
&#39;delphi pascal @shBrushDelphi.js&#39;,
&#39;diff patch pas @shBrushDiff.js&#39;,
&#39;erl erlang @shBrushErlang.js&#39;,
&#39;groovy @shBrushGroovy.js&#39;,
&#39;java @shBrushJava.js&#39;,
&#39;jfx javafx @shBrushJavaFX.js&#39;,
&#39;js jscript javascript @shBrushJScript.js&#39;,
&#39;perl pl @shBrushPerl.js&#39;,
&#39;php @shBrushPhp.js&#39;,
&#39;text plain @shBrushPlain.js&#39;,
&#39;py python @shBrushPython.js&#39;,
&#39;ruby rails ror rb @shBrushRuby.js&#39;,
&#39;sass scss @shBrushSass.js&#39;,
&#39;scala @shBrushScala.js&#39;,
&#39;sql @shBrushSql.js&#39;,
&#39;vb vbnet @shBrushVb.js&#39;,
&#39;xml xhtml xslt html @shBrushXml.js&#39;,
&#39;xml @shBrushXml.js&#39;

Notice I am using the new AutoLoader functionality and also since my blog is hosted on Blogger I am setting the bloggerMode to true. If your blog/website is different you should not set this flag and the rest of the setup should be the same for you. Also notice I have added XML brush twice one as a part of the xml xhtml.. group and one as a stand alone item. This was done to work around an issue with the WLW plug-in that I use so if you are not using it then you can remove that. Keeping it the way it is doesn’t hurt too. 

Step 4: Add the sections that you want to highlight and set the correct CSS class

<pre class="brush: css; toolbar: false;">

public static void main()


    Console.WriteLine(&quot;Highlight me!&quot;);



And if everything is setup correctly it should look like below,

public static void main()
Console.WriteLine("Highlight me!");

A complete list of brushes can be found here. And the complete list of Settings can be found here. But wait, why remember these brushes and settings, why not install the awesome PreCode Snippet plug-in for the Live Writer and let the plug-in handle that for you. Once you install the plug-in you should be able to fire up the plug-in window like below and go crazy..


Wow, this post got long! But hopefully it will save people some time. And hey, this post will be a good test to see if I set it up correctly or not.

Wednesday, August 4, 2010

Testing Some Code highlighting

public static void main()
Console.WriteLine("Syntax Highlighter Testing");

How about some XML

<script src='' type='text/javascript'/> 
<script src='' type='text/javascript'/>
<script src='' type='text/javascript'/>
<script src='' type='text/javascript'/>
<script src='' type='text/javascript'/>

And some JavaScript maybe

// Adds a new row to the table.
function addRow(){
//get the table
var table = document.getElementById('myExampleTable');

//get the number of rows currently in the table
var numRows = table.rows.length;

//insert a new row at the bottom
var newRow = table.insertRow(numRows);

//create new cells
var newCell1 = newRow.insertCell(0);
var newCell2 = newRow.insertCell(1);
var newCell3 = newRow.insertCell(2);

//set the cell text
newCell1.innerHTML = 'Row ' + (numRows + 1) + ' Cell 1';
newCell2.innerHTML = 'Row ' + (numRows + 1) + ' Cell 2';
newCell3.innerHTML = 'Row ' + (numRows + 1) + ' Cell 3';

And how can you forget SQL..

Select * from Employee

And CSS.. although it might not feature on the blog that much..

a:visited {
a:hover {
a img {

“Page not found” or 502 when accessing an Azure Web Role

In the last week me and one of my collogue have been trying to nail down an issue when we try to access a simple Azure application from our Work network. I am posting it here as I think someone can benefit from this,

I literally just clicked through the Create New Project –> Next –> Next and created a “Simple” Cloud application with just a single Web Role and a Hello World page. Removed the diagnostic connection string that Azure adds by default just to make it even simpler. Basically the page just said “Hello World!” and nothing else was going on. Deployed the app on Azure and to my surprise it just didn’t work. I kept getting the default “Page not found”! Time to fire up fiddler and see what’s going on and here’s what Fiddler gives me,

[Fiddler] Connection to failed.
Exception Text: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Basically nothing much. Same deal when you use a tracert command.

And to add to that the app was just working fine from my iPhone. So we have an app that worked from an external network but didn’t from our corporate network with very little debugging info that one can point at. Luckily there was one service that we were able to hit from our corpnet and I logged into that and found that the only difference between that service and my “hello world” app was the affinity group.

Affinity group Details for the Service that DID NOT work:

Affinity group : mycustomaffinitygroup
Geographic Location: North/Central US

Affinity group Details for the Service that DID work:

Affinity group : Unaffiniated
Geographic Location: Anywhere in US

I changed the “hello world” to Unaffiniated and “anywhere in US” and wallah It started working. Now this SHOULD NOT happen. Either the North/Central data center was just slow to respond to requests from our internet gateway or there is something wonky with the custom affinity groups but either ways it’s BADD! Or a third reason could be the timeout value for our gateway before it closes the connection is set to a low value.. but not likely as I have never seen any issues with any other internet sites as such.

I have a thread going with Steve Marx from Microsoft here. Let’s hope he can track it down if at all it’s an issue with the Azure service. I hope not!

Tuesday, August 3, 2010

Find your favorite Setting in Visual Studio 2010

Most programmers are really picky! Especially when it comes to the IDEs. Visual studio 2010 offers you 100s of customizations. For the most part it’s awesome as long as you can find the setting that you want to change. Here’s what an options dialog from Visual Studio 2010 looks like..


Notice there are 100s of items that you can customize but it’s missing one important thing! Where is the “Find” button to jump to the right setting???

Not to worry, Microsoft cares for you developers. Although it didn’t release it as a Visual studio feature they released an awesome extension called Productivity Power tools. Install that and it has a nice little feature called “Quick Access”, just press cntrl + 3 and you will see a window like below


Notice it finds menu items, Visual studio options and much more. It also let’s you navigate directly to the option from right within the interface. Really helpful.

Btw, have you tried pressing “cntrl + ,” yet?? Go ahead try it.. I think you will like it!

Hope that helps.

Tuesday, June 15, 2010

Configure Microsoft Web Platform installer to install developer tools

Web development is complex and changing rapidly. Just installing all the different tools that you need to do you job is a task in itself and when you have to keep all those pieces updated with the rapid product releases it becomes even more demanding.

Enter Microsoft Web Platform installer! It’s an amazing tool that analyses your computer and carves out a path to upgrade it to the latest bells and whistles. Also lists everything out in a single place where you can just check-check-check and Install instead of finding compatible installers and installing them separately. It also gives you jump starter web applications instead of reinventing those yourselves. Here’s how you configure the web platform installer to include the developer tools (silverlight, Azure and more..) in the mix.

Click on the “Options” on the bottom left corner.

And check the “Developer Tools” box. And click OK.


It will rescan your machine and come up with the dev tools suggestions.


I also like to just fire up the web platform installer every once in a while just to see if there are any interesting updates that are available that I can take advantage of, in fact that’s how I found the Azure tools v1.2 release.

Hope that helps.