digitalmars.D.learn - writeln and ~
- Ignacious (13/13) Jan 14 2017 string concatenation is weird.
- Adam D. Ruppe (7/12) Jan 14 2017 You'd be liable to write buggy stuff like appending the wrong
- thedeemon (4/5) Jan 14 2017 Just write writeln(x, " ok");
- Era Scarecrow (5/7) Jan 14 2017 Somehow I think that everything implicitly converting to a
string concatenation is weird. We can do stuff like writeln(x); where x is, say a struct and it prints fine but when we do writeln(x ~ " ok"); it fails and requires us to convert x! Why can't string concatenation automatically try to convert the arguments? Is there any reason this is bad behavior? How bout then having writeln parse the arguments as a string(take an alias or something first) and then automatically convert them? Seems like there is no real excuse to add such obfuscation... Obviously I can roll my own but that is not an acceptable answer.
Jan 14 2017
On Saturday, 14 January 2017 at 17:42:05 UTC, Ignacious wrote:Why can't string concatenation automatically try to convert the arguments? Is there any reason this is bad behavior?You'd be liable to write buggy stuff like appending the wrong kind of array since the auto conversion was wrong.How bout then having writeln parse the arguments as a string(take an alias or something first) and then automatically convert them?writeln already knows how to convert. There's also a std.conv.text function that returns the string instead of printing it. http://dpldocs.info/experimental-docs/std.conv.text.html
Jan 14 2017
On Saturday, 14 January 2017 at 17:42:05 UTC, Ignacious wrote:writeln(x ~ " ok");Just write writeln(x, " ok"); Any number of arguments, no unnecessary allocations. Do you really need ~?
Jan 14 2017
On Saturday, 14 January 2017 at 17:42:05 UTC, Ignacious wrote:Why can't string concatenation automatically try to convert the arguments? Is there any reason this is bad behavior?Somehow I think that everything implicitly converting to a string seems like a bad idea. Although writefln and writeln using ,'s seems like better ideas than some minor JavaScript convenience.
Jan 14 2017