On 07/13/2013 10:39 PM, Jack Moffitt wrote:
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.
Well, you could also do it D's way:
writefln("The result is %s", foo);
Where "%s" grabs the "default string representation" (note that is is
very unlike "%?" in Rust). You (in all cases your proposal would work)
don't need to remember any other formatting codes. Or you can do Tango's
way (a D library):
Stdout.formatln("The result is {}", foo);
Where "{}" does the same as above. I think separating formatting from
values is a valid approach that I sometimes (but not always) prefer
using. Just like Brendan in another email, I'd prefer both the
formatting and the non-formatting macros to exist, with the following
semantics:
print!(a, b, c); // grabs the default string representation and puts a
space between each one
print!(); // prints nothing
printf!("a = %f", a); // prints using the format string
printf!("a"); // prints just the format string
printf!(a); // illegal (or, alternatively grabs the default string
representation of a and uses it as the format string, especially if you
want to use this for gettext-like functionality)
printf!(a, b); // same as above
printf!(); // illegal
Speaking of "default string representation", it'd be only useful if it
is obtained via a trait like ToStr (but with a writer interface, for
efficiency). Using "%?" outside of debugging is almost never what I want
(it's unsafe anyway). It'd allow for an efficient implementation of fmt!
too (when used with this macro).
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'd prefer "ln" to stay, as it makes it clear what is happening. As a
newcomer to python (and bash with it's echo) I always have to double
check whether or not it outputs a newline. I like the documentation
benefit of keeping the name.
-SL
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev