2

I've been noticing that modern frameworks tend to have this kind of code style:

expect(6 - 4).toBe(2)

this can be rephrased as: assert(6-4, 2)

Yet the former is much more readable.

I would like to read more about this "style" of coding, but I have no idea what to search for. Does this convention have a name?

Thanks.

Jonny
  • 131
  • 3
  • 5
    That's often called a "fluent" style. – Mike Partridge Jun 19 '15 at 12:04
  • :) thanks. If you put it as an answer, I can mark it as the correct one. – Jonny Jun 19 '15 at 12:06
  • 1
    related: [Coding style for chained function calls](http://programmers.stackexchange.com/q/210221/31260) and [What is the pattern name for using method chaining to build an object?](http://programmers.stackexchange.com/q/137999/31260) – gnat Jun 19 '15 at 20:44

1 Answers1

3

It's called a fluent interface.

Some people may call it more expressive, but "more expressive" means that you couldn't 1:1 replace it with another language's statements, which you do in your second example. So, the first example is not more expressive, but it is certainly more fluent.

Rosa
  • 445
  • 3
  • 12