better string
Mike B Johnson via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jun 7 04:05:40 PDT 2017
On Wednesday, 7 June 2017 at 10:58:06 UTC, Mike B Johnson wrote:
> Why not alias string so that one can easily switch from the old
> string or wstring, etc?
>
> e.g., rename string internally to sstring or whatever.
>
> then globally define
>
> alias string = sstring;
>
> Which can be over realiased to wstring to affect the whole
> program
>
> alias string = wstring;
>
> Or use a command line to set it or whatever makes you happy.
>
> I'm in the progress of converting a large source code database
> to use the above technique so we can move to using wstring...
> it is not fun. Most code that works with a string should with
> any string encoding, so it shouldn't matter. Making D string
> agnostic(after all, the only main different in 99% of programs
> is the space they take up).
>
> If you are worried about it causing subtle bugs, then don't...
> because those same bugs would occur if one manually had to
> switch.
>
> By designing techniques to use strings that are agnostic of
> there internal representation should save a lot of headache.
> For those few cases that it matters, simple static analysis
> works fine.
I should mention, that with such a design, strings can default to
the string type, whatever it would be.
e.g.,
"this is a string"
depends on the "alias". If it is sstring then it is an sstring,
if it is wstring then it is a wstring.
Anything that returns a string will return it depend on the
alias, even templated functions such as
foreach(name; AliasSeq!(X.tupleof.stringof))
in which, generally makes name a sstring. (I suppose due to
stringof returning an sstring regardless).
More information about the Digitalmars-d
mailing list