Naming of new lazy versions of existing Phobos functions
Tourist via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jul 18 12:40:45 PDT 2014
On Thursday, 17 July 2014 at 22:59:27 UTC, Brad Anderson wrote:
> Walter's prototype[1] for removing allocations from a phobos
> function (std.path.setExtension) got hung up on the naming of
> the function. It couldn't keep the same name because it
> differed only by return type.
>
> Walter doesn't like explicitly naming them as lazy because
> existing lazy functions like most of std.algorithm don't have
> names that state they are lazy. On the other hand, setExt is
> controversial because it's an arbitrary abbreviation done just
> to avoid the naming conflict. Not every function we'd like to
> see adopt the same approach would be amenable to a simple
> abbreviation to dodge the naming issue.
>
> I think it's probably a good time to come up with a naming
> scheme for these lazy versions of existing functions so things
> are consistent throughout Phobos.
>
> David Nadlinger offered a few ideas in the thread:
> setExtensionLazy, extensionSetter, or withExtension.
>
> I find the "with" prefix particularly attractive. It implies
> the lazy behavior, is short, and reads well when chained with
> other calls. Hypothetical example I gave in the Pull Request
> comments:
>
> auto contents =
> " FILE".withStrip()
> .withLowercase()
> .withExtension(".txt")
> .readText();
>
> At the risk of bikeshedding, I thought it would be useful to
> solicit the wider forum audience for ideas and opinions.
> Thoughts?
>
> 1. https://github.com/D-Programming-Language/phobos/pull/2149
Are you planning to deprecate the non-lazy functions at some
(maybe very distant) point? If yes, I agree that it's a good
opportunity for a cleanup, and there's no point to add
prefixes/suffixes.
More information about the Digitalmars-d
mailing list