The best way to print variable?

Which one is the best practices to print a variable

fn main() {
  // first method
  let first_name = "Jhon";
  println!("name: {}", first_name);
  // second method
  let second_name = "Kyle";
  println!("name: {second_name}");

The second method only became possible recently, but is probably going to become the more common way over time. However, I don't know that there's a best practice, per se.

So if you're concerned about supporting versions of Rust before 1.58.0 (released 6 weeks ago), use the first method. If not, whichever you prefer.

This is why I despise such "features". They create bifurcation in the language and endless bikeshedding, due to the absence of an objectively better answer.

1 Like