standard ranges

Jonathan M Davis jmdavisProg at gmx.com
Wed Jun 27 18:48:54 PDT 2012


On Wednesday, June 27, 2012 23:41:14 Timon Gehr wrote:
> On 06/27/2012 11:11 PM, Steven Schveighoffer wrote:
> > When most string functions take strings, why would you want to use
> > immutable(char)[] everywhere?
> 
> Because the proposed 'string' interface is inconvenient to use and
> useless. It is a struct with one data member and no additionally
> maintained invariant, and it strictly narrows the essential parts of
> the interface to the data that is reachable without a large typing
> overhead. immutable(char)[] supports exactly the operations I usually
> need. Maybe I'm not representative.

I think that a lot of programmers want to be able to use strings without 
worrying about any of the details (like unicode). The fact that foreach and 
the library don't treat strings the same is confusing, and the fact that 
narrow strings are ranges of dchar (with all that that implies with regards to 
the operations that they support) seems to confuse a lot of people. If we had 
a struct for a string type, then the usage would be consistent (always a range 
of dchar), allowing the average programmer to more or less ignore unicode 
considerations as long as they don't care about efficiency, but it would still 
allow those who _do_ care to get at the underlying representation. So, a 
struct would be an improvement in that regard.

But for those who know what they're doing with regards to unicode and 
understand the fact that foreach treats strings one way and the library treats 
them another way, it really isn't a problem. It works quite well (which is one 
of the reasons that Walter isn't too keen on changing strings). It just isn't 
terribly newbie-friendly.

- Jonathan M Davis


More information about the Digitalmars-d mailing list