From 87ecc794d5f2aa42eaaabc084eab179b3b7b1da4 Mon Sep 17 00:00:00 2001 From: Eric Githinji Date: Fri, 28 Feb 2025 18:35:56 +0000 Subject: [PATCH] Use dbg! instead of println! in deep dive sessions. Part of #2478 to clean up code blocks when all that is needed is a trivial debug print statement. The deep dive sessions didn't have that many occurrences of trivial println! statements. I believe this can close #2478. --- CONTRIBUTING.md | 10 +++++----- src/bare-metal/useful-crates/spin.md | 4 ++-- src/concurrency/threads/scoped.md | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a5ecccc37889..fd02e8d41586 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,11 +19,11 @@ match ANCHOR comments in the `exercise.rs` file. Each segment also has a `Cargo.toml`. The result is that `exercise.rs` is built and tested by `cargo test`. -For segments on day 1, exercises should use `fn main() { .. }` and `println!`, -with students visually verifying the correct output. On subsequent days, prefer -tests and omit `fn main() { .. }`. However, where tests would be difficult and -visual verification is more natural (such as in the Logger exercise), using -`fn main { .. }` is OK. +For segments on day 1, exercises should use `fn main() { .. }` and `dbg!` or +`println!`, with students visually verifying the correct output. On subsequent +days, prefer tests and omit `fn main() { .. }`. However, where tests would be +difficult and visual verification is more natural (such as in the Logger +exercise), using `fn main { .. }` is OK. Especially for exercises without tests, consider including tests in `exercise.rs` that do not appear in either `exercise.md` or `solution.md`, as diff --git a/src/bare-metal/useful-crates/spin.md b/src/bare-metal/useful-crates/spin.md index 42f9f1de27d1..13fc863f1e18 100644 --- a/src/bare-metal/useful-crates/spin.md +++ b/src/bare-metal/useful-crates/spin.md @@ -15,9 +15,9 @@ use spin::mutex::SpinMutex; static COUNTER: SpinMutex = SpinMutex::new(0); fn main() { - println!("count: {}", COUNTER.lock()); + dbg!(COUNTER.lock()); *COUNTER.lock() += 2; - println!("count: {}", COUNTER.lock()); + dbg!(COUNTER.lock()); } ``` diff --git a/src/concurrency/threads/scoped.md b/src/concurrency/threads/scoped.md index 339645196f88..3bf65ff6c5ed 100644 --- a/src/concurrency/threads/scoped.md +++ b/src/concurrency/threads/scoped.md @@ -12,7 +12,7 @@ use std::thread; fn foo() { let s = String::from("Hello"); thread::spawn(|| { - println!("Length: {}", s.len()); + dbg!(s.len()); }); } @@ -30,7 +30,7 @@ fn foo() { let s = String::from("Hello"); thread::scope(|scope| { scope.spawn(|| { - println!("Length: {}", s.len()); + dbg!(s.len()); }); }); }