D-ish way to work with strings?

Robert M. Münch robert.muench at saphirion.com
Fri Dec 27 12:18:21 UTC 2019


On 2019-12-22 18:45:52 +0000, Steven Schveighoffer said:

> switch to using char[]. Unfortunately, there's a lot of code out there 
> that accepts string instead of const(char)[], which is more usable. I 
> think many people don't realize the purpose of the string type. It's 
> meant to be something that is heap-allocated (or as a global), and 
> NEVER goes out of scope.

Hi Steve, thanks for the feedback. Makes sense to me.

> It really depends on your use cases. strings are great precisely 
> because they don't change. slicing makes huge sense there.

My "strings" change a lot, so not really a good fit to use string.

> Again, use char[] if you are going to be rearranging strings. And you 
> have to take care not to cheat and cast to string. Always use idup if 
> you need one.

Will do.

> If you find Phobos functions that unnecessarily take string instead of 
> const(char)[] please post to bugzilla.

Ok, will keep an eye on it.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



More information about the Digitalmars-d-learn mailing list