-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactor All Expectations to Have the Form ‘to + infinitive’ #93
Comments
To start the discussion, let’s go through assertions that are mentioned in the README and see how they’d change:
My takeaway is: Most things are at least as good in the ‘to + infintive’ form as they are today. However, we inconsistently already use ‘to + infinitive’ from time to time (e.g. As expected, assertions using the Areas where I see trouble:
|
if we are going to change the functions then I would do it the same way as we did with other assertion functions we deprecated so far. Deprecate it and remove them at some major version, which means they might stay for some time but eventually be removed. https://www.ldoceonline.com/dictionary/i-expect
I guess that's the reason why I am used to it and maybe the reason why you aren't? I am pretty sure I have heard sentences like: Thanks for preparing all the examples. At a first glace, I think that
I am not convinced that On the other hand, I am convinced that it would be a nice match for the infix API:
IMO here it would make more sense, but code completion would also suffer here. Where I am really not with you is |
Last but not least we should also look at the long forms of iterable.contains and define what name we would use for after renaming status quo expect(list).contains.inAnyOrder.atLeast(2).elementWhich { isLessThan(2) } a few ideas: expect(list).toContain.inAnyOrder.atLeast(2).elementThatHas { toBeLessThan(2) }
expect(list).toContain.inAnyOrder.atLeast(2).elementWhichHas { toBeLessThan(2) }
expect(list).toContain.inAnyOrder.atLeast(2).elementWhichNeeds { toBeLessThan(2) }
expect(list).toContain.inAnyOrder.atLeast(2).elementThatNeeds { toBeLessThan(2) }
expect(list).toContain.inAnyOrder.atLeast(2).elementIdentifiedBy { toBeLessThan(2) }
expect(list).toContain.inAnyOrder.atLeast(2).elementFoundBy { toBeLessThan(2) }
expect(list).toContain.inAnyOrder.atLeast(2).elementMatching { toBeLessThan(2) } I am sure you have different ideas |
While I think that
As I have said many times before, I am not a representative user for the infix API.
I see your arguments. I would personally still prefer something like
I agree. Regarding |
I mulled the idea over... I start to make friends with it. Just as notice, we are going to resemble more and more jasmine (https://jasmine.github.io/2.0/introduction). There are still a few things I would like to look at and get your opinion before we move to 1. Rename
|
So do I! The more consistent naming in the API that I will lay out it point 2 would also be a significant improvement, from my point of view. 1. Rename toBe to toEqual.
Arriving at a point where others have arrived before is usually a good sign. However, resembling Jasmine should never be a goal in and of its own, I think. But seeing that something works well for others is always a good argument.
I am glad that you bring that up! I support this change fully, albeit mainly for the reason of precision. I don’t really care whether we are similar to another framework or not. I think
Neither would I! For the same reason I have given above: precision. 2. feature assertions
I agree. The shortcuts don’t form a fluent sentence, but we will never get them to: It would require genitives, and I don’t thik we want to go there. So agreed.
I strongly believe that they should be renamed and that renaming them would improve the API. I see your point that So for my mind, the fact that the functions have the same names as the “real” ones is irritating. After renaming everything, we would have a very clear structure:
I think this new consistency would improve the API. This should also answer your other examples. 3. unreported subject changes
I agree. It also fits nicely in the new naming rules I wrote above. 4. becauseI see no reason not to use because. I think it is a nice and fluent way to give the reason for an assertion. As I wrote above, “Jasmine does it” is not a convincing argument to me in and of its own. It would need to be attached with something like “Jasmine does it and it works very well for them because …”. |
Sweet, we agree on all points :) |
Coming back to robstoll/atrium#689 where you asked that
Thoughts? |
Do they? To my mind, they are closer to feature extractors than they are to assertions since they don’t actually do the checking but delegate to a real assertion. It’s a matter of perspective, I guess. Regarding However, I already know that you are concerned about developers programming subtle bugs into their tests. I agree that this can happen. Given that you want to help developers avoid such bugs, I think that Having said that, I’d find the following names more intuitive: These names are even longer, though. I think I feel more strongly about using |
According to your own statement:
The same applies to |
I somehow never looked at it this way, but you are right. Goes to show how subjective these things can be 🤷 |
Since we decided to do it: What is the timeline and plan for this change? If we coordinate ahead of time, I am happy to help realise it. I suspect it will be quite an endeavour and once started, should be finished quickly to avoid conflicts. |
Nice to hear. Planning is quite hard if you don't know the time you have available. So I cannot tell you when I would do it. Therefore, do you already know when it would be suitable for you? |
There won’t be any good time for at least the next half year, I’ll have to squeeze it in any way. So there’s no particular time constraint from my side. In general I’d suggest something like:
|
I don't see any breaking change happening on the API-level. Do you see one? Since you don't have a particular time slot, I suggest we don't stress ourselves and do it as fast as times allow it. I suggest the following:
You can already start with the rewrite in an own branch. Once 0.15.0 is released, we can merge the branch into master and we will release 0.16.0 as soon as all functions are rewritten for api-fluent. I would not touch api-infix at the moment and wait a bit to see how well it plays out for api-fluent |
I am on board, but I am a bit worried about
Don’t you think this will cause a lot of merge conflicts? |
I doubt it, just don't start with mapAssertions. There we could run into conflicts. In the end I want to move all deprecated functionality to files called deprecated... but let's do this after the merge. |
With rename I meant: duplicate, rename and deprecate the old version. It surely makes sense if you notify me after the first change so that I can give feedback before you continue with further changes. |
@robstoll I just noticed that we never discussed whether this change should affect reporting as well. I gave it some thought and think it should, for two reasons:
is Atrium telling me that the From my point of view, changing the reporting also to the ‘to+infinitive’ style will make the reports easier to read because it will be clear grammatically that lines state expectations:
I am not sure whether I am the only one having this problem, but I’d find it helpful. Plus, we could probably revert the assertion verb back to ‘expect’. |
Good input. By reverting to For me, both is fine. Your's and some else's argument to change it to |
Yes, although I am still sympathetic to use ‘expected’ instead of ‘expect’ since we are talking about the past (I miswrote above). But that is certainly not something I will pick fights about. |
Good with me as well, so we will change the reporting from
to
Do you agree? |
Yes. |
@jGleitz so, to + infitive will finally happen in 0.17.0 in the API. I'll start soon with the rewrite of anyAssertions to anyExpectations based on your open PR (I'll close it once I start) and hope you might find time do review it and then maybe rewrite some files as well. One thing which I muled over and I am not sure any more is regarding including articles in the expectation function name. For instance, the rewrite of
I even re-consider to remove articles from the infix API once we switch to Do you have any counter-arguments why we should include them (next to it would be grammatically correct)? |
I'll be happy to review if it's after April 19th. Otherwise, there will, unfortunately be little chance. Regarding articles:
I don't get this argument. We would catch a/an errors in PRs just like the myriad of other minor mistakes everybody makes when writing code. Sure, I agree, we will probably see some of these errors, but I don't see why that should pose any problem.
I also don't quite understand this argument. I don't think you want to argue that foreign speakers whose mother tongue doesn't have articles will have troubles reading code with articles. So I guess you must be arguing that they will have troubles writing it. But if that's your argument, this could only be a concern if people are guessing function names. I highly doubt that anybody is doing that. My typical modus operandi is using content completion. Sometimes I read the docs. That's how I find the available functions. Both methods are entirely unaffected by the presence or absence of articles. So in conclusion, I don't understand how not being used to articles should influence how well one can use a library that uses articles.
I understand this argument. I would judge the effect very minor, but I agree that it's there.
I'd argue that developers are mostly not used to it because most APIs are not fluent. If we followed this logic, we should probably not build a fluent API. Like all developers, I am, of course, quite used to code not being grammatically correct. I usually try to pick names that convey all important information with the shortest amount of letters possible. Once I use a fluent API, however, I switch modes and try to build correct sentences. I read the code a lot more like a book. Now imagine you'd read a book in English (or an language with articles, for that matter) and all of the articles were missing. It would just feel ... wrong. Sure, you'll get all of the meaning, articles are usually redundant after all. A lot of languages manage perfectly fine without them. But the whole time it would just feel wrong. It would make you uncomfortable. That's my issue with the articles in a fluent API. I am in ‘book reading mode’, thus, my brain expects articles and is always a little irritated if they are missing. Sure, that is a subjective, aesthetic argument. However, as I see it, there is no objective, and surely not non-aesthetic argument against articles. The best way to decide would probably be a study on a representative sample of users. Without having that, we (that is, ultimately you) will have to make the decision. I am in favour of articles. |
I totally agree but that's not my concern. My concern is in using Atrium, i.e. writing expectations in tests. I for one write many times faster than Intellij is able to suggest things. Which means, if I had trouble knowing if its
I agree, the more opinions we get of people using Atrium the better. I have started a poll in the atrium channel, I don't expect a lot of responses as there is normally not much going on in the channel but it's worth a try. |
This is an unexpected result for me. I interpret it such that they actually form a sentence in their mind, think of how it’s written in English and then type that out. I almost never do that. I have two ways major ways of writing identifiers:
Please note that the argument is two-edged: If there are people that form sentences and write those out, then there will also people who think like me that will be harmed if the articles are missing. That is, if we accept the argument that having articles irritates some when using functions (because they are irritated by how articles work in English), we must also accept the argument that not having articles irritates others (because they expect the articles to be there). The only way I can see this argument working is if we knew that one group greatly outnumbers the other group. |
I guess leaving out articles during writing will most likely not irritate someone who is expecting articles during reading, just because it's so common to leave them out during writing. But that's the same for people which do not expect an article during writing, it will surely not be a problem for them to read them (just the minor I totally get that missing articles are an annoyance during reading and I share this view. So I'll wait a bit and gather answers. So far, there is 1 vote more in favour of articles than for without articles. Maybe you can do the same, if you know someone which would potentially use Atrium, ask them what they would prefer. |
Please note that this is my vote! |
Thanks for your hint, I know. I did not mean the votes in the Atrium Channel, the votes of people I asked directly. |
Ah, I see. I just wanted to make the vote fair, since I expect a pretty small sample size. |
@jGleitz another topic but related, renaming isA.
|
@jGleitz I made up my mind regarding articles, we will include them as initially thought. |
Regarding I would exclude the option
I have used libraries that offer synonyms and it usually ends in chaos. For example, imagine that I, personally, like |
Very late to the discussion here but having raised my issue against the main project it's nice to see essentially exactly what I wanted is going ahead :) A couple of votes to later discussion points: Prefer No API functions should end in And whilst it's not my preference dropping articles altogether is also fine. |
Also would drop |
Good, I'll modify the PR robstoll/atrium#866 and change @CfGit12 one thing to note, I'll go with
@jGleitz I would definitely drop |
That makes a lot of sense. It is also better grammatically:
I wonder whether this is the best approach.
I agree completely. |
Good idea 👍 |
I did suggest I would however caution against trying to match underlying production APIs too much. Whether or not the underlying function is |
@jGleitz / @CfGit12 I am almost through with the transition 🎉
As additional information, there is only the inner class |
My initial thoughts would be:
Worth splitting out the two failure cases. There'll be times when you do and don't care about the type of failure coming out. |
Great! This is a big improvement for the API, from my point of view! (also: sorry for the long silence). Regarding the I think it should be |
@jGleitz I lately don't have much more time than reviewing things. I hope I will come around to implement the last bits during this summer. I have not yet created the change for I am not yet sure if we should use |
Makes sense from my point of view.
I think this is a good argument against
I’d be fine with just having Another reason why Should the above not convince you, and you want to make the type check somewhat explicit in the name, I’d suggest |
I am totally fine with toBeAFailure. We currently have isFailure and I never had the feeling it should include an |
expectation functions have been renamed in 0.17.0 open are the message in error reporting |
messages in error reporting were adopted with 0.18.0, closing this |
As we started to discuss in #92, it might make sense to refactor atrium’s API so that all assertions read like ‘expect (…).to + infinitve’, e.g. ‘
expect(x).toBe(y)
’, ‘expect(x).toStartWith(y)
’, ‘expect(x).all { toBeLessThan(y) }
’, etc.This would mean a massive change to the API, as nearly all assertion functions would need to change. Luckily, the process could be eased using Kotlin’s replacement feature for
@Deprecated
, but it would still put a huge burden on all users, as they’d need to migrate at some point¹.In this ticket, I want to evaluate whether the change would be worth it. I see these advantages:
to
andnotTo
as a prefix has some advantages, as you always start withto
ornotTo
to narrow the API surface. Thus, code completion will thus be better.In this ticket, I will try to collect examples of how different assertions would look like after the change. At the time of writing, I think that the change would only improve the API, without introducing cases that are worse. By collecting many examples, I want to confirm this.
Input from anybody is highly welcome!
¹ we might discuss whether we’d need to remove the old assertion verbs at all. We could probably mark all assertions as
@Deprecated
, move them into their own module and let them live there forever. Atrium separates API and logic so clearly, that this might not add a significant maintenance burden.The text was updated successfully, but these errors were encountered: