Try fast search NHibernate

13 February 2009

NHV.Loquacious : fluent-configuration for NHV

Loquacious is the name of the new fluent-configuration embedded in NHibernate.Validator.

public class AddressValidationDef: ValidationDef<Address>
{
public AddressValidationDef()
{
Define(x => x.Country)
.NotNullable().And
.MaxLength(5);
Define(x => x.Zip)
.MaxLength(5).WithMessage("{long}").And
.MatchWith("[0-9]+");
}
}

The thread about the API still open so, if you have some advise you can leave your opinion here or there.

One peculiar characteristic of NHibernate.Validator.Cfg.Loquacious is that was implemented avoiding XML generation; this mean that we are using NHV’s APIs to create all metadata needed by the ValidatorEngine.

I start this work only for fun and now I can make public my considerations about fluent-configuration.

IMO

“people use XML because they can’t use something else”: FALSE. I use XML because it is the more flexible and less intrusive than other “conf-ways”. A modern developer can’t avoid the knowledge of XML.

“fluent-configuration support Refactoring when XML don’t”: FALSE. Refactoring is not a matter of the language you are using to configure; the Refactoring is an IDE functionality (Eclipse users know this fact). The problem in .NET world is that, for us, is more easy the implementation of “fluent-configuration” than a VisualStudio/Resharper plug-in (check this or this for example).

“fluent-configuration is more readable”: Well… let me say that some fluent-configuration APIs are absolutely not more readable than XML.

“implements fluent-configuration is a big challenge”: basing the opinion in this experience I can say that is FALSE; it was a work of few hours (around a 5% or 6% than XML configuration).

Conclusions

That said, fluent-configuration is a useful tool but it is absolutely not indispensable to evaluate a framework usability.


kick it on DotNetKicks.com

4 comments:

  1. Refactoring is an process and not an IDE functionality or feature. IDE provides features for refactoring. And using fluent interfaces we easily can use build-in code refactoring features. Also we have working intellisense out of box.
    "Well… let me say that some fluent-configuration APIs are absolutely not more readable than XML." - and let me say that many XML configuration APIs are absolutely not more readable than fluent-ones. It's more easy for usual user to use good fluent configuration APIs than good XML ones due to intellisense, compile-time code validation, etc.
    "That said, fluent-configuration is a useful tool but it is absolutely not indispensable to evaluate a framework usability." - yes, but it's a good feature of framework. If I have 2 similar frameworks and only one of them will support fluent configuration I'll prefer to use framework it.

    ReplyDelete
  2. I think that I have some idea about what is Refactoring... BTW as you said is the IDE who "provides features for refactoring"; my point is that if you have a IDE's feature to apply Refactoring to an XML, the "refactoring" issue not exists. As you can see, Stefan Lieser, has a project to apply refactoring and "lexical-checker" to a NHibernate mapping XML file.

    ReplyDelete