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

Don't Panic: Remove main panic #105

Merged
merged 1 commit into from
Sep 14, 2020
Merged

Don't Panic: Remove main panic #105

merged 1 commit into from
Sep 14, 2020

Conversation

abhinav
Copy link
Collaborator

@abhinav abhinav commented Sep 14, 2020

In our example, we panic in main instead of the function foo. The
point that this was demonstrating was that the caller of the function
has the choice of panicking rather than foo itself.

Unfortunately, this causes confusion for readers modeling their main()
after this code, because the "good" example still panics.

This reduces confusion here by having main handle the error with an
os.Exit.

Note that this moves argument handling into foo because placing it in
main is not very testable.

In our example, we `panic` in `main` instead of the function `foo`. The
point that this was demonstrating was that the caller of the function
has the choice of panicking rather than `foo` itself.

Unfortunately, this causes confusion for readers modeling their `main()`
after this code, because the "good" example still panics.

This reduces confusion here by having `main` handle the `error` with an
`os.Exit`.

Note that this moves argument handling into `foo` because placing it in
`main` is not very testable.
@twilly
Copy link
Contributor

twilly commented Sep 14, 2020

Do you know where your towel is?

(+42)

@abhinav abhinav merged commit 9c691f1 into master Sep 14, 2020
@abhinav abhinav deleted the abg/dont-panic branch September 14, 2020 20:40
mmelnyk pushed a commit to mmelnyk/guide that referenced this pull request Oct 8, 2020
In our example, we `panic` in `main` instead of the function `foo`. The
point that this was demonstrating was that the caller of the function
has the choice of panicking rather than `foo` itself.

Unfortunately, this causes confusion for readers modeling their `main()`
after this code, because the "good" example still panics.

This reduces confusion here by having `main` handle the `error` with an
`os.Exit`.

Note that this moves argument handling into `foo` because placing it in
`main` is not very testable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants