﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ayende Rahien commented on Embracing fluent interfaces</title><description>I am saying that too much logic in the template is wrong, yes.
  
You should have loops, a few ifs, but not much more.
  
If you do have nested ifs or complex logic, it is time to extract it, and yes, it is entirely possible.
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment15</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment15</guid><pubDate>Sat, 03 Nov 2007 19:47:50 GMT</pubDate></item><item><title>Mats Helander commented on Embracing fluent interfaces</title><description>"In fact, it this is how your HTML template looks like, this is not readable, and you need to rethink how you are doing it"
  
  
Interesting! I must admit that's pretty much how all the examples I've seen of RoR, MonoRail etc have come across...but you're saying proper modularization gets rid of stuff like that? Completely? 
  
  
But are you in effect saying that someone using templates that look like that ^^ is doing it (RoR, MR) wrong? I may be totally off here, but I kinda think that's news...?
  
  
/Mats
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment14</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment14</guid><pubDate>Sat, 03 Nov 2007 19:30:03 GMT</pubDate></item><item><title>Ayende Rahien commented on Embracing fluent interfaces</title><description>Mats,
  
Take a look at Brail's, it has a DSL for building HTML, as a matter of fact.
  
In this case, it depends on what you are trying to do.
  
Most cases, it is not just string generation.
  
You can generate a sql statement with a template language:
  
  
select * from Customers
  
&lt;% if has_conditions: %&gt;
  
where
  
&lt;%  if first_name_starts_with:
  
 need_and = true
  
%&gt;
  
firstname like @first_name_starts_with+ '%'
  
&lt;% end %&gt;
  
&lt;% if last_name_starts_with: %&gt;
  
&lt;% if need_and: %&gt;
  
 and
  
&lt;% end %&gt;
  
lastname like @last_name_starts_with + '%'
  
&lt;% end %&gt;
  
&lt;% end %&gt;
  
  
  
This is not readable. In fact, it this is how your HTML template looks like, this is not readable, and you need to rethink how you are doing it.
  
But frankly, most of the time the HTML contains _very_ simple logic, rarely inter-related and rarely nested.
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment13</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment13</guid><pubDate>Sat, 03 Nov 2007 16:22:31 GMT</pubDate></item><item><title>Mats Helander commented on Embracing fluent interfaces</title><description>So, basically you're saying that you wouldn't want to do string concat, but would rather use a DOM (which underlies the fluent interface)....but the same argument, I take it, still doesn't apply to building html? ;-)
  
  
/Mats
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment12</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment12</guid><pubDate>Sat, 03 Nov 2007 16:16:39 GMT</pubDate></item><item><title>Hongtao commented on Embracing fluent interfaces</title><description>Total agree with the second example, and that's why I still don't use the LINQ now.
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment11</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment11</guid><pubDate>Fri, 02 Nov 2007 06:25:23 GMT</pubDate></item><item><title>Jeff Brown commented on Embracing fluent interfaces</title><description>I'm happy as long as the goal of the interface is to be composable not just verbose.
  
  
The objectives of fluent interfaces are a bit muddy.  They can introduce a higher level of abstraction along the lines of the Builder design pattern.  However part of it is about introducing extra static type information and extra noise words for the sake of Intellisense support or RAD.
  
  
There are many ways to accomplish the latter objective.  Unfortunately we're a bit constrained by the languages and the tools here.
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment10</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment10</guid><pubDate>Fri, 02 Nov 2007 01:44:16 GMT</pubDate></item><item><title>Lee commented on Embracing fluent interfaces</title><description>I couldn't disagree with jeff more. There is a fundamental concept that he is missing..... programming language are for humans, not computers (sort of speak). Otherwise we would be writing code in the equivalent to punch cards. 
  
  
1. Fluent interfaces offer increase speed, if programmers could type faster without using intellsense then it wouldn't exist in almost every single modern IDE. 
  
2. Fluent interfaces are a higher level form of abstraction, in a sense that's exactly why programming language were invented. 
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment9</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment9</guid><pubDate>Thu, 01 Nov 2007 16:00:03 GMT</pubDate></item><item><title>Luke Breuer commented on Embracing fluent interfaces</title><description>Your regex comparison isn't fair: split that regex onto multiple lines and use RegexOptions.IgnorePatternWhitespace.  You do bring up a very interesting point, as my usual impulse is to go with compiler-checkable syntax.   In the regex situation, I would prefer a multi-line, properly-indented, literal regex with IgnorePatternWhitespace.  The regex fluent interface you've provided is ridiculously wordy compared to a regex.  I've never really had to dynamically build regexes like I've had to do with SQL, so I'm probably unduly biased.
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment8</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment8</guid><pubDate>Wed, 31 Oct 2007 17:44:23 GMT</pubDate></item><item><title>Ayende Rahien commented on Embracing fluent interfaces</title><description>Andy,
  
Take a look at NHQG, I did some serious work there to that end.
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment7</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment7</guid><pubDate>Wed, 31 Oct 2007 17:04:21 GMT</pubDate></item><item><title>Ayende Rahien commented on Embracing fluent interfaces</title><description>James,
  
That depends on the implementation, but I don't think that regex's structured are exposed externally, so it probably build the string.
  
Then again, this is the perfect place to put best practices into place.
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment6</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment6</guid><pubDate>Wed, 31 Oct 2007 17:02:58 GMT</pubDate></item><item><title>Stuart Carnie commented on Embracing fluent interfaces</title><description>Ayende,
  
  
I would have to agree with you.  I have been experimenting with a fluent interface myself for our CRM platform.  I have found that it is far easier to read, and IMHO maintain (as a side effect of improved readability).
  
  
I also believe the learning curve is much simpler, due to using a syntax which includes operator overloads to allow:
  
  
Where(Contact.Columns.Age &gt; 18 &amp;&amp; Contact.Columns.Age &lt; 35 || Contact.Columns.Name.StartsWith("C"))
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment5</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment5</guid><pubDate>Wed, 31 Oct 2007 16:39:13 GMT</pubDate></item><item><title>Andrey Shchekin commented on Embracing fluent interfaces</title><description>I think query in straightforward fluent interface can be as easy to read as the
  
generated SQL:
  
Prepare
  
    .SelectAll()
  
    .From&lt;Tables.Customer&gt;()
  
    .Where(Tables.Customer.Country == "USA")
  
    .OrderBy(Tables.Customer.CompanyName).Ascending;
  
  
But now I can do 
  
Prepare
  
    .SelectAll()
  
    .From&lt;Tables.Customer&gt;()
  
    .Where(Tables.Customer.Country == "USA")
  
    .OrderBy(Tables.Customer.CompanyName).Ascending
  
    .Skip(5)
  
    .Take(10);
  
and get a magic paging CTE under SQL Server and degradable behavior under other engines.
  
  
Also Tables.Customer.Country == "USA" can be typesafe if Tables.Customer.Country is a QueryField&lt;string&gt;.
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment4</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment4</guid><pubDate>Wed, 31 Oct 2007 16:06:03 GMT</pubDate></item><item><title>James Curran commented on Embracing fluent interfaces</title><description>In the Regex example, is the result of the Fluent interface the string given in the first half?  Or is it the Regex's internal structure?  If the latter, then there could also be significant runtime savings as well.
  
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment3</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment3</guid><pubDate>Wed, 31 Oct 2007 15:36:06 GMT</pubDate></item><item><title>Tim Scott commented on Embracing fluent interfaces</title><description>Besides readability, there is a big benefit of your fluent examples that you didn't mention.  I have written a lot of complex searches like the one you mention using string concat to build SQL or HQL statements.  I would like to think that I have done it cleverly, making the code reasonably understandable.  Nonetheless, future developers must always take extra time when changing these methods...for one simple reason. The compiler is quite happy if put logic errors into string literals.  What's it worth to catch errors at compile time versus runtime?
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment2</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment2</guid><pubDate>Wed, 31 Oct 2007 15:10:27 GMT</pubDate></item><item><title>Dave Newman commented on Embracing fluent interfaces</title><description>Absolutely.  Works fine for the simple scenarios, but I was on a project last year where the developers had vomited SQL all through the app, through every "layer".  Trying to follow all the if/then logic to build an enormous SQL string to execute and identify injection problems was _not_ fun!    
  
  
This is for anyone writing code I may have to look at one day:  If you're going to use SQL strings in your app people PLEASE wrap them in some kind of DAL class(s) so they're all in one place!
</description><link>http://ayende.com/2923/embracing-fluent-interfaces#comment1</link><guid>http://ayende.com/2923/embracing-fluent-interfaces#comment1</guid><pubDate>Wed, 31 Oct 2007 08:06:42 GMT</pubDate></item></channel></rss>