string initialization question.

Jonathan M Davis jmdavisprog at gmail.com
Fri Jul 30 16:30:17 PDT 2010


On Friday, July 30, 2010 14:13:15 dcoder wrote:
> If I'm writing a program that pretty prints tree data, or output of sql,
> like Oracle's sqlplus, or postgres equivalent, I find having such a
> utility function/constructor a pretty handy feature.
> 
> I don't know where such a tool should finally be placed in D, but I having
> it available as a library or as part of the language would be great.  It
> seems like a lot of other languages have it like python, perl, C++, and
> Java.  So it can't be that useless.

Well, I certainly have no problem with a function like makeArray() existing. 
It's just that it's one of those functions that I've never found useful, and I 
don't think that I've ever seen anyone use it in code.

Now, for strings, I find such a function to be a bit dangerous since it's 
ignoring the fact that char is a UTF-8 code unit rather than an ASCII value, but 
for other types of arrays, that wouldn't be a problem. And for strings, you 
could either use dstrings or just be certain that all of your characters are 
actually a single code unit. But I certainly wouldn't want the equivalent of 
having a string constructor that takes a char and a count like C++'s string 
does. It would be fine in many cases, but string functions that take chars are 
generally asking for trouble due to unicode issues. But since, string in D is an 
array rather than a class, that's not really a problem in the same way. 
makeArray() being for arrays in general rather than specifically strings would 
not promote bad string code in the same way that C++'s string constructor does.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list