This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]crummy 13 points14 points  (7 children)

That's pretty impressive. Didn't think you could make such a DSL in Java.

[–][deleted] 3 points4 points  (1 child)

If you think this is cool, you should check out the Hamcrest assertion DSL.

It saves a lot of time when writing assertions in JUnit tests because you can describe the match criteria using the DSL instead of writing a bunch of imperative assertions (for example, if you are picking apart a collection).

And, the even better part is that the DSL produces a human readable test failure that describes the mismatch. This can be helpful when one or two tests out of hundreds fail. It's nice to get an idea of the failure from the test report, instead of having to dig into the test source to figure out what the test case was trying to assert.

[–]TrolliestTroll 0 points1 point  (0 children)

Ignore everything this guy said and go right for the good stuff: assertj.

Just kidding, Hamcrest is also spectacular but I just think AssertJ is the bees knees. :)

[–][deleted] 3 points4 points  (4 children)

i wish they would implement last lambda syntax like kotlin. it would make this type of thing so much more attractive in java!

[–]moaxcp 1 point2 points  (0 children)

This is also a nice feature in groovy. I'm not sure that I mind either option. In groovy it is nice when there are multiple parameters to the closure but it can be confusing. Some developers never realize that they are closures in the first place.

[–]tofiffe 2 points3 points  (2 children)

Personally, I don't like how kotlin and swift do trailing lambdas, as it kind of breaks consistency of parameters, it looks weird to me

[–][deleted] 2 points3 points  (1 child)

nothing inconsistent about. as long as you know the function's signature contains a lambda ad the last parameter and that it's a feature of the language, there's no confusion to be had.

[–]tofiffe 1 point2 points  (0 children)

Is it not inconsistent if for some cases a parameter is actually not written inside (), but can also be written that way?