On Sat, Jul 13, 2013 at 10:39 PM, Jack Moffitt <j...@metajack.im> wrote: > I saw https://github.com/mozilla/rust/pull/7779 come up today and > commented on it. I got to thinking about it some, and since the bug > doesn't seem the right place for such discussion, I wanted to bring it > up here. > > The PR proposes to rename print!() and println!() to printf!() and > printfln!(). The original macros exist to replace uses of print() and > println() that look like: println(fmt!("blah blah %s", s)); > > Having a good default way to print things is very important, and it's > one of the first things people will see of the language. I think it's > worth bikeshedding it a bit to see if we can't come up with something > better than the status quo. > > 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. > > > As some data to ponder, I went through the Servo code and all its > dependencies: > > - The dependencies of servo use println 42 times, 24 of which also use > fmt!(). None of these need to use fmt!() at all, they could just use > the default string representation. > > - Servo itself uses println about 10 times, only two of which need > fmt!(). These two uses are both fancy formatted output for the > profiler. > > Changing all these uses to print!() in the codebase (aside from the > two profiler fmt!()s) would make things much nicer looking. > > jack.
Without format strings as the primary way to do output, I think we'll fall down really short on the ability to do internationalization. _______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev