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

Make examples fully qualified #1660

Closed
msfeldstein opened this issue Aug 27, 2019 · 2 comments · Fixed by #1867
Closed

Make examples fully qualified #1660

msfeldstein opened this issue Aug 27, 2019 · 2 comments · Fixed by #1867
Labels
good first issue Hacktoberfest https://hacktoberfest.digitalocean.com/details

Comments

@msfeldstein
Copy link
Contributor

Currently our example code (for example StreamPayments) shows code running inside our Go SDK package, but anyone else will be running code outside the package. This means that they will need to properly qualify all the classes and methods, add the proper imports. This makes it far harder to just copy/paste/run examples. We should have the examples be fully qualified.

From @leighmcculloch :

we should put our examples in a separate files, something like examples_test.go, and at the top of the file, change package wonderfulthings to package wonderfulthings_test.

it will mean you’ll need to import github.com/stellar/wonderfulthings and throughout the code you’ll reference functions, types, etc as wonderfulthings.AmazingType.
@leighmcculloch
Copy link
Member

Here's a good example of an example test for the go sort package. It lives inside the same directory as the sort code, but is given the special _test suffix to tell the compiler we want the code built as if it's external to the package.

https://github.com/golang/go/blob/94bf9a8d4ad479e5a9dd57b3cb8e682e841d58d4/src/sort/example_search_test.go#L5-L25

Go blog also has some great examples: https://blog.golang.org/examples

@Rabatte
Copy link

Rabatte commented Sep 9, 2019

It will definitely be helpful. thank you very much

@ire-and-curses ire-and-curses added the Hacktoberfest https://hacktoberfest.digitalocean.com/details label Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Hacktoberfest https://hacktoberfest.digitalocean.com/details
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants