July 07, 2008
Correct me if I'm wrong, but I think the forthcoming support for overload sets and free functions will allow definition of a simple module to alleviate this.

import somewhere.easyconcat;

defining a bunch of extra opCats for simple types.


On Sun, Jul 6, 2008 at 9:30 PM, Frank Benoit <keinfarbton@googlemail.com> wrote:
> String concatenation in Java:
>
> "abc " + a + " bla";
>
> where a is an interface ref.
>
> Ported to D, this look like this:
>
> "abc " ~ (cast(Object)a).toString ~ " bla";
>
> This are 3 steps more:
> 1.) explicit cast to Object (interface/class compatibility!)
> 2.) explicit call to toString
> 3.) put additional parentheses
>
> I would be happy if we could remove all three of this annoying points.
>



-- 
Science without religion is lame, religion without science is blind.
 — Einstein

July 07, 2008
superdan, el  6 de julio a las 18:12 me escribiste:
> > Those are the cases I find D not nice.
> 
> yarp i concur. phobos oughtta have a function asStr that converts everything to string and concats. then you write:
> 
> auto x = asStr("You pressed button ", i, " with your pinky toe");


That sounds like a poor's man version of the python's built-in formatting capabilities:

x = "You pressed button %d with your pinky toe" % i

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Dale tu mano al mono, pero no el codo, dado que un mono confianzudo es
irreversible.
	-- Ricardo Vaporeso. La Reja, Agosto de 1912.
July 07, 2008
"Leandro Lucarella" <llucax@gmail.com> wrote in message news:20080707163413.GB17001@burns.springfield.home...
> superdan, el  6 de julio a las 18:12 me escribiste:
>> > Those are the cases I find D not nice.
>>
>> yarp i concur. phobos oughtta have a function asStr that converts everything to string and concats. then you write:
>>
>> auto x = asStr("You pressed button ", i, " with your pinky toe");
>
>
> That sounds like a poor's man version of the python's built-in formatting capabilities:
>
> x = "You pressed button %d with your pinky toe" % i

What can python's formatting operator do that std.string.format cannot?


July 07, 2008
Jarrett Billingsley, el  7 de julio a las 12:37 me escribiste:
> >> auto x = asStr("You pressed button ", i, " with your pinky toe");
> >
> >
> > That sounds like a poor's man version of the python's built-in formatting capabilities:
> >
> > x = "You pressed button %d with your pinky toe" % i
> 
> What can python's formatting operator do that std.string.format cannot?

Nothing I guess. I was talking about the nicer syntax =)

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
You can do better than me. You could throw a dart out the window and hit
someone better than me. I'm no good!
	-- George Constanza
July 07, 2008
On Mon, 07 Jul 2008 03:12:27 +0400, superdan <super@dan.org> wrote:

> downs Wrote:
>
>> superdan wrote:
>> > Ary Borenszweig Wrote:
>> >
>> >> Frank Benoit a écrit :
>> >>> String concatenation in Java:
>> >>>
>> >>> "abc " + a + " bla";
>> >>>
>> >>> where a is an interface ref.
>> >>>
>> >>> Ported to D, this look like this:
>> >>>
>> >>> "abc " ~ (cast(Object)a).toString ~ " bla";
>> >>>
>> >>> This are 3 steps more:
>> >>> 1.) explicit cast to Object (interface/class compatibility!)
>> >>> 2.) explicit call to toString
>> >>> 3.) put additional parentheses
>> >>>
>> >>> I would be happy if we could remove all three of this annoying  
>> points.
>> >> Exactly the same thought here. Also:
>> >>
>> >> int i = ...;
>> >> char[] x = "You pressed button " + i;
>> >>
>> >> Oops... doesn't compile. To fix it:
>> >>
>> >> import std.string;
>> >>
>> >> int i = ...;
>> >> char[] x = "You pressed button " + toString(i);
>> >>
>> >> But wait, if that piece of code is inside a method of a class, than
>> >> (WHY?) it thinks it's the toString() method, so you end up writing:
>> >>
>> >> import std.string;
>> >>
>> >> int i = ...;
>> >> char[] x = "You pressed button " + std.string.toString(i);
>> >>
>> >> Those are the cases I find D not nice.
>> >
>> > yarp i concur. phobos oughtta have a function asStr that converts  
>> everything to string and concats. then you write:
>> >
>> > auto x = asStr("You pressed button ", i, " with your pinky toe");
>> >
>>
>> This is also known as std.string.format.
>
> narp that interprets %s and shit which can quickly become dangerous.

No, unlike printf-family functions, writef/std.string.format and other D counterparts *are* type-safe, so you can use %s with strings, ints, longs, Objects, i.e. with just _anything_.

> you'd have to say
>
> auto x = format("", ........);
>

class Dude {}
auto greeting = format("Hello, %s!", new Dude());

> i also agree with ary that infix could help a ton. but then it would confuse noobs. can't please everyone. life's a bitch.
July 07, 2008
Koroskin Denis Wrote:

> On Mon, 07 Jul 2008 03:12:27 +0400, superdan <super@dan.org> wrote:
> 
> > downs Wrote:
> >
> >> superdan wrote:
> >> > Ary Borenszweig Wrote:
> >> >
> >> >> Frank Benoit a écrit :
> >> >>> String concatenation in Java:
> >> >>>
> >> >>> "abc " + a + " bla";
> >> >>>
> >> >>> where a is an interface ref.
> >> >>>
> >> >>> Ported to D, this look like this:
> >> >>>
> >> >>> "abc " ~ (cast(Object)a).toString ~ " bla";
> >> >>>
> >> >>> This are 3 steps more:
> >> >>> 1.) explicit cast to Object (interface/class compatibility!)
> >> >>> 2.) explicit call to toString
> >> >>> 3.) put additional parentheses
> >> >>>
> >> >>> I would be happy if we could remove all three of this annoying
> >> points.
> >> >> Exactly the same thought here. Also:
> >> >>
> >> >> int i = ...;
> >> >> char[] x = "You pressed button " + i;
> >> >>
> >> >> Oops... doesn't compile. To fix it:
> >> >>
> >> >> import std.string;
> >> >>
> >> >> int i = ...;
> >> >> char[] x = "You pressed button " + toString(i);
> >> >>
> >> >> But wait, if that piece of code is inside a method of a class, than
> >> >> (WHY?) it thinks it's the toString() method, so you end up writing:
> >> >>
> >> >> import std.string;
> >> >>
> >> >> int i = ...;
> >> >> char[] x = "You pressed button " + std.string.toString(i);
> >> >>
> >> >> Those are the cases I find D not nice.
> >> >
> >> > yarp i concur. phobos oughtta have a function asStr that converts
> >> everything to string and concats. then you write:
> >> >
> >> > auto x = asStr("You pressed button ", i, " with your pinky toe");
> >> >
> >>
> >> This is also known as std.string.format.
> >
> > narp that interprets %s and shit which can quickly become dangerous.
> 
> No, unlike printf-family functions, writef/std.string.format and other D counterparts *are* type-safe, so you can use %s with strings, ints, longs, Objects, i.e. with just _anything_.

narp i meant something else. maybe dangerous was not the appropriate word. let's say surprising.

import std.stdio, std.string;

void main()
{
    string shit = "I embed a %s thing";
    // ...
    writeln(format("innocent formatting string ", shit));
}

this will fail dynamically. the problem is that any string argument is searched for %. that bad behavior was fixed in writefln but not in string.format. writefln only parses its first string for % shit but not the others. as it should.

> > you'd have to say
> >
> > auto x = format("", ........);
> >
> 
> class Dude {}
> auto greeting = format("Hello, %s!", new Dude());

not sure what that illustrates but i also realize my fix was wrong. again all strings will be parsed for % shit. that blows.
July 08, 2008
"superdan" <super@dan.org> wrote in message news:g4u4t3$1aln$1@digitalmars.com...
> Koroskin Denis Wrote:
>
>> On Mon, 07 Jul 2008 03:12:27 +0400, superdan <super@dan.org> wrote:
>>
>> > downs Wrote:
>> >
>> >> superdan wrote:
>> >> > Ary Borenszweig Wrote:
>> >> >
>> >> >> Frank Benoit a écrit :
>> >> >>> String concatenation in Java:
>> >> >>>
>> >> >>> "abc " + a + " bla";
>> >> >>>
>> >> >>> where a is an interface ref.
>> >> >>>
>> >> >>> Ported to D, this look like this:
>> >> >>>
>> >> >>> "abc " ~ (cast(Object)a).toString ~ " bla";
>> >> >>>
>> >> >>> This are 3 steps more:
>> >> >>> 1.) explicit cast to Object (interface/class compatibility!)
>> >> >>> 2.) explicit call to toString
>> >> >>> 3.) put additional parentheses
>> >> >>>
>> >> >>> I would be happy if we could remove all three of this annoying
>> >> points.
>> >> >> Exactly the same thought here. Also:
>> >> >>
>> >> >> int i = ...;
>> >> >> char[] x = "You pressed button " + i;
>> >> >>
>> >> >> Oops... doesn't compile. To fix it:
>> >> >>
>> >> >> import std.string;
>> >> >>
>> >> >> int i = ...;
>> >> >> char[] x = "You pressed button " + toString(i);
>> >> >>
>> >> >> But wait, if that piece of code is inside a method of a class, than
>> >> >> (WHY?) it thinks it's the toString() method, so you end up writing:
>> >> >>
>> >> >> import std.string;
>> >> >>
>> >> >> int i = ...;
>> >> >> char[] x = "You pressed button " + std.string.toString(i);
>> >> >>
>> >> >> Those are the cases I find D not nice.
>> >> >
>> >> > yarp i concur. phobos oughtta have a function asStr that converts
>> >> everything to string and concats. then you write:
>> >> >
>> >> > auto x = asStr("You pressed button ", i, " with your pinky toe");
>> >> >
>> >>
>> >> This is also known as std.string.format.
>> >
>> > narp that interprets %s and shit which can quickly become dangerous.
>>
>> No, unlike printf-family functions, writef/std.string.format and other D
>> counterparts *are* type-safe, so you can use %s with strings, ints,
>> longs,
>> Objects, i.e. with just _anything_.
>
> narp i meant something else. maybe dangerous was not the appropriate word. let's say surprising.
>
> import std.stdio, std.string;
>
> void main()
> {
>    string shit = "I embed a %s thing";
>    // ...
>    writeln(format("innocent formatting string ", shit));
> }
>
> this will fail dynamically. the problem is that any string argument is searched for %. that bad behavior was fixed in writefln but not in string.format. writefln only parses its first string for % shit but not the others. as it should.

If that's true and hasn't been fixed, you should probably submit a bugzilla report if you/someone else hasn't already.


July 08, 2008
"Nick Sabalausky" <a@a.a> wrote in message news:g4uip0$2ag1$1@digitalmars.com...

>> import std.stdio, std.string;
>>
>> void main()
>> {
>>    string shit = "I embed a %s thing";
>>    // ...
>>    writeln(format("innocent formatting string ", shit));
>> }
>>
>> this will fail dynamically. the problem is that any string argument is searched for %. that bad behavior was fixed in writefln but not in string.format. writefln only parses its first string for % shit but not the others. as it should.
>
> If that's true and hasn't been fixed, you should probably submit a bugzilla report if you/someone else hasn't already.

It's true and expected behavior in phobos 1.  All strings are interpreted as format strings unless they themselves are formatted into another string using %s.  Phobos 2 only interprets the first parameter as a format string, so it won't break there.


July 08, 2008
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:g4ujs8$2d2m$1@digitalmars.com...
> "Nick Sabalausky" <a@a.a> wrote in message news:g4uip0$2ag1$1@digitalmars.com...
>
>>> import std.stdio, std.string;
>>>
>>> void main()
>>> {
>>>    string shit = "I embed a %s thing";
>>>    // ...
>>>    writeln(format("innocent formatting string ", shit));
>>> }
>>>
>>> this will fail dynamically. the problem is that any string argument is searched for %. that bad behavior was fixed in writefln but not in string.format. writefln only parses its first string for % shit but not the others. as it should.
>>
>> If that's true and hasn't been fixed, you should probably submit a bugzilla report if you/someone else hasn't already.
>
> It's true and expected behavior in phobos 1.  All strings are interpreted as format strings unless they themselves are formatted into another string using %s.  Phobos 2 only interprets the first parameter as a format string, so it won't break there.

Actually that seems only to be writefln in Phobos 2, not sure about format.


July 08, 2008
Frank Benoit wrote:
> String concatenation in Java:
> 
> "abc " + a + " bla";
> 
> where a is an interface ref.
> 
> Ported to D, this look like this:
> 
> "abc " ~ (cast(Object)a).toString ~ " bla";
> 
> This are 3 steps more:
> 1.) explicit cast to Object (interface/class compatibility!)
> 2.) explicit call to toString
> 3.) put additional parentheses
> 
> I would be happy if we could remove all three of this annoying points.

I agree, string handling could be better its such a common operation. Its one of worst things to work with in C++.  Implicit string conversions would make things much easier and more readable.

-Joel