Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC][DO_NOT_MERGE] Kpact #3

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

[RFC][DO_NOT_MERGE] Kpact #3

wants to merge 16 commits into from

Conversation

usr42
Copy link
Owner

@usr42 usr42 commented Aug 18, 2018

This PR is an RFC and only for discussing the current state of the DSL and how it should evolve.
It's not intended to be merged.

@usr42
Copy link
Owner Author

usr42 commented Aug 23, 2018

Documentation is available at https://usr42.github.io/pact-jvm/

Copy link

@johnny johnny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I like this.

You could consider another use case, which i don't know if it makes sense at all, but here goes:
People might want to use your API in unexpected ways. E.g. extracting parts of the definition into variables and reusing them multiple times in different contexts.
I'm not sure, if the current code supports this, since I've seen only 2 immutable objects.

[source,java,indent=0,role="primary"]
.Infix DSL
----
include::src/test/kotlin/au/com/dius/pact/consumer/kotlin/dsl/examples/InfixDslExample.kt[lines=11..47]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github doesn't render this properly, which results in an unexpected experience. I expect the README to render correctly and have the complete content available. Having a short readme and linking to the github.io page is also fine.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done
I've split into a brief README.md and a detailed, parsed asciidoc-generated gh-page linked in the readme.

[source,java,indent=0,role="secondary"]
.Fluent DSL
----
include::src/test/kotlin/au/com/dius/pact/consumer/kotlin/dsl/examples/FluentDslExample.kt[lines=11..47]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referencing line numbers is probably fragile. Consider using tags instead

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of tags for includes. Awesome feature. Thanks for the hint.
done

:n: icon:times[role="red"]

== Goals
* Easy readable
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prose could be more extensive here, e.g. the resulting pact should be readable. Also should they be easy or simple https://www.youtube.com/watch?v=34_L7t7fD_U

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done
I reformulated the first two bullet points

* Things on the same logical level are on the same indentation level (auto-indentation of IDE)
* Usable also from https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-consumer-junit5[pact-jvm-consumer-junit5]
(from `PactDslWithProvider` to `RequestResponsePact`)
* Support both:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you support both.

[source,java,indent=0,role="primary"]
.infix
----
consumer withName "consumer" andProvider "provider" havePact {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that not backed by real code?

@@ -0,0 +1,79 @@
plugins {
id "io.gitlab.arturbosch.detekt" version "1.0.0.RC8"
id "com.github.ben-manes.versions" version "0.20.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice finding.
done

[source,java,indent=0,role="secondary"]
.fluent
----
"consumer".hasPactWith("provider") {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like a string extension goes too far. A string does not represent a consumer by itself. So "consumer".hasPactWith reads kind of non-sensical to me

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This String extension is only applicable inside of the kPact DSL lambda. So, it is not a general String extension.

"consumer".hasPactWith("provider") {
----

==== (Dis-)Advantages
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider a title like: Comparing the different DSL Styles

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// ...
}

consumer withName "consumer" andProvider "provider" havePact {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand your concern here. Couldn't this second call raise an exception, due to a conflict with an existing pact?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is the missing compile time safety. The exception is thrown during runtime, so the compiler and the IDE cannot help to prevent this error. With the other approach this error is not possible at all.

fun infixDsl() {
val infixDsl =
// tag::CamelCase[]
KPact between "Some Consumer" and "Some Provider" isDefinedBy { // <1> <2>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this one. One word usually makes it easier to use in an IDE. I personally like it to be a little more explicit, thus I prefer this over the very short option.

fun proseLikeShorter() {
val infixDsl =
// tag::proseLikeShorter[]
KPact between "Some Consumer" and "Some Provider" { // <1> <2>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this one, it is more concise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants