www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Auto-Resizing String...

reply Joe Somewhere.com writes:
I have no idea if this has been posted before and can't search. But I don't
understand why auto-resizing strings are not available in D. I mean in this day
and age, string usage is an extremely common task therefore worrying about if
your char array is big enough is annoying. Also, char overflows are a common
problem in C and therefore something that needs addressing. So why on earth
wouldn't you have a built in string type where it is impossible to overflow. It
would also make it easier for people from any other background (BASIC, C++, C#)
to move to D because they can get their heads around string more easily than
char. 

The char type is also OVERLY complex. Although the char type clearly is
required, it is harder to read. 

char[100] thingy = ""; 
thingy ~= Input; 

string thingy = ""; 
thingy += Input; 

This is not a good example but in complex code, strings are easier to read and
use. I just think for a new language in 2004 to NOT include a string type is
just insane.
May 06 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
Joe Somewhere.com wrote:

I have no idea if this has been posted before and can't search. But I don't
understand why auto-resizing strings are not available in D. I mean in this day
and age, string usage is an extremely common task therefore worrying about if
your char array is big enough is annoying. Also, char overflows are a common
problem in C and therefore something that needs addressing. So why on earth
wouldn't you have a built in string type where it is impossible to overflow. It
would also make it easier for people from any other background (BASIC, C++, C#)
to move to D because they can get their heads around string more easily than
char. 

The char type is also OVERLY complex. Although the char type clearly is
required, it is harder to read. 

char[100] thingy = ""; 
thingy ~= Input; 

string thingy = ""; 
thingy += Input; 

This is not a good example but in complex code, strings are easier to read and
use. I just think for a new language in 2004 to NOT include a string type is
just insane.
  

Hu? Why not create an alias if you don't like the name char []? Overflow? I've never had an overflow with char []. char [] are resizable strings. It's just a difference of names. Are you arguing for a name change? -- -Anderson: http://badmama.com.au/~anderson/
May 06 2004
prev sibling next sibling parent Norbert Nemec <Norbert.Nemec gmx.de> writes:
Joe Somewhere.com wrote:

 I have no idea if this has been posted before and can't search. But I
 don't understand why auto-resizing strings are not available in D. I mean
 in this day and age, string usage is an extremely common task therefore
 worrying about if your char array is big enough is annoying. Also, char
 overflows are a common problem in C and therefore something that needs
 addressing. So why on earth wouldn't you have a built in string type where
 it is impossible to overflow. It would also make it easier for people from
 any other background (BASIC, C++, C#) to move to D because they can get
 their heads around string more easily than char.
 
 The char type is also OVERLY complex. Although the char type clearly is
 required, it is harder to read.
 
 char[100] thingy = "";
 thingy ~= Input;
 
 string thingy = "";
 thingy += Input;
 
 This is not a good example but in complex code, strings are easier to read
 and use. I just think for a new language in 2004 to NOT include a string
 type is just insane.

try char[] thingy = ""; thingy ~= Input; what happens internally is, that char[] is basically a char* together with the range of the array. The ~ operator allocates new space on the heap copies the content of both string there and returns a reference to that space which is then assigned to thingy. char[] bahaves just as you would expect it from a string type. If you want to, you can just to a alias char[] string; to get what you ask for.
May 06 2004
prev sibling parent Chris Lawson <cl mangler.tinfoilhat.ca> writes:
Joe Somewhere.com wrote:

 I have no idea if this has been posted before and can't search. But I don't
 understand why auto-resizing strings are not available in D. I mean in this day
 and age, string usage is an extremely common task therefore worrying about if
 your char array is big enough is annoying. Also, char overflows are a common
 problem in C and therefore something that needs addressing. So why on earth
 wouldn't you have a built in string type where it is impossible to overflow. It
 would also make it easier for people from any other background (BASIC, C++, C#)
 to move to D because they can get their heads around string more easily than
 char. 
 
 The char type is also OVERLY complex. Although the char type clearly is
 required, it is harder to read. 
 
 char[100] thingy = ""; 
 thingy ~= Input; 
 
 string thingy = ""; 
 thingy += Input; 
 
 This is not a good example but in complex code, strings are easier to read and
 use. I just think for a new language in 2004 to NOT include a string type is
 just insane.
 
 

scroll down to the Strings section. HTH, Chris
May 06 2004