Le 14/07/2013 03:39, Jack Moffitt a écrit :
I propose instead:

1) Do away with the formatting stuff as the default. print!() and
println!() should just take a variable number of arguments, and each
one should be printed in its default string representation with a
space between each one. This is how Clojure's (and Python's?) print
and println work.

This would change code like this: println!("The result is %f", foo);
to this: println!("The result is", foo)

It's much easier. There are no formatting codes to remember and it
does exaclty what you want in most cases. Consider: println!(a, ,b, c,
"d=", d); This seems great for the standard printf-style debugging.

If formatting is needed, it's easy to get to:
println!("My name is",  name, "and I scored", fmt!("%0.2f", score));

2) Since println!() is likely to be used the most often, I feel like
it should have a shorter name. Ie, we should call it just print!(),
and have a newline-less version with a different name, or perhaps a
different style of invocation of the macro.

I like this.

For comparison, Python 3 has a single print() function that takes a variable number of positional parameters (including zero), and two optional keyword-only parameters sep=' ' and end='\n'.

In my experience 'end' is not used often. When it is, it is most often set to the emtpty string. 'sep' is even less used. So maybe it’s okay to not have so much flexibility, and require complex cases to fall back on fmt!()


--
Simon Sapin
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to