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

Improve learning experience for interfaces, errors and error wrapping #2492

Open
3 of 4 tasks
junedev opened this issue Sep 17, 2022 · 2 comments
Open
3 of 4 tasks

Improve learning experience for interfaces, errors and error wrapping #2492

junedev opened this issue Sep 17, 2022 · 2 comments
Assignees
Labels
x:rep/medium Medium amount of reputation

Comments

@junedev
Copy link
Member

junedev commented Sep 17, 2022

[This is a dummy issue for now to keep track of this improvement idea. More detailed issues that can be worked on will be created later. If someone wants to work beforehand, please comment below and we can discuss.]

In JavaScript, teaching inheritance together with errors works very well which is why I thought a similar combination might work out in Go. But I think it's not working very well, interfaces are quite a big topic in Go so we currently only scratch the surface in the existing "The Farm" exercise. We don't practice creating an interface currently, people don't understand the difference between unwrapping an error and not unwrapping, etc. To fix this I think it would be good to have one exercise to teach interfaces with tasks that include creating and interface and using an existing one etc. Then we can have an errors concept that includes error wrapping and shows unwrapping and not unwrapping in error handling "side by side" so people better understand the difference and can practice in the exercise. The new interfaces exercise will then be a prerequisite for the errors exercise.

Sequence:

  • Create new separate exercise for interfaces
  • Remove learning interfaces from the errors exercise
  • Simplify existing error concept and exercise
  • Create new error wrapping concept and exercise
@junedev junedev added the discussion This is a topic for a longer discussion. The issue can stay open for a while. label Sep 17, 2022
@junedev
Copy link
Member Author

junedev commented Sep 17, 2022

See #2011 for something to include in the new errors concept.

@junedev junedev self-assigned this Jan 22, 2023
@junedev junedev removed the discussion This is a topic for a longer discussion. The issue can stay open for a while. label Jan 22, 2023
@junedev
Copy link
Member Author

junedev commented Feb 20, 2023

Latest draft about how to split the errors exercise/ add wrapping:

Exercise 1 - Error basics

  • create sentinel error (errors.New)
  • use a variable if you want to re-use
  • returning an error, what else to return, don't use other results if there was an error
  • return nil if there was no error
  • check via if err != nil
  • early returns/line of sight (might be only about.md)
  • Create custom error type

Exercise 2 - Error checking and wrapping

  • fmt.Errorf("...%v") and fmt.Errorf("...%w")
  • errors.Is and ==
  • errors.As and the non-unwrap equivalent
  • wrapping in custom type and custom unwrap

@junedev junedev added the x:rep/medium Medium amount of reputation label Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:rep/medium Medium amount of reputation
Projects
None yet
Development

No branches or pull requests

1 participant