2005 2006 2007 2008 2009 2010 2011 2015 2016 2017 aspnet azure csharp debugging elasticsearch exceptions firefox javascriptajax linux llblgen mongodb powershell projects python security services silverlight training videos wcf wpf xag xhtmlcss

Cwalina's Framework Engineering Lecture Posted

In my mind the single most important aspect of any system is usability.  Unless the context states otherwise, when I use the term "optimize" or "efficiency" I am always always talking about usability optimization and efficiency.  Things can be fast with a small footprint, but if you can't figure out how to use it right away or continually confuses your methods for your fields, then it doesn't really matter.  Fortunately, Microsoft agrees with this.  The days of every company writing their own coding-guidelines are gone and we .NET developers been unified under the great Framework Design Guidelines ("FDG") that Krzysztof Cwalina and Brad Abrams have so graciously given us.

To help further the unity in the community, Krzysztof recently posted a lecture on his blog entitled "Framework Engineering: Architecting, Designing, and Developing Reusable Libraries".  Here is the abstract of the lecture:

This session covers the main aspects of reusable library design: API design, architecture, and general framework engineering processes. Well-designed APIs are critical to the success of reusable libraries, but there are other aspects of framework development that are equally important, yet not widely covered in literature. Organizations creating reusable libraries often struggle with the process of managing dependencies, compatibility, and other design processes so critical to the success of modern frameworks. Come to this session and learn about how Microsoft creates its frameworks. The session is based on experiences from the development of the .NET Framework and Silverlight, and will cover processes Microsoft uses in the development of managed frameworks.

This video is, of course, not the only video on such an incredibly critical topic.  Many years ago, Brad Abrams (and friends) gave a lecture series to Microsoft employees on the topic of framework design guidelines.  These videos don't just cover the critically important topic of name guidelines, but also CLR performance topics, interopability guidelines, security topics, as well as various others.  It's a video series that's essential to serious .NET development.

More importantly then these videos though, is the classic work produced by Krzysztof and Brad entitled "Microsoft Framework Design Guidelines".  At the time of this writing, this book has 28 Amazon.com customer reviews and is still at five stars.  Look at a few of the review titles: "A must have for any C# Developer or Architect", "For the individual who wants to rise above the masses", "If you only ever buy one .NET book, make it this one", "AWESOME * 10 = MUST HAVE;" and my personal favorite: "Passionate About Quality?"  These reviews give you a good idea of the level of community acceptance that the framework design guidelines have.  One reviewer even said "I would pay $5 per page for this book, and have found it to be, by far, the most outstandingly useful technical book I've read."  This book covers in detail many of the aspects (and often times more) that have been covered in the videos.  In fact, the videos are actually on the DVD that comes with the book.

The book is also not simply a set of laws.  Throughout the book Microsoft architects and major Microsoft community leaders like Jeffery Richter make comments on various aspects of the framework.  Sometimes they explain why a rule is stated in a certain way and other times they emphasis how crucially important a rule is.  A few of the comments in the book explain problems in the .NET framework stemming from the fact that the guidelines were still in development (people used to say C# looked like Java-- well, many people used Java's nearly obfuscated coding standard!)  At one point in the book one of the authors explains a usability study for .NET streamed and right-out admitted what most of us already know: .NET streaming is extremely non-intuitive!

Many times I hear people say that the success of the .NET framework comes from it's extremely efficient garage collection model, it's flexible common language runtime (in contrast to Java's platform runtime) and it's powerful JIT model.  All those things are crucial, but ease of use is even more at the heart of .NET.  Abstraction in framework design can be defined as the increasing of the semantic value or usability of any entity and it's at this point where we can see .NET far outshine Java and PHP.  I've all but forgotten how to work with pointers, but it's when I forgot my coding standard that I'll start to become obsolete.  It's been said that the success of Windows was driven by the very open nature of the Win16/Win32 API.  Similarly, I highly suspect that it's the the beautiful abstraction with extremely high usability that explains .NET's sheer success.  There's only so much marketing can do; at some point a product has to stand on it's own (even then, Programmers can see though marketing!).  This beautiful abstraction and extremely high usability if course due to the existence and enforcement of the FDG.

To be clear, when I talk about FDG, I'm not simply talking about FXCop rules.  I typically break the .NET framework rules down into three levels: CLS-compliance, FXCop compliance, FDG compliance, and the iDesign standard.  If you do not strictly enforce CLS-compliance, then you may very well be completely stuck in the next version of .NET.  Who knows how non-Microsoft compilers will become.  FXCop will catch problems in your CLS-compliance and it will also catch many of the FDG violations as well.  The FDG rules, however, also cover various aspects of security and performance that only a human can check.  Lastly, when people often mention the FDG, many times what they really mean is the iDesign standard, edited by Microsoft Software Legend Juval Lowy.

In fact, I often use the terms "Framework Design Guidelines" and iDesign standard interchangeably.  They aren't the same thing, but in some contexts it's acceptable to mix them.  Whereas the FDG is primarily for the public interface of a framework, the iDesign standard covers both the public and internal.  The term "iDesign standard" may not be familiar to all, but what represents is.  It's been the .NET coding defacto standard since 2003.  In fact, when you crack open any APress, Wrox, or Sam Publishing book, you will probably be looking at code following the iDesign standard.  Further, the default settings for Visual Studio is the iDesign code layout. 

Every .NET developer knows it and just about everyone follows it.  Some may think the iDesign standard is optional and since it covers private code and in a sense it is optional, but, to be sure, if you are following the FDG rules and the iDesign standard, you have immediately chopped the learning curve of your system by an enormous factor.  Also, if you ever go public with your application (i.e. go open source), you will need to make sure you follow the FDG standard (which includes CLS and FXCop compliance) and the iDesign standard.  Otherwise, your system will probably have virtually no acceptance.

In closing, I should mention that Krzysztof Cwalina and Brad Abrams are releasing the 2nd edition of their famous book, due September 29, 2008.  You can, of course, pre-order on Amazon.  You can be sure that I will!

Links

New XAG Feature: Support for C# 3.0 Automatic Properties

One of the nicest features of C# 3.0 is one of the most subtle: automatic properties.  It's really nothing more than syntactical sugar and saves us a little bit of typing, but it's been a big help in making my code more self-documenting.  If you're unfamiliar with automatic properties, here is what one looks like:

public Int32 Id { get; set; }

When that single line is compiled and viewed in Reflector, you get the following:

[CompilerGenerated]
private int <Id>k__BackingField;

public int Id
{
    [CompilerGenerated]
    get
    {
        return this.<Id>k__BackingField;
    }
    [CompilerGenerated]
    set
    {
        this.<Id>k__BackingField = value;
    }
}

The new syntax is equivalent to a classic C# property.  Note that this property has a get accessor and a set accessor.  This is the only type of automatic property you will be able to create.  You need the full {get; set; } for the automatic property to compile.  { get; } or { set; } won't cut it.  If you need a property with only a get or set accessor, then you need to use a classic C# property.  However, you can use { get; private set; } for a read-only property.  It will create both accessors, but only the get accessor will be public.  Also keep in mind that the Visual Studio 2008 code-snippet shortcut "prop" now creates an automatic property and "propg" creates an automatic property with a private set accessor.

Since this feature helps so greatly in the readability of the code, I have added a new feature to XAG: minimized properties.  Here is what the classical C# 2.0 syntax would look like for simple DTO (data transfer object) using XAG:

<Assembly xmlns:x="http://www.jampadtechnology.com/xag/2006/11/">
    <SimpleType x:Key="ClassKey" Type="Class" AutoGenerateConstructorsByProperties="True" Namespace="ClassNamespace"  AccessModifier="Public">
        <Properties AccessModifier="Public">
            <Id Type="Int32" />
            <Name Type="String" />
            <Title Type="String" />
        </Properties>
    </SimpleType>
</Assembly>

Using XAG's express type creation, the XML compiles to the following C# code:

using System;

namespace ClassNamespace
{
    public class SimpleType
    {
        private Int32 id;
        private String name;
        private String title;
        public Int32 Id {
            get { return id; }
            set { id = value; }
        }

        public String Name {
            get { return name; }
            set { name = value; }
        }

        public String Title {
            get { return title; }
            set { title = value; }
        }

        public SimpleType(Int32 id, String name, String title) {
            this.Id = id;
            this.Name = name;
            this.Title = title;
        }

        public SimpleType( ) {
        }
    }
}

That's painfully verbose when compared with automatic properties.  The new feature in XAG allows you to choose between a classic property and a minimized property (an automatic property in C# 3.0).  Below is the same XAG DTO done with Minimized properties.  In this example, notice that AutoGenerateConstructorsByProperties is set to false (the default).  This is because C# 3.0 has feature called object initializers, which allow you to set properties when you instantiate an object without needing any special constructor.

<Assembly xmlns:x="http://www.jampadtechnology.com/xag/2006/11/">
  <SimpleType x:Key="ClassKey" Type="Class" Namespace="ClassNamespace" AccessModifier="Public">
    <Properties AccessModifier="Public" Minimized="True">
      <Id Type="Int32" />
      <Name Type="String" />
      <Title Type="String" />
    </Properties>
  </SimpleType>
</Assembly>

By simply setting Minimized to true (and optionally, AutoGenerateConstructorsByProperties to false), you get the following C# 3.0 code:

using System;

namespace ClassNamespace
{
    public class SimpleType
    {
        public Int32 Id { get; set; }
        public String Name { get; set; }
        public String Title { get; set; }

        public SimpleType( ) {
        }
    }
}

You can also use this new minimize option with the existing options Static (a Boolean) and Mode (Blank, "GetOnly", or "SetOnly"), but you obviously can't use it with the Backing option.   The Backing option has a default value of true which means that the property is backed by a private field.  There is no such thing as an automatic property with an explicit backing field; that's the entire point of an automatic property.  The following example demonstrates a few legal combinations for properties in XAG.  Notice that you can tell XAG that you want all but a few specified properties to be minimized.

<Assembly xmlns:x="http://www.jampadtechnology.com/xag/2006/11/">
    <SimpleType x:Key="ClassKey" Type="Class" Namespace="ClassNamespace"  AccessModifier="Public">
        <Properties AccessModifier="Public" Minimized="True">
            <Id Type="Int32" />
            <Name Type="String" Static="true" Mode="GetOnly" />
            <Title Type="String" Minimized="False" Backing="False" Mode="GetOnly" />
        </Properties>
    </SimpleType>
</Assembly>

This XML code compiles to the following C# 3.0 class:

using System;

namespace ClassNamespace
{
    public class SimpleType
    {
        public Int32 Id { get; set; }

        public static String Name { get; private set; }

        public String Title {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        public SimpleType( ) {
        }
    }
}

In C# 3.0, you could use that code with an object initializer like this:

SimpleType st = new SimpleType( )
{
    Id = 8
};

Int32 id = st.Id; // id == 8

You can find more information about my XML Assembly Compiler at http://www.jampadtechnology.com/xag/.

Related Links

The ECMA-334 Standard

Let me state publicly for the record: I do not approve of books for learning C#. The only guide you will ever need is the ECMA-334 standard. It's a readable guide to the entire C# language that covers every facet of the language. This document is the definitive guide for C#. In fact, there is no document on MSDN that even comes close to the comprehensive native of C# than does the ECMA-334 standard as the ECMA-334 standard *is* C#.

Why do I mention this at all? Because, from time to time I get people asking me what book he or she should *buy* to learn C# and I always tell them what I've just stated above. Unlike Visual Basic, C# is NOT Microsoft's baby. They may have been the ones who gave birth to C# and continue feed it and nurture it, but it's a standard -- not Microsoft's baby.

Lastly, while you are getting the ECMA-334 standard, check out the ECMA-335 standard. This one is the standard for the CLI (Common Language Infrastructure -- which Microsoft implements as the CLR or Common Language Runtime). It goes into detail about the IL (Intermediate Language), the Common Language Specification (CLS), the Common Type System, and talks in some detail about various .NET concepts. I would consider this standard to be more advanced than what most people need at first, so I don't recommend this for initial learning (for that get Duffy's Professional .NET Framework 2.0 [0764571354] and then Richter's CLR via C# [0735621632]).

As a footnote, you could also check out the ECMA-262 standard (ECMAScript, that is, JavaScript), but it's not nearly as well written as the ECMA-334 and ECMA-335 standards and because of that I've never recommended it's reading to anyone.

C# 3.0 Features at MSDN Nuggets

The MSDN Nuggets website has just released a TON of awesome videos about new C# 3.0 features. Personally I love the stuff they are doing with the LINQ project. It's going to make the awesome C# 2.0 language even more powerful and flexible.

The site also released a cool video about how to get Vista's glass to work in your apps. By the way, if you're interested in the workflow foundation, there are a ton of videos on that as well.

Here are the videos...

C# 2.0 Self-Test

In the .NET course I'm teaching (".NET Complete") I gave a little project to the class, of which all of them are new to OO design, C#, .NET, and all the related items. The project requirement was for them to study the example and see what it does. The point of the project was to allow them to test their knowledge of C# syntax, collections, generics, and nullable types

It's almost as useless as "Hello World". Or,rather, hello world is almost as useless as this.

You simply type in string and it tokenized it into characters...but they didn't know that.  Anyhow here you go...

using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;

namespace CodeExamples
{
    class Program
    {
        class Storage<T> where T : ICollection<Char>, new( )
        {
            private Dictionary<String, T> list = new Dictionary<String, T>( );

            public void ShowLines( ){
                Int32? i;
                foreach(KeyValuePair<String, T> collection in list) {
                    i = null;
                    if(collection.Key.Length > 2) {
                        i = collection.Key.Length;
                    }

                    Console.Write((i ?? -1) + " : " + collection.Key + " : ");
                    foreach(Char thing in collection.Value) {
                        Console.Write(thing);
                    }


                    Console.WriteLine();
                }
            }

            public void Save(String text) {
                T parts = new T( );
                foreach(Char c in text.ToCharArray( )) {
                    parts.Add(c);
                }

                if(!list.ContainsKey(text)) {
                    list.Add(text, parts);
                }
            }
        }

        static void Main(String[] args) {
            Storage<Collection<Char>> storage = new Storage<Collection<Char>>( );

            Boolean done = false;

            while(!done) {
                String text = Console.ReadLine( );

                if(text == "end") {
                    done = true;
                    continue;
                }

                storage.Save(text);
            }

            storage.ShowLines( );
            Console.ReadLine( );
        }
    }
}
1 2

Powered by
Python / Django / Elasticsearch / Azure / Nginx / CentOS 7

Mini-icons are part of the Silk Icons set of icons at famfamfam.com