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

Update 10-defensive.md #1085

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update 10-defensive.md #1085

wants to merge 1 commit into from

Conversation

dhvalden
Copy link

complete change of the lesson to cover exceptions and try except pattern. Closes #1084

If this pull request addresses an open issue on the repository, please add 'Closes #NN' below, where NN is the issue number.

Please briefly summarise the changes made in the pull request, and the reason(s) for making these changes.

Changes completely the lesson to cover input validation using exception and try except patterns. It addresses #1084 adn #979

If any relevant discussions have taken place elsewhere, please provide links to these.

#979 #622, #773 and #874,

For more guidance on how to contribute changes to a Carpentries project, please review the Contributing Guide and Code of Conduct.

Please keep in mind that lesson Maintainers are volunteers and it may be some time before they can respond to your contribution. Although not all contributions can be incorporated into the lesson materials, we appreciate your time and effort to improve the curriculum. If you have any questions about the lesson maintenance process or would like to volunteer your time as a contribution reviewer, please contact The Carpentries Team at [email protected].

complete change of the lesson to cover exceptions and try except pattern
Copy link

🆗 Pre-flight checks passed 😃

This pull request has been checked and contains no modified workflow files, spoofing, or invalid commits.

It should be safe to Approve and Run the workflows that need maintainer approval.

Copy link

@quirksahern quirksahern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a member of the SWC LPGC (now incorporating the CAC) I broadly support the recommended changes to this episode.

The focus is largely on focusing on introducing the concept that things can go wrong, and we need to check for those errors. At this stage I think that is sufficient. We can still maintain some content on TDD but that isn't the focus of this lesson.

For input validation assertions aren't appropriate, and can cause issues later on.
For these instances try ... except is the better option.

It would still be could to include assert, I recommend the following:

  1. an example of the assert syntax be included, then
  2. example of using assert to check input and outputs to variables.
  3. Then add a comment that this kind of thing is done as part of the Test Driven Development approach, link out to further information on TDD

I don't think that there needs to be a discussion on TDD in this episode as it is beyond what learners need to know at this point in time.

@martinosorb
Copy link
Contributor

The first part can be read as using assert for input validation, which we have all agreed is not right, but could also be interpreted as testing, if we assume the input comes from other parts of our code. However, this is not sufficiently clear, and I agree to change this part to raising errors, since raise is not taught anywhere else.

The main problem is that we're throwing away the baby with the bathwater, as this becomes an episode on input validation only, removing the rest. I'd say we could keep a part on assert, and on the benefits of adding little testing devices to our code, which was the main point of this episode.
We can also still briefly talk about TDD, but without all the current detail.

In summary, I would

  • keep the current introduction that motivates testing and checks
  • when talking about pre-conditions
    • introduce raise for input validation
    • add some of @dhvalden's new material motivating input testing.
    • the discussion on the difference between TypeError and ValueError should be moved to ep 9, where all the error types are discussed, but can be referred to in the example
    • alternatively, we can keep the current example, which both shows pre- and post-conditions, so I think is better suited
  • when talking about post-conditions, introduce assert for quick testing and explain its benefits
  • shorten the part on TDD
  • introduce try...except, but with a real use case where there is no solution other than using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using Assert as input validation is wrong and needs to be changed
3 participants