Is str ~ regex the root of all evil, or the leaf of all good?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Feb 19 19:21:22 PST 2009


Christopher Wright wrote:
> Denis Koroskin wrote:
>> On Thu, 19 Feb 2009 15:00:42 +0300, Christopher Wright 
>> <dhasenan at gmail.com> wrote:
>>
>>> Denis Koroskin wrote:
>>>> "abracazoo".match("a[b-e]", "g") is as short as "abracazoo" ~ 
>>>> regex("a[b-e]", "g") but doesn't existing conventions. I prefer it 
>>>> over '~' version. In is also fine (both ways).
>>>
>>> This isn't so good for two reasons.
>>> First, I can't reuse regexes in your way, so if there is any 
>>> expensive initialization, that is duplicated.
>>>
>>> Second, I can't reuse regexes in your way, so I have to use a pair of 
>>> string constants.
>>
>> auto re = regex("a[b-e]", "g");
>> foreach (e; "abracazoo".match(re)) {
>>     // what's wrong with that?
>> }
> 
> Your first example was:
> auto match (char[] source, char[] pattern, char[] options);
> 
> Your second example was:
> auto match (char[] source, regex expression);
> 
> The second is good, but more typing than you said originally. The first 
> is problematic.

Why is it problematic? Is the name "match" too common?

Andrei



More information about the Digitalmars-d mailing list