Composite WPF and the Ribbon Control

While working for WPF and Composite Application Library (CAL) for the first time, I had some difficulty both understanding their concepts and apply them in the optimal way, but I tried harder.

One of the benefits of CAL I found was the Command Binding which truly facilitates complying to the Model-View-ViewModel UI Design Architecture. But finding an easy implementation for them in all the desired control was not as easy as with default menu items and tool bars. A question on stackoverflow was asking about implementing the Command Binding with the WPF Ribbon which is downloadable within the WPF Futures, and not included in the out-of-box visual studio installation.

The trick was to make custom region adapters as those of menu and tool bar. I have found samples of  RibbonRegionAdapter.

To comply with CAL and Model-View-ViewModel,  the View containing the Ribbon will be be bound to a ViewModel containing all commands. These commands would be exposed publicly and available to other modules to attach Executed and CanExecute handlers. It is possible also to expose a generic method to add commands at run time by providing their image and location on the ribbon.

I found also open source implementation for binding the docking manager. The Composite WPF Contrib Project on CodePlex contains a TabGroupPaneRegionAdapter for Infragistics TabGroupPane.

StyleCop for ReSharper has been released

StyleCop for ReSharper has been released last week as a plugin for ReSharper to bring StyleCop code styling issues to ReSharper real-time syntax highlighting, quick-fixes, and Code CleanUp.

Although I personally don’t like many of StyleCop rules, but like ReSharper rules, they can be turned off individually. The plugin performance can also be customized from within the ReSharper options window.

More about StyleCop:

Microsoft StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. It is another static analysis tool by Microsoft like FxCop, but the later analyzes the compiled object code for design issues, not the source code.

More about ReSharper:

ReSharper is a Visual Studio add-in created by JetBrains (the creator of many software productivity tools like IntelliJ®IDEA the Java IDE, TeamCity™ the build integration server, and dotTrace Profiler)

I have been using ReSharper almost since I started using Visual Studio and it has always been a complement to it. Even when Visual Studio evolved from 2003 to 2005, and finally 2008, ReSharper has still much to add.

One of the features I like most in ReSharper is its ability to detect syntax and styling error while you type, refactor code quickly, suggest variable names based on classnames, highlight redundant code, make code more readible, find references and jump to it directly if only once.

There has been some talks that Visual Studio 2010 is actually 2008 + ReSharper because of a mistake they made when they posted some snapshots of Visual Studio 2010 with ReSharper menus and screens in it.

Microsoft on the other hand had been promoting one of ReSharper competitors and announced a cooperation with DevExpress to license a free version of CodeRush Express exculsively for C# developers working on Visual Studio.

kick it on

//Comments about comments

Although they are usually enforced by coding standards, and I strongly agree, I believe code comments should be minimized for many reasons:

  • Except for XML comments of methods and classes, most comments are not affected by automatic refactoring tools
  • Most developers forget to update comments after updating code
  • Sometimes they mix with temporarily commented code
  • Every one adds one or more additional lines to the source code
  • They might make the code ugly
  • They implicitly admit that your code cannot express your ideas
  • They cannot be validated by type checking or unit testing
  • Most of the times, there are more better alternatives than comments

Yet I believe they are highly needed in these cases

  • Writing important messages to self or others
  • Writing code review comments
  • Writing //TODO tasks for self or others
  • Writing failed trials to avoid reusing them later while refactoring
  • Writing justification for code that might not appear logical at first look

And finally here are some cases when comments can be replaced by better alternatives

if (i >= 5) // number of orders
if (numOrders >= 5) // <-- better option: use meaningful var names
if (custType == 5) // credit customer
if (custType == CustomerTypes.Credit) // <-- better option: use enums

if (custCredit >= 30) // credit over 30%
if (OverCredit()) // <-- better option: use methods (or properties)

private bool OverCredit()
    return custCredit >= 30;
if (a == b)
    if (d == c)
        // ... long lines of code ...
    } // if (d == c)
} // if (a == b)

// Most decent IDEs highlight matching braces when u select one of them
// Also long lines of codes should be avoided, use methods
// begin saving data
    // ... long lines of code ...
// end saving data

#region Saving data               // <-- better option: use regions
    // ... long lines of code ...

SaveData()          // <—- another better option: extract as method
// Modified by modeeb @ Feb 6, 2009 02:32:12 PM
// better option: use a version control system that have "blame" or "annotate" functionality

Delphi is back!

I have started my first years of Windows Development using Delphi (which I call Visual Object Pascal) and I used it for quite few years and within 3 companies before I move to C#.

“Delfee” as pronounced in Greek or “Delf-eye” as pronounced in English was the place of the Oracle in the Greek mythology. That’s why Danny Thrope (Chief Scientist) chose the name to reference it as a language to communicate with the database (Oracle at that time), hence; “If you want to talk to Oracle, go to Delphi”

It is funny to know that Danny left Borland to Google and later to Microsoft, as well as Chuck Jazdzewski (Chief Scientist and Architect), and Anders Hejlsberg (Chief Architect) who moved to Microsoft to be the Lead Architect of the C# team.

The most stable versions of it were 5 and 7 (2002) while other versions did not get much acceptance, specially after the transition to .NET and removing Win32 support. Last I heard about Delphi was that it was going to be sold.

Last week, I found an announcement and I knew the rest of the story. Borland did not get an appropriate offer, so they split the Developer Tools Group into a self-managed company called CodeGear which continued to release Delphi targeting Win32 Development after the inability to compete with C# in .NET development.

Earlier this year, Borland sold CodeGear to Embarcadero Technologies and the later decided to issue two parallel releases, one for Win32 and one for .NET based on Microsoft Visual Studio Shell.

Delphi Prism for .NET is going to compete on the area of cross-platform development as it is going to target development on .NET as well as other non Microsoft operating systems.

Dynamic Typing

In my last post, I talked about Duck Typing and I said it is one of the principle of Dynamic Typing, but don’t have to be in a dynamically typed language.

In order to discuss Dynamic Typing, we need to go thorough other typing systems and know the differences between them

Implicit Typing (or Type Inference) [C# 3.0 and later]:

It is one of the forms of Latent Typing as well as Duck Typing and Dynamic Typing. Let’s see this example

var test = 5; // test is an integer

Here, you don’t have to specify the type as the Compiler can infer from the statement that the variable will hold an integer. That’s why it cannot be used if declaration and assignment are not on the same statement…

var test; // Compilation error
test = 5;

Implicit typing is used mainly when the developer wants to use the result of a function, or an expression (as in LINQ) without the need to specify its type, as the compiler already knows the type. Also, if Explicit casting is used, there is no need for explicit typing…

var test = (int) cmd.ExecuteScalar();

Dynamic Typing [Ruby, Python, and C# 4.0]

It is another form of Latent Typing, but unlike Implicit typing, type is deduced at runtime, so, there is no type checking at compile time. The support for dynamic typing is introduced in C# 4.0 to support API calls into dynamic type languages, or the use of other non-typed data, like XML.

XElement element = XElement.Parse(@"
dynamic personXml = new DynamicXml(element);
personXml.FirstName = "Bob";

It is important to know that once a variable type is defined at runtime, it cannot be redefined later as another type. i.e. Dynamic Typing is not Weak Typing

Weak Typing (or Loose Typing) [Javascript, VB 6.0]

In javascript, this code is valid

var x = new Array(); // Any array
x[0] = "One"; // First element is a string, other elements can be any type
x[1] = "two";
x[2] = "three";
alert(x.length); // return 3
x = x.join(""); // Now x is a string not an Array
alert(x.length); // now return 11 (string length)

Weak typing is antonym to Strong Typing, while Dynamic Typing is antonym to Static Typing.

Here are some good related articles about typing systems by Bruce Eckel (author of Thinking in C++ and Thinking in Java):

Strong Typing vs. Strong Testing
About Latent Typing
How to Argue about Typing
I’m Over It

An insight on functional programming

It has been a long vacation, with quite some events to talk about

I had been following up the release of F# CTP which I haven’t got comprehensive knowledge yet, but to sum it up, it is a functional, declarative programming language.

In a functional language, each function should get some inputs, and return an output, with no other “side effect”; which means the internal implementation of the function doesn’t affect the state of the object or the state of any other related objects or global variables.

This is what differs functional languages from procedural or object oriented languages where a “method” can affect the instance fields or properties of the same object and/or other objects, can print something on a screen, or can persist something on other media. Each of these action doesn’t qualify a language as a functional language.

Some “pure functions” are mathematical functions such as “SUM()”, “AVG()”, “MAX()”, “MIN()” which typically get one or more input and return an output regardless of the context it is called from.

That decoupling from the context, make it easy to define “what” instead of “how” and hence it is a declarative programming language as well.

You can get a quick understanding of this language and the concepts of functional languages from this 20 minutes tutorial.

Visual Studio 2010 (Rosario)

Microsoft has provided the first look at its new development platform Visual Studio 2010 which is based on the new .NET Framework 4.0.

Microsoft described the next release through the following five focus areas:

  • riding the next-generation platform wave
  • inspiring developer delight
  • powering breakthrough departmental applications
  • enabling emerging trends such as cloud computing
  • democratizing application life-cycle management (ALM)

Their efforts in the area of ALM is the next step after their launch of Team Foundation Server (TFS) in 2005 and their efforts to combine Management, Analysis, Design, Testing, and Deployment all together under one platform.

The new announced features includes enhanced modeling with new diagram types such as use case, activity, and sequence beside the tightly close integration of modeling with existing and new code.

My favorite in the new features is the new testing capabilities which includes a stand-alone Test Runner that allows for running manual test, and at the same time take system snapshots with pertinent information and can be even used to take video captures of what was done during the test and report a bug to TFS directly with the captured data as an attachment.

Another favorite is the Test Impact View, which allows the developer to view the code changes made and the impacted tests that needs to re-run before checking in the latest modification.

For more info you can check the Visual Studio Team System 2010 Overview page.

A new free Programming Q & A Site

Hello, World!

I had just started my technical blog and here is my first post

Today I came across a nice and neat site for Q & A in programming (funny name, I thought)

So what’s new about it and why is it different from hundreds of other Q&A Sites?

Joel Spolsky, one of the site creators and CEO of Fog Creek Software, maker of FogBugz, a bug tracking software, comments on the reason why he and Jeff Atwood, author of Coding Horror blog, started this project:

If you’re very lucky, on the fourth page of the search results
[while searching for a programming answer to a question], if you have the patience, you find a seven-page discussion with hundreds of replies, of which 25% are spam advertisements posted by bots …

…. I thought that the programming community could do better by combining the idea of a Q&A site with voting and editing.

Like Wikipedia, every question should appear once on the site; readers and admins clean duplicates regularly.

Readers can “Vote” up or down for answers and the answer seeker can “Accept” a specific answer

Good answers grant you reputation “badges” as a reward

Since it is a collaborative work, it is totally free, no ads, no bots, no sales people