www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Higher level built-in strings

reply Marianne Gagnon <auria.mg gmail.com> writes:
Pragmatically, I seem to have noted that in languages with low level strings,
people invariably come up with librairies that provide higher-level strings.
C/C++ provided low-level strings only initially, then a not-so-powerful
std::string; and we saw QString, wxString, irr::string, BetterString, countless
others...

Java, on the other end, provided a powerful high-level String object from the
start; and to my knowledge it is used consistently in all Java programs with no
other string classes being made.

I do acknowlegde that D arrays are much better than C/C++ arrays. Still, my
prediction is that if D chooses to stick to C-style function calls, and does
not provide a standard high-level String object, then a myriad of string
objects will start popping around. Because lots of people like OOP and don't
like C-style calls.

Just my 2c :) I mean be wrong

-- Auria

Walter Bright Wrote:

 Strings in D are deliberately meant to be arrays, not special things. Other 
 languages make them special because they have insufficiently powerful arrays.
 
 As for indexing by code point, I also believe this is a mistake. It is
proposed 
 often, but overlooks:
 
 1. most string operations, such as copying and searching, even regular 
 expressions, work just fine using regular indices.
 
 2. doing the operations in (1) using code points and having to continually 
 decode the strings would result in disastrously slow code.
 
 3. the user can always layer a code point interface over the strings, but
going 
 the other way is not so practical.

Jul 19 2010
parent Jonathan M Davis <jmdavisprog gmail.com> writes:
On Monday, July 19, 2010 16:49:58 Marianne Gagnon wrote:
 Pragmatically, I seem to have noted that in languages with low level
 strings, people invariably come up with librairies that provide
 higher-level strings. C/C++ provided low-level strings only initially,
 then a not-so-powerful std::string; and we saw QString, wxString,
 irr::string, BetterString, countless others...
 
 Java, on the other end, provided a powerful high-level String object from
 the start; and to my knowledge it is used consistently in all Java
 programs with no other string classes being made.
 
 I do acknowlegde that D arrays are much better than C/C++ arrays. Still, my
 prediction is that if D chooses to stick to C-style function calls, and
 does not provide a standard high-level String object, then a myriad of
 string objects will start popping around. Because lots of people like OOP
 and don't like C-style calls.
 
 Just my 2c :) I mean be wrong
 
 -- Auria

For the most part, D's strings are plenty high level. Between how fantastic D's arrays are and the fact that you can call functions on them as if they were objects, D's strings are quite high level in terms of how you use them. Their solution for how to deal with unicode is also quite powerful. The problem is that the solution for how to deal with unicode makes it so that if you try and deal with individual chars or wchars, you're going to very quickly shoot yourself in the foot. If you want to avoid the problem entirely, you simply use dstring and they're at least as powerful - and arguably more so - than Java's strings. The only issue with strings in D that I'm aware of is the danger with trying to deal with individual characters. But their are lots of great functions for dealing with strings, and they allow you to easily deal with individual characters by just using them as single-character strings rather than as chars or wchars. On the whole, D's strings are the best strings that I've used. - Jonathan M Davis
Jul 19 2010