Maybe the problem is that this is not a "fluent interface".
There are no dots.
Oh, and by the way, Go has an expression syntax
that might just do the trick:
assert(x >= 5 && x < 18 && !prime(x))
Russ
The failure messages won't be so readable, though.
Chris
--
Chris "allusive" Dollin
I wasn't being sarcastic. I don't see the point
of creating a separate syntax for writing expressions
when Go already has a rich syntax for writing expressions.
To automate error messages? I can write error messages
myself and then not have to learn (and continually extend)
some other testing language that isn't Go. I'd rather write
my tests and my code in the same language.
> An obstacle to the adoption of fluent APIs in Go will be that many of
> the core libraries thus far have been written by people with an
> extremely terse style. Fluent interfaces are a major style clash for
> "tersers"...a clash that isn't endemic to Go (the language), but has
> everything to do with personal tastes.
No. It has everything to do with writing Go versus
writing some other language mapped to Go function calls.
> Broadly speaking, the "tersers" arrived first, but the "fluents" have
> started to move in. I'm very curious to see whether they work
> together or set up separate camps on the island...err...I mean, in the
> language.
It's interesting that the fluents only move in on existing languages.
Where is the programming language written entirely in this
"fluent" manner, and why don't the fluents all use that one?
I suspect it is because you can't get any real work done,
only testing.
Russ
Why, so can I, or so can any man --
> and then not have to learn (and continually extend)
> some other testing language that isn't Go.
It's just function calls; it's not a new language. It's a stylised way
of using the existing language, which pretty much any application
is.
As for the messages, while it's true that you can write [1]
if x < 5 {
bother( "expected", x, "to be less than 5" )
} else if x >= 18 {
bother( "expected", x, "to be less than 18" )
} else if prime(x) {
bother( "expected", x, "to be composite" )
}
I'd rather write something more like, if not exactly like:
AssertThat(8, Is(AllOf(GreaterThan(5),LessThan(18),Not(Prime())))
because the 17th time I wrote the former my head would
explode and my fingers start to smoke.
Chris
[1] `bother` being assumed to print its arguments nicely and quite the test.
--
Chris "allusive" Dollin
> because the 17th time I wrote
something like!
> the former my head would explode and my fingers start to smoke.
Chris
--
Chris "allusive" Dollin
I'd have written
if x < 5 || x >= 18 || prime(x) {
t.Fatalf("invalid x: %d", x)
}
but this is not a common kind of check in a test.
I certainly have never written 17 such checks
in my life.
Can you point to places in actual Go tests
in the distribution where the so-called fluent
style would help? It seems like a solution in
search of a problem.
As far as I can tell, fluent coding is quite the misnomer.
It ignores the surrounding language instead of actually
using it idiomatically and, well, fluently.
Russ
Thereby not saying what test failed (yes, I know I can look
at the code and work it out -- I'd rather have the machine tell
me what it already knows).
> but this is not a common kind of check in a test.
> I certainly have never written 17 such checks
> in my life.
17 such AllOfs, nor me either. But at the smaller scale,
in JUnit tests I routinely use assertEquals (and a local
assertDiffers) rather than AssertTrue (or AssertFalse)
because of the better error messages, routinely create
assertWhatever methods when there's a meaningful
Whatever predicate that applies for the values in question,
and will happily write functions over the different Whatevers
(which amounts to being able to write the "fluent" expressions
in question).
> Can you point to places in actual Go tests
> in the distribution where the so-called fluent
> style would help?
No, but that only proves my current ignorance of the contents
of the Go tests.
> As far as I can tell, fluent coding is quite the misnomer.
> It ignores the surrounding language instead of actually
> using it idiomatically and, well, fluently.
I didn't (and possibly still don't) know what "fluent coding" is;
the Hamcrest-style being discussed is just, well, declarative-
style code written to be explicit about what it means, as far as I
can see. There's a bunch of library functions and you use them
to write things -- that some of them parallel existing language
structures is hardly surprising.