CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Patrick Smacchia [MVP C#]

August 2007 - Posts

  • UI matters (Revisited): Menus and ToolBars vs. Office 2007 Ribbons

     

    My post about our current work in enhancing the VisualNDepend UI with Ribbon Office 2007 style got a lot of feedbacks. Thanks to everybody who participate in the debate and especially to:

     

    • Wesner Moise who took the time to clearly expose its motivation on his blog about his choice of Ribbon for the UI of the NStatic tool.
    • Chris Bryant, Senior Product Manager, Microsoft Office, who took the time to advise us and to answer our questions about the Ribbon license (more on this later).

     

     

     

    Based on all these feedbacks, we got convinced that the Ribbon choice is the good one. It seems that around 2 users on 3 would prefer Ribbon over Menus and ToolBars (aka. CommandBar). Although this ratio is significant, it is not high enough to allow us completely getting rid of the CommandBar option. Hence, in the option menu we will let the choice to our users to choose between Ribbon or (exclusive) CommandBar (Ribbon is the choice by default).

     


     

     

     

    Supporting both Ribbon and CommandBar leaded us to some interesting refactoring of our MainForm class. Basically, we now have 2 MainForm classes, one that derives from the DevExpress.XtraEditors.XtraForm class (that directly derives from System.Windows.Forms.Form) and one that derives from  DevExpress.XtraBars.Ribbon.RibbonForm (that directly derives from XtraForm). Both classes rely on 15 common high level UI responsibility managers (one for file menu actions, one for project UI appearance while project loading, one for skin management, one for panel management, one for UI option persistence etc). Our 2 MainForm classes contain controls initialization code that is generated by the VisualStudio's Windows Form designer and also managers' objects' initialization. Except this, our MainForm classes are empty. This choice avoids duplicating code but also allow logically partitioning our big set of controls and as a consequence, we get a more rationalized code.

     

     

     

    Since my first post on Ribbon vs. CommandBar, we figured out that we were not abiding by the Ribbon UI Microsoft license. Basically we were missing the application menu, the Quick access toolbar and some other details:

     


     

     

     

    To respect the Ribbon UI Microsoft license, you must also make sure that you get only one Ribbon menu, that can optionally contains RibbonTab.

     


     

     

     

    At first we were frustrated by this rule because we liked the fact to host a ribbon in our docking panel.

     


     

     

     

    We then moved our Ribbon related to the dependency feature to the main Ribbon and figured out that this was the right think to do. Having 2 Ribbons shown at the same time represent a lot of screen real estate dedicated to commands.More importantly, having just one Ribbon with tabs makes the concepts of contextual UI a reality. When the user wants to browse dependencies, she doesn’t need to see UI commands related to metrics or build comparison.

     


     

     

     

    However, we know that some advanced users work with both metrics and dependencies panels at the same time. It is especially convenient if you have more than one monitor. To handle this scenario, we decided to allow users to show/hide the ToolBars in respective panels at whim. It didn’t mean more work because these ToolBars were already implemented to support the Menus and ToolBars scenario.

     


     

     

     

    Finally we took a chance on this major UI refactoring to propose a use-case oriented help panel that should result in a less steep learning curve:

     


     

     

     

    We also propose a dozen of different UI skins. First we just wanted one skin to avoid investing energy in skins. But then we realized that the framework DXperience offers this possibility almost for free.

     


     

    Once again, thanks for feedbacks and don't hesistate if you have more remarks. We hope to release this new UI (with some bug fixes) by mid september.

     

  • Review: WPF Unleashed By Adam Nathan

    I recently had the chance to read WPF Unleashed by Adam Nathan on the beautiful beaches of the Corsica island . Reading good technical books in a pleasant place is my preferred way to learn about new stuff:

     

     

     

    I can’t imagine a better book to learn WPF for developers with a good win32/GDI/Windows Forms background. If you are not already experienced in these fields, then you’ll certainly find this book overwhelming.

     

    What I really enjoyed is that the author has a mature vision about WPF although we are still in the early days of this platform. What I mean by mature vision is that the book is full of non trivial tips and also contains a lot of advanced remarks that shed lights on implementation details.

     

    WPF is still young from MS clients point of view, but for MSFT insiders, WPF is 6 or 7 years old (or even older?! btw I would like to know the history of the WPF development). I remember Don Box introducing XAML 4 years ago during the PDC 2003 KeyNote. Adam is a senior software development engineer in Microsoft’s .NET Developer Division since 1999, hence the unique vision provided in the book.

     

    The author did also a great job at underlining the intentions behind each part of WPF. As a former technical author, I consider that explaining the intentions surrounding a technical subject as the most important part of writing. Technology is all about intentions! You won’t do anything good with an API as long as you don’t understand the intentions that motivated the engineers who developed it. In my opinion, MSDN often lacks intentions and it is its biggest flaw (although this point got a bit better in the last years).

     

    Another good point is that the book comes with an excellent 50 pages introduction about WPF 3D done by Daniel Lehenbauer, the Lead Developer Responsible for WPF 3D. Here also, you can feel that each remark and each tip provided will be a great help once you’ll have to use WPF 3D in the real-world.

     

    Finally, WPF Unleashed layout is colorful. It certainly makes the reading more pleasant. This particular details generated many talks.

     

    WPF Unleashed is a great book, but WPF is a fantastic technology. I’m really looking forward using it in my own developments. Here are some rambling about some cool details that positively surprised me as a win32/GDI/Windows Forms developer:

     

    • Most of WPF code will be XAML declarative code and not C# or VB.NET procedural code. XAML is a general-purpose declarative language based on XML. Although it is heavily used by WPF, some others framework such as Windows Workflow Fundation use XAML and you can easily use it to handle your own scenarios. XAML code doesn’t compile to IL or C# or VB.NET code but to a binary form (the BAML format). BAML has the double advantage over XML that it yields lighter documents and that BAML documents can be parsed more quickly. Concretely, most of XAML code will be automatically generated by tools. There is no doubt that this XML format will be easier to parse than the messy Windows Forms generated code. Hence, I expect that XAML editors such as the upcoming Microsoft Expression Blend will be much more reliable than the Windows Forms ones.
    • Windows Forms heavily relies on the notion of .NET properties. The engineers of WPF thought that .NET properties were not enough to handle common WPF scenarios and they introduced Dependency Properties. The value of a Dependency Property depends on one or several providers for determining its value at any point of time. For example, the notion of WPF animation continuously modifies the value of a Dependency property to move or rotate an UI object. Dependency Property is the corner-stone to provide declaratively (in XAML) your own logic on value change notifications. Dependency Property is also great to handle inheritance scenario such as: the font of a panel have been changed, which control child’ font should be updated?
    • WPF comes with an entire new API to draw things on the screen. The main difference with the GDI API is that WPF is a completely retained mode graphics system rather than an immediate mode graphics system as GDI. Basically, in immediate mode it is your responsibility to draw the correct pixels when a region of the screen is invalidated (hence the famous WM_PAINT and OnPaint). In retained mode you just have to describe higher-level concepts such as “place a 10x10 blue square at (0,0)”. Clearly retained mode is a simpler way to code complex UI scenarios and it also represents the magic that makes WPF a 100% vector based framework.
    • WPF relies heavily on the logical tree vs. visual trees paradigms. Logical tree is the well know controls tree (a Panel contains 2 GroupBoxes that each contains two Buttons and a Textbox…). Developers will be mainly concerned by the logical tree. The visual tree is the visual representation of things that will be displayed on screen by the retained mode graphics engine. Although a ListBox is logically a single control its default visual tree representation is composed of more primitive WPF elements such as a Border, one or two scrollbars… In WPF the visual tree is decoupled from the logical tree. Thus it is easy to do crazy things such as displaying items of your ListBox on the faces of a rotating 3D polygon.

     

    As Adam pinpoints in his introduction, WPF is the definitive technology to allow doing UI that looks like what you see in the Hollywood movies, such as slick 3D animations when you print a document or when you send a mail. Usability issues aside, Hollywood has been telling us for a long time that software in the real world isn’t as compelling as it should be.

  • UI matters: Menus and ToolBars vs. Office 2007 Ribbons

     Update: This blog entry has been revisited here.
     

    We are currently refactoring the NDepend UI and we hope to make it simpler. Everything started from a simple, yet judicious, remark from my friends and colleagues Bob Powell and Fabrice Marguerie:

     

    When you target .NET developers, the closer to VisualStudio’UI, the better your UI is.

     

    I then realized that NDepend UI has room for improvement to abide by this simple tenet and decided that the next feature will be a refactored UI. The UI will be delivered in two phases:

     

    NDepend 2.4 (scheduled for September) will have:

    • Docking windows
    • Menus and ToolBars
    • A new Options Window
    • Super tooltip (with pictures when relevant and 2 levels of explanations)
    • The possibility to choose the skin (the default will be the VisualStudio 2008 one, but we’ll propose also Office 2007 Blue/Black/Silver, Office 2003 and many others)
    • Automatic saving/restoring of layout.
    • Enhanced help categorized by use-case (metric, dependencies browsing, build comparison etc..). For each use case a starter will be proposed

     

    NDepend 2.5 (scheduled for October) will have:

    • Integration of NDepend.Project.exe into VisualNDepend.exe (a la VisualStudio Project Properties)

    • Start Page
    • Colorfull information about Code Elements.

     

    This way we expect that .NET developers will more feel at home when using NDepend which should result in a less steep learning curve. We needed more than default WindowsForm 2.0 controls. Following Wesner Moise (from NStatic) advice, we will rely on the DevExpress’ DXperience controls suite (free for MVPs by the way). We already tinker a lot with DXperience and I’m completely satisfied with it. Good object model, full integration with VisualStudio Windows Form editor, nice rendering and good runtime performances. The only drawback is that the NDepend redistributable zip file will grow from 1.7 to around 6 MB because of the weight of DXperience DLLs. I like to keep things small when possible but here we had no choices.

     

    We had to take a decision. On one hand VisualStudio.NET (all versions) heavily relies on Menus and ToolBars. On the other hand, since Office2007 Microsoft claims that Ribbons represent a better way than Menus and ToolBars to organize features of a product. I suppose that completely refactoring the UI of their second flagship product was a big challenge for MS and that they thought about it very carefully.

     

    In order to abide by the ‘closer to VS UI, the better’ tenet, we first decided to choose Menus and ToolBars. After all, Ribbons are good for beginners but NDepend users are experienced developers. Here is what the Menus and ToolBars UI looks like:

     

     

     

     

    However, when starting using NDepend, experienced developers are NDepend beginners and we then thought that Ribbons could be a good choice also. We did a UI try and here is what the Ribbon UI looks like: 

     


     

     

     

    Here is what it looks like with Office2007 blue skin:

     


     

     

     

    Instead of choosing between Menus and ToolBars or Ribbons, we decided to choose both. When running NDepend for the first time, the user will get the Ribbons UI. A 32x32 commented button will allow her to switch to Menus and ToolBars UI version. She could then go back to Ribbons UI by clicking a toolbar button or by using the first Options panel:

     

     

     

    This setting is automatically saved and will be restored for future use and it can be changed at anytime.

     

    The main drawbacks of this approach is that it gives 2 appearances to the product and it adds a button. On the other hand, we expect that experienced developers are used to configure their tool appearance.

     

    Please, tell us what you think.

  • New .NET 3.5 core stuff

    While installing VisualStudio 2008 Beta2 I was surprised that the NET framework 2.0 installation got automatically updated. My good old copies of mscorlib.dll v2.0.50727.42 and friends got updated to v2.0.50727.1378. I expected to saw a new C:\WINDOWS\Microsoft.NET\Framework\v3.5.xxx folder but instead I had to search in C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5 to see new assemblies. I’ve been especially interested by the new System.Core.dll assembly that contains most of new stuff that should have been put in mscorlib.

     

    When creating a new project with VisualStudio 2008 Beta2, System.Core.dll is automatically referenced. It seems that System.Core.dll has been created to avoid touching mscorlib.dll and System.dll code. This is a consequence of the.NET framework compatibility policy. 

     

    However mscorlib has been updated and by curiosity I compared mscorlib v2.0.50727.0 and v2.0.50727.1378 with the build comparison feature of NDepend :

     

    The following CQL Query matches 389 methods dispatched into 95 types:

    SELECT METHODS FROM ASSEMBLIES "mscorlib" WHERE CodeWasChanged

     

    The following CQL Query matches 164 methods:

    SELECT METHODS FROM ASSEMBLIES "mscorlib" WHERE CodeWasChanged AND IsPublic

     

    The following CQL Query matches 30 methods:

    SELECT METHODS FROM ASSEMBLIES "mscorlib" WHERE WasAdded

     

    The following CQL Query matches no method:

    SELECT METHODS FROM ASSEMBLIES "mscorlib" WHERE WasRemoved

     

    The following CQL Query matches 4 methods (all of them were declared as internal and are now private):

    SELECT METHODS FROM ASSEMBLIES "mscorlib" WHERE CodeWasChanged AND IsPublic

     

    These numbers might be a bit flawed because some C#3 compiler optimization might have changed the IL code of some methods (and NDepend bases its code comparison on IL code). However, I checked with Reflector and I didn’t find any false positive. So, what code has been changed? Actually I’m not sure I can legally talk about such internal implementations details. If you are curious (as me) I invite you to do the comparison by yourself.

     

    However we can talk for sure about System.Core.dll content. My preferred new class is System.Collections.Generic.HashSet<T> .My code is full of Dictionary<something,object> where the second parameter type is useless and I will be for sure heavy consumer of HashSet<T>. However, we won’t migrate the NDepend code soon to get these facilities since like many ISVs, we have to wait that the .NET framework 3.5 gets largely adopted (end of 2008 sounds reasonable). HashSet<T> is the only new collection in .NET 3.5.

     

    The namespace System in System.Core.dll contains some classes for extended time zone feature and a lot of new delegate classes dedicated to LINQ support(Func<T,TResult>…). There is also 2 new namespaces dedicated to LINQ: System.Linq and System.Linq.Expressions.

     

    There is a new namespace Microsoft.Contract that contains some attribute with sexy names such as ImmutableAttribute or InvariantMethodAttribute. Unfortunately, all these attributes are declared internal and we can’t use them. That’s sad since in my opinion immutable types are an excellent mean to deal with multi-threaded code (I hope to blog about this later). Btw, we recently add some supports in CQL to allow ensuring immutability with CQL queries such as:

    // This CQL constraints warns when MyImmutableClass is not indeed immutable

    WARN IF Count > 0 IN SELECT TYPES WHERE !IsImmutable AND NameIs "MyImmutableClass"

     

    There seems to be new support for encrypted Safe Handle with some new public classes such as SafeNCryptHandle in the namespace Microsoft.Win32.SafeHandles but so far there is no documentation available online. SafeHandle was a great addition to .NET 2.0, sometime considered as the best v2.0 feature of the .NET Framework 2.0. Safe Handles allow dealing properly with complex situations when using unmanaged resources from managed code.

     

    There is a new namespace System.IO.Pipes that allows using Windows pipe from managed code without relying on .NET Remoting (that relies internally on pipes when using the ipc scheme, InterProcessCommunication).

     

    There is the new namespace System.Diagnostics.PerformanceData that allows to use from managed code some new Vista specific performance counters

     

    There is some new WMI wrappers in the namespace System.Management.Instrumentation.

     

    The namespace System.Runtime.CompilerServices contains 3 classes dedicated to LINQ advanced scenario such as serializing your expressions and scoping their executions. Ayende wrote some thoughts on this.

     

    The namespace System.Security.Cryptography has been enhanced with some new algorithms largely commented by Shawn Farkas here and here.

     

    Finally the namespace System.Threading contains a new ReaderWriterLockSlim that is meant to replace the ReaderWriterLock class that notoriously suffers from both design and performance issues. Joe Duffy has some great talk about this. Actually, the ReaderWriterLock class hasn't been tagged as obsolete.

     

    There is few new ‘core’ stuff in .NET 3.5 comparing to what contained the .NET 1.1 to .NET 2.0 delta. It seems to be a good sign of maturity and it allows developers to concentrate their learning endeavour on high level framework such as WCF and WPF. My two cents is that I would have wished more collection implementations, more core math support (such as linear algebra) and more IO support (especially for absolute/relative/normalized pathes).

More Posts

Our Sponsors