Talk:Fluent interface

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computer science (Rated Stub-class)
WikiProject icon This article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Stub-Class article Stub  This article has been rated as Stub-Class on the project's quality scale.
 ???  This article has not yet received a rating on the project's importance scale.

Not a Monad[edit]

Bind is not the equivalent of a map operation, which is what is needed for method chaining. This is a misunderstanding of monads, and should be removed. — Preceding unsigned comment added by (talk) 22:26, 12 February 2015 (UTC)

Minor Problem with the Java sample code[edit]

With the font being used and the use of the variable name "l", it requires some thought to see that "l" is not "1" in pack( l ).

I tried changing "l" to "label" but that made the alignment of the grid method invocations look ... a bit ... ugly.

So I thought I'd just mention my problem with the "l" here. — Preceding unsigned comment added by (talk) 19:44, 20 January 2014 (UTC)

Problem with the C# sample code[edit]


1) I tried the C# sample code, but the compiler alerted 12 syntax errors. Please give a sample with runnable code.

2) The "fluent-interface-benefit" (short intuitive code) is not demonstrated very convincing. I would prefer to see something like:

IConfiguration config = ConfigurationFluent.Create().Color("blue").Height(1).Length(2).Depth(3);


IConfiguration config = ConfigurationFluent.CreateColored("blue").Height(1).Length(2).Depth(3);

(Create() or CreateColored() would be static methods, returning a new instance as an "entry-Point" into the fluent interface.

That is no really good Sample too, because C# 2008 provides the with-Keyword, so one could instantiate without fluent interface as well:

var config = new Configuration() with { Color = "blue", Height = 1, Length = 2, Depth = 3 };

3) A better sample would result in stuff like:

// List<SpecialItem> _SpecialItems = new List<SpecialItem>();

That would demonstrate, how fluent interface reduce nesting. Compare to:

// List<SpecialItem> _SpecialItems = new List<SpecialItem>();
_SpecialItems.Add(new SpecialItem() with { Color = "blue", Height = 1, Length = 2, Depth = 3 });

Unfortunately the benefit "help from Intellisense" (a fluent interface supports fluent writing code) cannot be shown in an article, or would you like to add screenshots?

ErfinderDesRades (talk) 11:11, 15 December 2008 (UTC)

IMO the published sample is garbage. Chaining in itself does not make for readability and the ALT.NET community is severely abusing mere chaining with this misunderstanding. There's nothing less readable about




In my opinion, this actually makes it less readable because these are distinct statements that are being slurred together.

I agree that the samples from ErfinderDesRades are better. Jon (talk) 09:52, 30 September 2009 (UTC)

PHP sample[edit]

In the PHP sample, what is this part good for?

	error_reporting(E_ALL | E_USER_NOTICE);
	require_once 'classes/Loader.php';
	require_once 'config.php';


Shouldn't a reference to monad be included somewhere in this article? Dave Sexton (talk) 08:43, 26 July 2010 (UTC)

Fluent Interface vs Method Chains[edit]

The article correctly states that a fluent interface entails more than just method chaining but then goes on to to show examples that solely use Method Chaining. This is misleading. The article and the examples could be improved to reflect a Fluent Interface' role in creating internal DSLs. This would make the distinction more clear. —Preceding unsigned comment added by (talk) 08:46, 22 September 2010 (UTC)

Same comment from my side. The C++ example in fact does implement a fluent interface, but not so the other examples. One correct example is much more worth than a dozen of examples whereof only one really illustrates the point. Since nothing happened since this comment from 2010 I am going to remove the other examples. --Chiccodoro (talk) 11:15, 7 September 2012 (UTC)
The C++ example is also unnecessarily verbose. What about just deleting them all and adding a concise example in pseudo-code? As soon as you use a real language, people start getting all fanboyish and feel compelled to add their favorite one to the mix. — Preceding unsigned comment added by (talk) 03:15, 18 December 2014 (UTC)


Is JQuery considered a fluent interface? If so, it should be referenced in this article.

Also, I'd like to echo the above topic's concern. This article doesn't make clear what the requirements for fluent interfaces are, beyond method chaining. —Preceding unsigned comment added by (talk) 22:11, 27 October 2010 (UTC)

jQuery (note capitalization) definitely at least uses method chaining[1]. When you start with a selection of elements — e.g., $("li") to select all list items in the page — then most chained functions do indeed return the same collection (or perhaps a reduced/expanded collection) for further operations. Honestly, the Martin Fowler piece cited in the main article isn't terribly clear on what would be required to call something a "Fluent interface" either, though it does cite JMock as an example. Dave Brown (talk) 01:11, 8 April 2013 (UTC)

The non-existence of C# 3.5[edit]

Regarding "With C# 3.5 and later there are more advanced method chaining techniques".

I don't think C# 3.5 exist; there is C# 3.0 and .NET Framework 3.5. Do you agree? --Mortense (talk) 03:09, 17 November 2010 (UTC)

Single-statement nature and debugging[edit]

Issues raised in this comment were addressed, please see the 'Problems' section.

The article should elaborate on the problematic side of fluent style, which is debugging: fluent chains constitute a single statement or expression, which can be problematic when debugging, compared to more classic styles.

Typically, for many languages you are not able set breakpoints within a chain, and stepping will often be problematic.

There is also an issue with crash stack reports, in which a fluent chain will be treated as a single statement when the debug information is limited to statements (which for many languages is the case). That can make identifying which method call triggered an issue ambiguous if the same method is present more than once in a chain. —Preceding unsigned comment added by (talk) 20:58, 7 January 2011 (UTC)

Problems > Subclasses[edit]

In Java, Generics are used to enable subclassing without the subclasses having to implement all parent methods just to change the return type. JATL is a good example how it is done. — Preceding unsigned comment added by (talk) 19:17, 25 December 2012 (UTC)


Isn't this kind of style similar to a Monad? Should be linked in the text? — Preceding unsigned comment added by Sukima (talkcontribs) 22:29, 21 May 2014 (UTC)

Re monads - this is a Javascript and purescript comparison showing this is just monads. Here is the commentary: — Preceding unsigned comment added by (talk) 04:36, 19 July 2014 (UTC)

Example Farm[edit]

This is yet another computer science article that has turned into a large body of inconsistent and completely unecessary examples. The JavaScript section is (as usual) particularly egregious. A single pseudo-code example would more than suffice. — Preceding unsigned comment added by (talk) 03:11, 18 December 2014 (UTC)