Naming is important

Just stumbled over a “bug” in .NET 4.0 DataAnnotations/Validator that was quite easy to “work around”, but still took us a while to figure out.

We want to do simple structural server-side validations.

Data Annotations

/* haven’t installed my Live Writer beautifier-plugin yet */

public class SomeCommand : Command {

    [Required] public string Name { get; set; }

    [Required] public sting City { get; set; }

    [Range(0,99)] public string Age { get; set; }

}

The base class uses System.ComponentModel.DataAnnotations.Validator to run the validations in this simple Method:

private IEnumerable<ValidationResult> AutoValidation()
{
    var results = new List<ValidationResult>();
    Validator.TryValidateObject(this, new ValidationContext(this, null, null), results);
    return results;
}

Problem

It only validated the fields marked as required. The RangeAttribute was ignored.

After a while we had a look at the .NET-Framework-Sources using Reflector, and found this:

if (validateAllProperties)
{
    source.AddRange(GetValidationErrors(pair.Value, pair.Key, propertyValidationAttributes, breakOnFirstError));
}
else
{
    RequiredAttribute validationAttribute = propertyValidationAttributes.FirstOrDefault<ValidationAttribute>(delegate (ValidationAttribute a) {
        return (a is RequiredAttribute);
    }) as RequiredAttribute;
    if (validationAttribute != null)
   {
       // validate the RequiredAttribute

validateAllProperties in this case means: do not only run Required-Validations.

Solution

Actually a different override of Validator.TryValidateObject has a flag named validateAllProperties. But since it did already validate more than one property, I assumed true was the default.

Lesson I learned: do not assume anything!

Lesson for MS: Take time finding the right name! Do refactor!

I filed a bug here: https://connect.microsoft.com/VisualStudio/feedback/details/605635/missleading-parametername-validateallproperties-in-validator-try-validate-componentemodel-dataannotations

Advertisement

Oslo, Quadrant and the Repository is dead, long live “M”?

What the community (me included) has hoped and feared at the same time and what many foresaw, happened: Microsoft discontinued it’s investment in SQL Modeling Services (aka “Oslo” Repository) as well as “Quadrant”, as Don Box states on the Model Citizen Blog.

One important aspect of that focus is that we will not bring “Oslo” repository to market.

The Winners on the data-side of things are OData and the Entity Framework including EDM.

Given the increasing adoption of both OData and EDM, we have decided to focus our investments in those technologies to make our modeling vision a reality.

But Don also states, that Micrsosoft will further invest in the modeling language codenamed “M”, which also was a former part of Oslo, but clearly didn’t fit into the “SQL” rebranding right from the beginning.

While we used “M” to build the “Oslo” repository and “Quadrant,” there has been significant interest both inside and outside of Microsoft in using “M” for other applications. We are continuing our investment in this technology and will share our plans for productization once they are concrete.

I think, all together this is good news. Both the Repository and Quadrant were very far away from what I consider useful.

Hopefully the “M” team moves over to DevDiv into the ScottGu-Area. Hopefully it then returns to collaborative language design, now that the internal goals are removed.  Hopefully, Microsoft also now listens’ to the modeling community when designing the final language. And hopefully they bring great Visual Studio Support for textual DSLs.

Hey Microsoft, what about open sourcing “M”? This would be a huge step forward, after this very huge step backwards!

Microsoft Encourages Bad Software Quality

This post is not about bad documentation and samples. Much simpler. It’s about the Visual Studio license model.

You can’t tell me Microsoft really earns any real money with development tools. We’ve heard that before. Microsoft is all about Windows, Office and SQL Server. The rest is ecosystem.

Professional for hobbyists

But to come to the point. The Visual Studio License Model makes Software Quality Hard. The problem is, that the most common Professional Edition has major restrictions. It is not worth being called “Professional” version.

A Professional Software Engineer should be able to:

  • To analyze the code he writes
  • To run test coverage and find code impacted by tests
  • To do UI testing
  • To do web testing
  • To do performance testing
  • To explore the architecture of the project he is working on

Agree? Then why is all of this not available in an edition called “Professional”? And if you get the Professional without MSDN Subscription, it is even worse.

The Price Problem

Then just go buy the “Premium” or “Ultimate”, right?

Hm. Who decides this again? The developer? In most cases, sadly enough, the manager. But we also know managers have hard times buying tools. Especially in big enterprises.

Well you don’t buy VS on Amazon – so the prices vary a lot. On this online list two years of VS Professional cost around €1000, the Premium is available for about €7000 and the Ultimate costs €16000.

Now what happens if you try to order an Ultimate? Your manager will ask if Ultimate is a 16x productivity gain, right?

Managers (at least too many of them) are interested in quality as long as they get it for free. Quality Software is already expensive enough. Why do you make it so hard, my dear Tools Devision?

Good Medicine is bad for Doctors

Oh, I forgot: Bad quality software means somebody has to fix it for money. Slow software means more hardware and hence more sold licenses.

I have more to say. But I think I said enough.