I have read about Fluent APIs, where code can be made to read like English, but I can't seem to find any examples of them, as I would like to find out whether they are a reasonable way to make an easy to use interface to a system by non full time programmers. Does anyone have any examples of a fluent interface?
Couple of examples below in C#. Used by non-programmers? Well, decide for yourself, I'd say probably not - they're designed for coders and you need to know the syntax. But then this is C#, there are better examples in Ruby and other languages with much more readable, english-like syntax.
You'd might want to also look at external DSLs (domain specific languages). (Fluent APIs are considered internal DSLs).
NUnit:
Assert.That(result, Is.EqualTo(10));
Ninject:
Bind<IDataAccess>()
.To<Db4oDataAccess>()
.WithConstructorArgument("fileName", "dbFile.db");
Rhino Mocks:
repository.Expect(x => x.LoadUserList()).Return(users);
Here's some Ruby from RSpec:
@account.balance.should eql(Money.new(0, :dollars))
However, bear in mind that these examples are aimed at programmers, it is possible to get much more human-readable code if non-programmers are the target audience, especially with Ruby and the like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With