2 ms·
Fluent interfaces are cool, but they throw away the semantics of the programming language like meaningful return values. The DSL in the article is a good examp
by jeswin 16y ago
Fluent interfaces are cool, but they throw away the semantics of the programming language like meaningful return values.
The DSL in the article is a good example of this problem:
OrderId.StartsWith("a2d")......
So the StartsWith() returns a TransactionSearch, instead of a bool as you would expect. Once you do this often enough, you really get objects full of state-information, rather than methods with return values.
An alternative to doing this is using Expression Trees, but somewhat harder (and not without faults)
It would look like this:
search.Where(s => s.Order.Id.StartsWith('a2d') &&
s.Customer.Website.EndsWith('.com') && ...)
Two benefits come to mind:
1. StartsWith() can return a bool as you would expect.
2. You can use StartsWith() on strings, like OrderId
--- I am not sure how you pulled this off in the DSL example (is OrderId a custom type, since you can't use Extension methods there?)
The biggest drawback of course is:
1. Harder - You will need to parse the Expression Tree.
- mquander 16y agoI replied to say as much but then I tossed my reply, because the guy says he's on .NET 2.0.