-
-
Notifications
You must be signed in to change notification settings - Fork 710
Binary search #186
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
Binary search #186
Conversation
@javaeeeee thanks for this addition! Overall the exercise implementation looks very solid; I'll comment inline with a few comments/questions and we can discuss from there :) |
|
||
dependencies { | ||
testCompile "junit:junit:4.12" | ||
testCompile "org.assertj:assertj-core:3.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, my preference (moving forward) would be for all new exercise implementations to rely on the default JUnit assertions. While I definitely think AssertJ assertions read better, it's another API surface that newcomers need to explore/understand to make sense of the tests we present.
@exercism/java thoughts on this? Is there somewhere we can capture standards such as the one I'm proposing for future reference? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, @stkent for the exact reason you gave.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, also agree. Actually used jUnit assertions in the test. In some other projects AssertJ is used, so It looks like a standard for the project. Removed the dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, @javaeeeee, we haven't completely removed "not technically necessary" third party dependencies. Sorry for the confusion that caused.
|
||
public class BinarySearch<T extends Comparable<T>> { | ||
|
||
public static String ARRAY_MUST_BE_SORTED = "Array should be sorted."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field can be marked final
to make it an honest-to-goodness constant :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, missed this. Static analyzers had several other complaints including Javadocs, so didn't spot it. Are Javadocs actually allowed in the project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem! As far as I know, adding Javadocs to example implementations (when appropriate) should be just fine. Pinging @exercism/java for confirmation of that though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, Stuart, thank you for the answer. So the takeaway is that comments may be used only in the example implementations, not the tests. Am I right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think comments are just fine in the tests too - as mentioned somewhere else in this PR, we have them when JUnit rules are implemented, so that users can find relevant context more quickly. However, as is generally considered good practice, we definitely don't want comments on every line of code just for the sake of it ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, the code should be self-explanatory will little need for comment.
If one is tempted to add a comment, ask first, "is there a way I can reword this code to make it so clear, a comment is no longer necessary?"
Comments are best used to explain unusual/surprising context... that is to say, they share why a chunk of code is shaped in the way it is.
For example, in robot-simulator
, @stkent smartly overloaded Object::equals
instead of overriding it and didn't implement Object::hashCode
. He left a comment explaining why and how one would do it in the real world.
assertEquals(actual, SORTED_LIST); | ||
} | ||
|
||
@Ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for ignoring all but the first test by default! Implementors thank you.
final int actual = sut.indexOf(number); | ||
final int expected = -1; | ||
assertEquals(expected, actual); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The binary-search
problem has associated canonical test data located here.
In general, when implementing a new exercise in a track we should reference those canonical test cases (if they exist) to ensure consistency across languages. I think you have most of the expected cases covered, but for future maintainability it would be awesome if you could adjust your tests to match the canonical naming/data exactly. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Thank you for the reference.
); | ||
|
||
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of Rules! Since this is a relatively advanced concept that we've only just begun integrating into the track, we've been marking all usages with a helpful comment (for an example, see https://github.com/exercism/xjava/blob/master/exercises/queen-attack/src/test/java/QueenAttackCalculatorTest.java#L11-L14). Please add that same comment here. Once we have established a progression of exercises per #142, then we'll likely reduce this redundancy some, but better safe than sorry for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the @rule from the tests altogether as according to the canonical test data one shouldn't test if the array is sorted.
Hello, Stuart and thank you.
…On Sat, Nov 26, 2016 at 9:39 AM, Stuart Kent ***@***.***> wrote:
@javaeeeee <https://github.com/javaeeeee> thanks for this addition!
Overall the exercise implementation looks very solid; I'll comment inline
with a few comments/questions and we can discuss from there :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#186 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AIezh3U1iyAAGnUMP_q-KsDfJjqMlF0vks5rCES7gaJpZM4K8po3>
.
|
|
||
import java.util.List; | ||
|
||
public class BinarySearch<T extends Comparable<T>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed that this generic type means the example implementation is a lot more general than the tests require. @exercism/java is this a good feature in a reference solution, or does it veer towards YAGNI territory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I currently give wide berth to implementors in what happens in the example. As long as it passes the tests and represents a true solution, it's generally been implementor's choice.
I think this way because practitioners don't see these. The high value conversations in PRs are about how the test suite flows, the API decisions therein and whether we're implementing the exercise correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, and thank you for your comments. Here is a question: Do we need .keep files? Spotted that some were removed in one of the commits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there are other files in exercises/binary-search/src/main/java/
and exercises/binary-search/src/test/java/
, it should be safe to remove exercises/binary-search/src/main/java/.keep
and exercises/binary-search/src/test/java/.keep
. Thanks for checking!
One more merge with master needed! |
Merged! |
Sorry for the silence yesterday; I should be able to take another look at this tonight :o) |
It's Okay. Thank you. There is no hurry. |
Looks good! One more merge, then I'll hit the button as fast as possible so we don't need any more :) |
Take your time; I'll make sure not to merge until this one goes through (assuming no corrective feedback). |
Thank you. Done.
…On Fri, Dec 2, 2016 at 9:22 AM, John Ryan ***@***.***> wrote:
Take your time; I'll make sure not to merge until this one goes through
(assuming no corrective feedback).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#186 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AIezh2MW0vnkc02CNwCOVyB4sCNfQl9hks5rECmMgaJpZM4K8po3>
.
|
@jtigger hah, yes, I wouldn't really race, but thank you for holding off on others. (I haven't dealt with my own merge conflict for that same reason :) |
Thank you. :)
…On Fri, Dec 2, 2016 at 10:46 AM, Stuart Kent ***@***.***> wrote:
Merged #186 <#186>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#186 (comment)>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AIezhzx1ISDCp9dmd6u_9EZxqBhTtvKTks5rED1QgaJpZM4K8po3>
.
|
Added the binary search exercise to the Java track.