Should this work?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Jan 9 21:48:51 PST 2014


On 1/9/14 8:21 AM, Manu wrote:
> My standing opinion is that string manipulation in D is not nice, it is
> possibly the most difficult and time consuming I have used in any
> language ever. Am I alone?

No, but probably in the minority.

The long and short of it is, you must get ranges in order to enjoy the 
power of D algorithms (as per http://goo.gl/dVprVT).

std.{algorithm,range} are commonly mentioned as an attractive asset of 
D, and those who get that style of doing things have no trouble applying 
such notions to a variety of data, notably including strings. So going 
with the attitude "I don't use, know, or care for phobos... I just want 
to do this pesky string thing!" is bound to create frustration.

I personally find strings very easy to deal with in D. They might be 
easier in Perl or sometimes Python, but at a steep efficiency cost.

Walter has recently written a non-trivial utility that beats the pants 
off (3x performance) the equivalent C program that has been highly 
scrutinized and honed for literally decades by dozens (hundreds?) of 
professionals. Walter's implementations uses ranges and algorithms (a 
few standard, many custom) through and through. If all goes well we'll 
open-source it. He himself is now an range/algorithm convert, even 
though he'd be the first to point the no-nonsense nature of a function 
like strrchr. (And btw strrchr is after all a POS because it needs to 
scan the string left to right... so lastIndex is faster!)


Andrei



More information about the Digitalmars-d mailing list