Nov 28

As expected, Day 2 at the PDC had people with more expectations and hopes of being exciting than day 1 did.

A much better keynote from Steven Sinofsky laid out the details on how Windows 7 was built with users in mind, how they like to share the user pain etc with funny videos thrown in to the mix. Also IE9 was announced with better standards and HTML5 support, including rounded corners in css.

There was a hardware devices walkthrough that showed us variety of devices and laptops with touch, sensor, location-aware capabilities. The biggest surprise was when Sinofsky announced that Microsoft was giving away a custom-built multi-touch laptop to every attendee. Now it all made sense, why Microsoft had cut various corners at the conference including no breakfast, no party.

Scott Guthrie, the developer folk hero (that’s what the press calls him), made an awesome presentation of new capabilities in Silverlight 4. The key thing was how Silverlight now is going to be the #1 development platform for a .Net developer and still target business apps, games, and a variety of other applicable scenarios across OSs. It’s amazing how they delivered exactly what the developers have been asking for since Silverlight 3, in such a short time span. He attributed the success to some innovative ways of managing development.

Key takeaways from ScottGu’s keynote:
Silverlight 4 Beta out now – RTM early 2010
General

  1. Printing Support
  2. Implicit Styling
  3. WebCam/Microphone Support
  4. RichTextArea Control
  5. Right-Mouse Button Events
  6. Drag-n-Drop/Clipboard Access
  7. UDP/Multicast Support in Networking

Out of the Browser Improvements

  1. Elevated Trust
  2. WebBrowser Control
  3. Controlling the Window
  4. Notification Windows (e.g. Outlook popup’s)
  5. COM Integration

Data Binding Improvements

  1. Binding to DependencyObjects (used to be FrameworkElement)
  2. StringFormat Markup Extension
  3. TargetNullValue Markup Extension
  4. FallbackValue Markup Extension
  5. Support for IDataErrorInfo and new INotifyDataErrorInfo for reporting validation errors.
  6. Binding to String Indexers
  7. GroupDescription support on CollectionViewSource for simplified grouping.

iPhone support from streaming media – IIS smooth streaming in Silverlight

There was a quick demo by Scott Hanselman on drag and drop and rich support for Silverlight in VS 2010, along with RIA services. To me, Silverlight 4, VS 2010 and RIA Services try to provide the kind of platform that ASP.Net 2 with VS 2005 provided. Allowing developers not to think too much about the underlying behaviors and magic, just make things work. With RIA Services, write validations once and they will be applied to both server and client side, also developers don’t have to worry about async behavior of Silverlight. There is also magical Intellisense support for RIA services on the Silverlight client side, the moment anything changes on the server side. This all happens inside Visual Studio. Magic!

I won’t go much in to SharePoint 2010 and it’s supposed awesomeness, as it’s not directly related to our work. If you are interested check out the keynote.

Another interesting announcement is the Microsoft Live Labs product called Pivot. Pivot makes it easier to interact with massive amounts of data in ways that are powerful, informative, and fun. Basically it’s a way to do rich data visualization. I asked the guy at the Pivot booth, if Xaml itself can be viewed as Pivot data. Right now they don’t support that. May be in future. Doesn’t stop me from thinking the possibility of doing it on our own, by using WPF RenderBitMap. If you need a Pivot invite, let me know.

Moving on, I attended Scott Hanselman’s session on ASPNet MVC Ninja tricks. He mostly covered the hidden potential of T4 templates and how one can use them with MVC. Talk was entertaining as usual, Some notes from the session.

  1. Set MvcBuildViews flag in the csproj file to true, to be able to do type-checking compile time errors on MVC views
  2. Use T4 to get compile time errors for dynamic/string references in views (like image filenames)
  3. Html.EnableClientValidation provides automated json-based client side validation on domain objects and properties
  4. Html.DisplayForModel just spits out the values from the model object – easy to troubleshoot, verify
  5. UIHint attribute on a model object property for “Phone” maps to Phone.ascx, that way now we can have generic way of rendering a type in the UI
  6. DataAnnotations is getting better and adding more and more stuff like UIHint attribute above.

Many Core, parallel computing session by Stephen Toub (Sr Prog Manager of Parallel Computing platform) was pretty good. The session on PLINQ also provided a lot of tips on what to use and when. Some notes from the session.

Performance tips when using PLINQ

  1. Avoid/Reduce Memory allocations inside delegates and linq queries, use value types (structs may be) if you’ve to use Anonymous types
  2. Set in app.config of an application
  3. Avoid true and false sharing - Recently accessed memory locations are stored in a fast cache
  4. Use expensive delegates, computationally expensive delegates is the best linq. Cheap delegate over long sequence may have overheads
  5. Write simple plinq queries, use AsParallel only where you want to in the linq query
  6. Choose the right partitioning
  7. a. Arrays and Ilists are partitioned statically, because we know the length before hand
  8. b. Other collections like Ienumerable are done in chunks of a few at a time, in to the buffer
  9. Measure always if it works
  10. Find a bottleneck if it fits a data-parallel pattern, try plinq
  11. Use Parallel extensions related toolwindows for debugging inside visual studio

More at Code.msdn.microsoft.com/perfextsamples

After the session, had a chat with Stephen Toub, specifically around the idea of using it for a com component used by ASPNet. He said that he is not so sure about this scenario as a case for PLINQ. Once the website hits saturation, the ROI may not yield enough benefits. However during non-peak periods the response time can speed up. He concluded that the best approach might be to try Parallel.For or Parallel.ForEach rather than using IParallelEnumerable based linq queries. PLINQ is mostly used in scenarios where a large number of computation has to happen in batch, performing the same task everytime. The way to look at parallel computing is to look at it as breaking up of your program in to several tiny pieces of task. These tasks should be independent of each other and not have side effects. Now you can parallelize them using Parallel extensions and/or PLINQ.

How about powerful features like sequence operators, pattern matching etc from F# are brought to C#. Talked to an architect from VS langauges platform about this. It looks like there are no such plans atleast in the near future. Both languages are meant to serve specific purposes and things in mind.

From Luca’s session on Fututre of languages, the next new features in C# are going to be

  1. Compiler as a service – this will enable a C# interactive tool just like F# interactive today, inplace compile and run
  2. Asynchronous Programming – Async prefix to api methods, with yield keyword marking async operations, without changing readability of code
  3. Immutability – like F#, immutability without having to worry about state changes can be a cool addition to C#

As you know the C# 4 already supports declarative, concurrent and dynamic behaviors.

Another super cool technology I am excited about is Reactive Extensions (Rx) to .Net. Primarily looked at as Linq 2 Events, although it’s much more than that. Rx introduces duality to IEnmerable and IEnumerator, by providing IObserverable and IObserver. Enables us to write inline code that subscribes to events and the callback is pushed iteratively to the piece of code inside the subscription. Erik Meijer’s session on Rx was pretty much the same as the channel 9 videos you might have seen already. Worth a watch if you are new to Rx. This is part of Silverlight 4. Now it’s backported to .Net 3.5 and available for download on devlabs. System.Reactive namespace is where Rx comes from.

One of the other edutaining sessions was Windows Identity Foundation by Vittorio Bertocci, don’t miss that one. With WIF we now have another addition to Foundation technologies. This is moving to a Claims based / Federated security model. Soon I think enterprise apps and websites moving to this approach and will fundamentally change the messiness of the authentication/authorization code for better.

As there were too many sessions overlapping each other, I couldnt’ catch up on all of them, but I have begun to watch the videos and aim to cover the missed ones. Will write more blog posts as I learn more.

As expected, Day 2 at the PDC had people with more expectations and hopes of being exciting than day 1 did.
A much better keynote from Steven Sinofsky laid out the details on how Windows 7 was built with users in mind, how they like to share the user pain etc with funny videos thrown in to the mix. Also IE9 was announced with better standards and HTML5 support, including rounded corners in css.
There was a hardware walkthrough that showed us variety of devices and laptops with touch, sensor, location-aware capabilities. The biggest surprise was when Sinofsky announced that Microsoft was giving away a custom-built multi-touch laptop to every attendee. Now it all made sense, why Microsoft had cut various corners at the conference including no breakfast, no party.
Scott Guthrie, the developer folk hero (that’s what the press calls him), made an awesome presentation of new capabilities in Silverlight 4. The key thing was how Silverlight now is going to be the #1 development platform for a .Net developer and still target business apps, games, and a variety of other applicable scenarios across OSs. It’s amazing how they delivered exactly what the developers have been asking for since Silverlight 3, in such a short time span. He attributed the success to some innovative ways of managing development.
Key takeaways from ScottGu’s keynote:
Silverlight 4 Beta out now – RTM early 2010
General
Printing Support
Implicit Styling
WebCam/Microphone Support
RichTextArea Control
Right-Mouse Button Events
Drag-n-Drop/Clipboard Access
UDP/Multicast Support in Networking
Out of the Browser Improvements
Elevated Trust
WebBrowser Control
Controlling the Window
Notification Windows (e.g. Outlook popup’s)
COM Integration
Data Binding Improvements
Binding to DependencyObjects (used to be FrameworkElement)
StringFormat Markup Extension
TargetNullValue Markup Extension
FallbackValue Markup Extension
Support for IDataErrorInfo and new INotifyDataErrorInfo for reporting validation errors.
Binding to String Indexers
GroupDescription support on CollectionViewSource for simplified grouping.
iPhone support from streaming media – IIS smooth streaming in Silverlight
There was a quick demo by Scott Hanselman on drag and drop and rich support for Silverlight in VS 2010, along with RIA services. To me, Silverlight 4, VS 2010 and RIA Services try to provide the kind of platform that ASP.Net 2 with VS 2005 provided. Allowing developers not to think too much about the underlying behaviors and magic, just make things work. With RIA Services, write validations once and they will be applied to both server and client side, also developers don’t have to worry about async behavior of Silverlight. There is also magical Intellisense support for RIA services on the Silverlight client side, the moment anything changes on the server side. This all happens inside Visual Studio. Magic!
I won’t go much in to SharePoint 2010 and it’s supposed awesomeness, as it’s not directly related to our work. If you are interested check out the keynote.
Another interesting announcement is the Microsoft Live Labs product called Pivot. Pivot makes it easier to interact with massive amounts of data in ways that are powerful, informative, and fun. Basically it’s a way to do rich data visualization. I asked the guy at the Pivot booth, if Xaml itself can be viewed as Pivot data. Right now they don’t support that. May be in future. Doesn’t stop me from thinking the possibility of doing it on our own, by using WPF RenderBitMap.(http://www.getsatisfaction.com/live_labs_pivot/topics/text_based_image_content) If you need a Pivot invite, let me know.
Moving on, I attended Scott Hanselman’s session on ASPNet MVC Ninja tricks. He mostly covered the hidden potential of T4 templates and how one can use them with MVC. Talk was entertaining as usual, Some notes from the session.
1. Set MvcBuildViews flag in the csproj file to true, to be able to do type-checking compile time errors on MVC views
2. Use T4 to get compile time errors for dynamic/string references in views (like image filenames)
3. Html.EnableClientValidation provides automated json-based client side validation on domain objects and properties
4. Html.DisplayForModel just spits out the values from the model object – easy to troubleshoot, verify
5. UIHint attribute on a model object property for “Phone” maps to Phone.ascx, that way now we can have generic way of rendering a type in the UI
6. DataAnnotations is getting better and adding more and more stuff like UIHint attribute above.
Many Core, parallel computing session by Stephen Toub was pretty good. The session on PLINQ also provided a lot of tips on what to use and when. Some notes from the session.
Performance tips when using PLINQ
1. Avoid/Reduce Memory allocations inside delegates and linq queries, use value types (structs may be) if you’ve to use Anonymous types
2. Set <runtime><gcServer enabled=”true”></runtime> in app.config of an application
3. Avoid true and false sharing
a. Recently accessed memory locations are stored in a fast cache
4. Use expensive delegates, computationally expensive delegates is  the best linq. Cheap delegate over long sequence may have overheads
5. Write simple plinq queries, use AsParallel only where you want to in the linq query
6. Choose the right partitioning
a. Arrays and Ilists are partitioned statically, because we know the length before hand
b. Other collections like Ienumerable are done in chunks of a few at a time, in to the buffer
7. Measure always if it works
8. Find a bottleneck if it fits a data-parallel pattern, try plinq
9. Use Parallel extensions related toolwindows for debugging inside visual studio
10. Code.msdn.microsoft.com/perfextsamples
After the session, had a chat with Stephen Toub (Sr Prog Manager of Parallel Computing platform), specifically around the idea of using it for a com component used by ASPNet. He said that he is not so sure about this scenario as a case for PLINQ. Once the website hits saturation, the ROI may not yield enough benefits. However during non-peak periods the response time can speed up. He concluded that the best approach might be to try Parallel.For or Parallel.ForEach rather than using IParallelEnumerable based linq queries. PLINQ is mostly used in scenarios where a large number of computation has to happen in batch, performing the same task everytime. The way to look at parallel computing is to look at it as breaking up of your program in to several tiny pieces of task. These tasks should be independent of each other and not have side effects. Now you can parallelize them using Parallel extensions and/or PLINQ.
One of the things I wanted to find out about was – if powerful features like sequence operators, pattern matching etc from F# are brought to C#. Talked to an architect from VS langauges platform about this. It looks like there are no such plans atleast in the near future. Both languages are meant to serve specific purposes and things in mind.
From Luca’s session on Fututre of languages, the next new features in C# are going to be
Compiler as a service – this will enable a C# interactive tool just like F# interactive today, inplace compile and run
Asynchronous Programming – Async prefix to api methods, with yield keyword marking async operations, without changing readability of code
Immutability – like F#, immutability without having to worry about state changes can be a cool addition to C#
As you know the C# 4 supports declarative, concurrent and dynamic behaviors.
Another super cool technology I am excited about is Reactive Extensions (Rx) to .Net. Primarily looked at as Linq 2 Events, although it’s much more than that. Rx introduces duality to IEnmerable and IEnumerator, by providing IObserverable and IObserver. Enables us to write inline code that subscribes to events and the callback is pushed iteratively to the piece of code inside the subscription. Erik Meijer’s session on Rx was pretty much the same as the channel 9 videos you might have seen already. Worth a watch if you are new to Rx. This is part of Silverlight 4. Now it’s backported to .Net 3.5 and available for download on devlabs. System.Reactive namespace is where Rx comes from.
One of the other edutaining sessions was Windows Identity Foundation by Vittorio Bertocci, don’t miss that one. With WIF we now have another addition to Foundation technologies. This is moving to a Claims based / Federated security model. Soon I see enterprise apps and websites moving to this approach and will fundamentally change the messiness of the authentication/authorization code for better.
As there were too many sessions overlapping each other, I couldnt’ catch up on all of them, but I have begun to watch the videos and aim to cover the missed ones. Will write more blog posts as I learn more.

Must watch PDC Presentations, recommend you to watch wmvhigh version in Windows Media Player, because you can forward/rewind etc

  1. CL09 How Microsoft Visual Studio 2010 Was Built with WPF 4 by Paul Harrington
  2. CL16 Optimizing for Performance with the Windows Performance Toolkit by Michael Milirud
  3. CL19 Building Line of Business Applications with Microsoft Silverlight 4 by David Poll
  4. CL20 Improving and Extending the Sandbox with Microsoft Silverlight 4 by Joe Stegman
  5. CL22 Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight by John Papa
  6. CL24 XAML Futures in Microsoft .NET Framework, Microsoft Silverlight and Tools by Michael Shim, Rob Relyea
  7. FT11 Future Directions for C# and Visual Basic by Luca Bolognese
  8. FT20 F# for Parallel and Asynchronous Programming by Luke Hoban
  9. FT23 Extending the Microsoft Visual Studio 2010 Code Editor to Visualize Runtime Intelligence by Bill Leach, Gabriel Torok
  10. FT24 Building Extensible Rich Internet Applications with the Managed Extensibility Framework by Glenn Block
  11. FT35 Microsoft Visual C# IDE Tips and Tricks by DJ Park
  12. FT52 Microsoft Perspectives on the Future of Programming by Butler Lampson, Erik Meijer, Don Box, Jeffrey Snover, Herb Sutter, Burton Smith
  13. FT59 ASP.NET MVC 2: Ninjas Still on Fire Black Belt Tips by Scott Hanselman
  14. SVC01 Lap Around the Windows Azure Platform by Manuvir Das
  15. FT03 Manycore and the Microsoft .NET Framework 4: A Match Made in Microsoft Visual Studio 2010 by Stephen Toub
  16. CL01 Microsoft Silverlight 4 Overview by Karen Corby
  17. VTL04 Rx: Reactive Extensions for .NET by Erik Meijer
  18. SVC02 Windows Identity Foundation Overview by Vittorio Bertocci
Tagged with:
Oct 16

What is TDD? From whatever information and little bit of knowledge gathered, I’ve come to believe it’s “Test Driven Design” – as opposed to “Test Driven Development”. Often it’s also called test-first development. In any case, you write tests first, watch it fail, go back and write code that implements the function or class at hand, then watch the test pass. This is also called red-green refactoring because, the “Test Results” turn from red to green as you go along.

However, the primary goal of TDD seems to be driving the design itself. You write tests, with the scenario of how a function would be ‘used’ and then go back and implement it. This does a lot of positive things. First, it cuts down a lot of premature code overrun. Often times we fall in to the trap, where we spend lot of time and effort trying to make up for things like, ‘one other thing I want to add here’, ‘may be sometime in future somebody will use this, so let me add another function’. Basically writing a whole lot of extra code, that you many never need or wanted. By following the TDD way, however, you are most likely be addressing and completing only the immediate requirement and function at hand. If in future, the time comes, you simply write a test for it, go back and implement it. That simple.

With tools like Resharper and CodeRush at hand inside Visual Studio, refactoring and making the code evolve like a flow becomes so much more quicker and addictive.

Thus, by remembering that TDD is “Test Driven Design” you start focusing more on ‘Evolution of your design’ as opposed to simply ‘Unit testing your code’.

The by-product of the ‘Evolution of design’ is of course the unit tests, which is a bonus. This is not entirely true always. Because once the design is complete, and you go in to a QA phase, you will be writing unit tests to evaluate when you fix a bug. Which is perfectly the right way to go. Thus you will then have both ‘design oriented unit tests’ + ‘unit tests against bugs’, at which point you will be expert enough to see the difference between the two.

Now, there is also what is called a bottom-up approach, which lot of programmers used to follow until TDD came along. Write a little bit of code, test it, then write some more, test it. It’s like manufacturing or carpentry. You cut a wood, you measure it, check if it’s okay, if still more needs to be cut, you go back and do it. This is the most straight forward obvious reason many write unit tests. Easy to get your head around the rationale. TDD is only for those who are willing to spend that extra time and effort initially to understand and assimilate the art. It would only be an initial down payment for the betterment of the design process long term.

Important to remember, like Uncle Bob Martin says, nothing can be concluded unless you try it out yourself. I certainly would have to agree it may not work out in all situations,especially UI. There are many who dispute TDD and claim that TDD slows you down, and it’s not feasible to do TDD and have 90%-100% code coverage, when you have a deadline approaching.

The famous blogger, founder of FogCreek software and author Joel Spolsky recently wrote an article on his blog about ‘Duct tape programmer’. There’s been a lot of comments, criticism and blog posts about it in the blogosphere, by the likes of Uncle Bob Martin, Peter Siebel (Author of the now famous book ‘Coders at Work‘) and Tim Bray.

This post was inspired by reading all these articles.

Tagged with:
Sep 02

I stumbled in to a section of code today, that looked like it needed refactoring.
Refactored it basically by using generics and breaking it in to two functions, one of which is reusable.
Important thing was to get the config value of the right type, even when a config key is missing and is null.
The default(T) is pretty sweet.

Thought of sharing this.
Before:

/// 
        /// Loads config values in to Settings object and returns it
        /// 
        /// A filled settings object
        private static Settings LoadAndReturnSettings()
        {
            var settings = new Settings();

            if (ConfigurationSettings.AppSettings["WebFolderPath"] != null)
            {
                settings.WebFolderPath =
                    Convert.ToString(ConfigurationSettings.AppSettings["WebFolderPath"]);
            }

            if (ConfigurationSettings.AppSettings["HtmlTemplatePath"] != null)
            {
                settings.HtmlTemplatePath =
                    Convert.ToString(ConfigurationSettings.AppSettings["HtmlTemplatePath"]);
            }

            if (ConfigurationSettings.AppSettings["IsSummaryVisible"] != null)
            {
                settings.IsSummaryVisible =
                    Convert.ToBoolean(ConfigurationSettings.AppSettings["IsSummaryVisible"]);
            }

            if (ConfigurationSettings.AppSettings["IsPanelVisible"] != null)
            {
                settings.IsPanelVisible =
                    Convert.ToBoolean(ConfigurationSettings.AppSettings["IsPanelVisible"]);
            }

            if (ConfigurationSettings.AppSettings["IsValueVisible"] != null)
            {
                settings.IsValueVisible =
                    Convert.ToBoolean(ConfigurationSettings.AppSettings["IsValueVisible"]);
            }
            return settings;
        }

After:

  /// 
        /// Loads config values in to Settings object and returns it
        /// 
        /// A filled Settings object
        private static Settings LoadAndReturnSettings()
        {
            var settings = new Settings();
            settings.WebFolderPath = GetConfigValue("WebFolderPath");
            settings.HtmlTemplatePath = GetConfigValue("HtmlTemplatePath");
            settings.IsSummaryVisible = GetConfigValue("IsSummaryVisible");
            settings.IsPanelVisible = GetConfigValue("IsPanelVisible");
            settings.IsValueVisible = GetConfigValue("IsValueVisible");
            return settings;
        }

        /// 
        /// Extracts a value from Config file and returns the correct type, given a Configuration key
        /// 
        /// a value of the right type
        private static T GetConfigValue(string configurationKey)
        {
            if (ConfigurationSettings.AppSettings[configurationKey] != null)
            {
                return (T)Convert.ChangeType(
                       ConfigurationSettings.AppSettings[configurationKey], typeof(T));
            }
            return default(T);
        }
Tagged with:
preload preload preload

Powered by eShop v.4