July 12, 2005
Walter I understand Your concerns, and apriciate Your work.

Recently I came to one great quote:

The language designer should be familiar with many alternative features designed by others, and should have excellent judgment in choosing the best and rejecting any that are mutually inconsistent... One thing he should not do is to include untried ideas of his own. His task is consolidation, not innovation. ---C.A.R. Hoare

I think You perfectly fit into this above. :)

Kind regards

Dejan

-- 
...........
Dejan Lekic
  http://dejan.lekic.org

July 12, 2005
In article <daud1v$1qp9$1@digitaldaemon.com>, Walter says...
>
>The problem with that is that implicit conversions will always be on, and one can inadvertently fall into the hole.

Two suggestions:

1) Don't solve this using a general approach, but only treat it as a specific case for easy string concatenation, i.e. implicit conversions only happen on toString() method.


2) Or, look at Python's approach:

sqlexec(" ... i = %d  f = %f ..." % (i, f));

It's kind of similar to formated printf, but more flexible.  Easy to write, easy to read, and easy to maintain.

Just as syntatic sugar to:

char[256] buf;
sprintf(buf, " ... i = %d  f = %f ...", i, f);
sqlexec(buf);

I'd vote for the 2nd Python's approach.


July 12, 2005
> 2) Or, look at Python's approach:
>
> sqlexec(" ... i = %d  f = %f ..." % (i, f));

import std.string;
...
sqlexec(format("i = %d f = %f",i,f));



July 12, 2005
In article <davaot$2k7h$1@digitaldaemon.com>, Ben Hinkle says...
>
>> 2) Or, look at Python's approach:
>>
>> sqlexec(" ... i = %d  f = %f ..." % (i, f));
>
>import std.string;
>...
>sqlexec(format("i = %d f = %f",i,f));

Ah, good to know it works! I hope this is close to what people asked to concat string more easily.

Sometimes I think perl's approach of embedding variable directly in string is also interesting:

sqlexec(" ... i = $i  f = $f ...");

of course you need an extra symbol '$' to indicate the variable.  But this approach is not as inconvinient as to write the whole casting expression explicitly, and is not as dangerous as implicit casting.  Probably something we can also consider?


July 12, 2005
Can anyone provide an example which demonstrates the danger of implicit conversion from an integer to a string?

Thanks,

Tony
Melbourne, Australia


July 12, 2005
On Tue, 12 Jul 2005 15:52:08 +1000, Tony <talktotony@email.com> wrote:
> Can anyone provide an example which demonstrates the danger of implicit
> conversion from an integer to a string?

Essentially any situation where the programmer makes a small error by accidently using the wrong variable, a number, where a string is required. In essence a typo.

void foo(float f, double d, char[] string, char[] string2, int num = 1) {}
void main()
{
	int a = 5;
	char[] b = "test";
	foo(1.0,2.2,b,a); //oops meant foo(1.0,2.2,b,"",a);
}

The compiler does not error on the above it silently converts the number to a string. Imagine if the parameters had longer names than "a" and "b", imagine short constants were not used but longer variable names, imagine more distance between function/variable declaration and function call.

Regan
July 12, 2005
In article <davlr5$2uo8$1@digitaldaemon.com>, Tony says...
>
>Can anyone provide an example which demonstrates the danger of implicit conversion from an integer to a string?
>
>Thanks,
>
long ident;
void foo(char[] data)
{
 . .
}
 . .
foo(msg ~ ident);  // Is this correct use of ident?

If 'ident' is implicitly converted to a string, it hides a potential mistake. Did the author use the wrong variable? Did they mean to use 'ident' or something else?

In the long run, and for the sake of maintence programmers everywhere, it pays to be explicit about your intentions.

e.g.
foo(msg ~ toString(ident));  // Now this is unambiguous.


July 12, 2005
>>sqlexec(" ... i = $i  f = $f ...");

Well it would be a good idea, but not in standard string.

Lets make a specian string
sqlexec('" ... i = $i  f = $f ..."');

the special string would be between '" "'
And there could be many special thinks about this special string, starting that
you can write variables directly into it.




In article <davidq$2rk0$1@digitaldaemon.com>, z@gg.com says...
>
>In article <davaot$2k7h$1@digitaldaemon.com>, Ben Hinkle says...
>>
>>> 2) Or, look at Python's approach:
>>>
>>> sqlexec(" ... i = %d  f = %f ..." % (i, f));
>>
>>import std.string;
>>...
>>sqlexec(format("i = %d f = %f",i,f));
>
>Ah, good to know it works! I hope this is close to what people asked to concat string more easily.
>
>Sometimes I think perl's approach of embedding variable directly in string is also interesting:
>
>sqlexec(" ... i = $i  f = $f ...");
>
>of course you need an extra symbol '$' to indicate the variable.  But this approach is not as inconvinient as to write the whole casting expression explicitly, and is not as dangerous as implicit casting.  Probably something we can also consider?
>
>


July 12, 2005
<z@gg.com> wrote in message news:davidq$2rk0$1@digitaldaemon.com...
> In article <davaot$2k7h$1@digitaldaemon.com>, Ben Hinkle says...
>>
>>> 2) Or, look at Python's approach:
>>>
>>> sqlexec(" ... i = %d  f = %f ..." % (i, f));
>>
>>import std.string;
>>...
>>sqlexec(format("i = %d f = %f",i,f));
>
> Ah, good to know it works! I hope this is close to what people asked to
> concat
> string more easily.
>
> Sometimes I think perl's approach of embedding variable directly in string
> is
> also interesting:
>
> sqlexec(" ... i = $i  f = $f ...");
>
> of course you need an extra symbol '$' to indicate the variable.  But this
> approach is not as inconvinient as to write the whole casting expression
> explicitly, and is not as dangerous as implicit casting.  Probably
> something we
> can also consider?

For completeness another way to write the above D example would be
sqlexec(format("i = ",i," f = ",f));
To me any of the above are pretty much equally readable.


July 12, 2005
>For completeness another way to write the above D example would be
>sqlexec(format("i = ",i," f = ",f));
>To me any of the above are pretty much equally readable.


Ok, what happens when you mess up the order?


sqlexec(format("i = ",i,uups," f = ",f));

Can easyly happen, quite serious error and hard detect.



in article <db0b05$i7j$1@digitaldaemon.com>, Ben Hinkle says...
>
>
><z@gg.com> wrote in message news:davidq$2rk0$1@digitaldaemon.com...
>> In article <davaot$2k7h$1@digitaldaemon.com>, Ben Hinkle says...
>>>
>>>> 2) Or, look at Python's approach:
>>>>
>>>> sqlexec(" ... i = %d  f = %f ..." % (i, f));
>>>
>>>import std.string;
>>>...
>>>sqlexec(format("i = %d f = %f",i,f));
>>
>> Ah, good to know it works! I hope this is close to what people asked to
>> concat
>> string more easily.
>>
>> Sometimes I think perl's approach of embedding variable directly in string
>> is
>> also interesting:
>>
>> sqlexec(" ... i = $i  f = $f ...");
>>
>> of course you need an extra symbol '$' to indicate the variable.  But this
>> approach is not as inconvinient as to write the whole casting expression
>> explicitly, and is not as dangerous as implicit casting.  Probably
>> something we
>> can also consider?
>
>For completeness another way to write the above D example would be
>sqlexec(format("i = ",i," f = ",f));
>To me any of the above are pretty much equally readable.
>
>