You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
move example code from docs into source code - #2143
This should fix#774 via creating a separate 'example' module with sources only for documentation purposes and at the same time it can be used as a start to create a Java project using GraphHopper through the Java library.
There were many incomplete examples (that probably converted into this state over the time and because they are not executable) and this is the main indication that we really need to do this when we want usable example Java code :)
TODOs:
I was unsure if we should make it safe for refactoring via assertEquals or easy for beginners to copy and paste via System.out.println. But now I'm sure I need both and will e.g. comment all assertEquals with "// not necessary in real code".
I was unsure if we should make it safe for refactoring via assertEquals or easy for beginners to copy and paste via System.out.println. But now I'm sure I need both and will e.g. comment all assertEquals with "// not necessary in real code".
I would suggest not mixing levels of instruction here, or meta-commenting on what you're doing -- keep it simple, choose one of two:
Write the examples as JUnit tests. Then assume that user knows what a test is and what assert means, and how to write regular code from the example given by the test. Let it speak for itself, don't comment on it. Comment only on what the API is doing.
Otherwise, you would in principle also have to explain how to move the code from test to main, how to write a main method, etc. -- doesn't make sense. Don't teach Java while documenting a Java API. Different job.
Write the examples as "main" code. Then don't put them in src/test but in src/main, and use Java's assert, not JUnit's, and then just run them from a one-line JUnit test. Even then, no need to apologize, it's fine to have assertions, especially beginners (but really everyone) should use them more. So you could even comment // verify that what we're doing makes sense rather than // not necessary in real code.
Write the examples as "main" code. Then don't put them in src/test but in src/main,...
then just run them from a one-line JUnit test.
Thanks, this is an interesting idea. Will think about which one makes more sense and also look into other open source projects how they do it. btw: do you know any with good examples?
Will move the code into main and use your second approach. Open source projects like dropwizard or optaplanner that use this approach seem to have normal unit testing in place for the example app instead of asserts in the code. Will see if I can make it working this way, otherwise I will use assert like you proposed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This should fix #774 via creating a separate 'example' module with sources only for documentation purposes and at the same time it can be used as a start to create a Java project using GraphHopper through the Java library.
There were many incomplete examples (that probably converted into this state over the time and because they are not executable) and this is the main indication that we really need to do this when we want usable example Java code :)
TODOs: