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

Exercise consistency: tests or main? and allow(unused) #1581

Closed
djmitche opened this issue Dec 12, 2023 · 1 comment · Fixed by #2644
Closed

Exercise consistency: tests or main? and allow(unused) #1581

djmitche opened this issue Dec 12, 2023 · 1 comment · Fixed by #2644
Assignees

Comments

@djmitche
Copy link
Collaborator

djmitche commented Dec 12, 2023

See #1565 for context.

Also, put all text above the code sample!

@mgeisler
Copy link
Collaborator

Good questions!

There are some practical reasons and constraints for some of this:

  • Tests are not run in the embedded playgrounds — the playgrounds need a main function.
  • On the other hand, we run tests via cargo test in CI!

So I like tests because they help keep the course code correct. I also think it's fine to show people simple unit tests from day 1: they're just small functions after all and don't look scary in my opnion.

We ask people to solve most or all exercises in https://play.rust-lang.org/ or locally using an editor with rust-analyzer. This means that they can execute tests just fine. However, having passing tests be the criteria for success takes away some of the free-form experimentation that you can do when you just have some code and a main function to call it from.

Related to this, it always bothered me how Rust doctests have to use assert_eq!(foo, 123) to express the expectations in your example. It feels dry and it means I cannot talk about things like println! or dbg! output in my example. I like the Python way much more where you show an interactive console session.

However, since we're not Python and don't have such interactive tools, I guess using small unit tests is okay. A bit boring, but probably also more professional 😄

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 a pull request may close this issue.

2 participants