4 ms·
If you think about it, that's just fluent API. And it's up to your to use it to design thing that's convenience and readable for you. When you design an API, yo
by kureikain 9y ago
If you think about it, that's just fluent API. And it's up to your to use it to design thing that's convenience and readable for you. When you design an API, you put it to the context. When in context:
10.seconds.from_now
is beautiful to me.
Let's do a quick google for "Fluent API in Java" and you will get something like this:
Invoice inv = Invoice.builder()
.createdOn(new Date())
.withDocumentNumber("5150")
.shippingOnTrailer("2112")
.suppliedBy(InvoiceActor.builder()
.named("101")
.as(InvoiceActorType.DC)
.build())
.beingSentTo(InvoiceActor.builder()
.named("42")
.as(InvoiceActorType.STORE)
.build())
.with(InvoiceItem.builder()
.as("TK421")
.orderedQuantity(10)
.shippedQuantity(8)
.build())
.with(InvoiceItem.builder()
.as("FN2187")
.orderedQuantity(5)
.shippedQuantity(5)
.build())
.build();
The only difference here is that Ruby allow you to attach method to anything.
But then you have category in Objective C, extension in Swift/Kotlin.
The language gives you the tool, to make your job easier, that's why I wrote "I feel happy when writing Ruby" because I have that power.
To even protected you from changing everything, you can also use refinement to scope this, though it seems underestimated currently IMHO.
When using it the right way, it helps everyone write readable code.
Back to your example:
> 10.pixels.from.top_left_corner.to.southeast.using.red.stroke
It's up to your however you want to design it.