Skip to content

Commit

Permalink
Use dbg! instead of println! in Day 1 aft session (#2654)
Browse files Browse the repository at this point in the history
Part of #2478 to clean up code blocks when all that is needed is a
trivial debug print statement.

In certain slides (8.1, 9.2, 9.3, 10.5) I've opted to retain the use of
println! because dbg! makes it less readable. The
dbg! macro uses pretty-printing by default and this results in a simple
array such as the one in 8.1 being printed vertically instead of a
cleaner one-liner.

Co-authored-by: Eric Githinji <egithinji@google.com>
  • Loading branch information
egithinji and Eric Githinji authored Feb 24, 2025
1 parent 0daab17 commit f531d4d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/references/dangling.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ use. One rule is that references can never be `null`, making them safe to use
without `null` checks. The other rule we'll look at for now is that references
can't _outlive_ the data they point to.

<!-- mdbook-xgettext: skip -->

```rust,editable,compile_fail
fn main() {
let x_ref = {
let x = 10;
&x
};
println!("x: {x_ref}");
dbg!(x_ref);
}
```

Expand Down
6 changes: 2 additions & 4 deletions src/references/shared.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ A reference provides a way to access another value without taking ownership of
the value, and is also called "borrowing". Shared references are read-only, and
the referenced data cannot change.

<!-- mdbook-xgettext: skip -->

```rust,editable
fn main() {
let a = 'A';
let b = 'B';
let mut r: &char = &a;
println!("r: {}", *r);
dbg!(*r);
r = &b;
println!("r: {}", *r);
dbg!(*r);
}
```

Expand Down
4 changes: 2 additions & 2 deletions src/tuples-and-arrays/exercise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ fn main() {
[301, 302, 303],
];

println!("matrix: {:#?}", matrix);
dbg!(matrix);
let transposed = transpose(matrix);
println!("transposed: {:#?}", transposed);
dbg!(transposed);
}
// ANCHOR_END: main
// ANCHOR_END: solution
Expand Down
4 changes: 2 additions & 2 deletions src/tuples-and-arrays/tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ minutes: 5
```rust,editable
fn main() {
let t: (i8, bool) = (7, true);
println!("t.0: {}", t.0);
println!("t.1: {}", t.1);
dbg!(t.0);
dbg!(t.1);
}
```

Expand Down

0 comments on commit f531d4d

Please sign in to comment.