Naming of new lazy versions of existing Phobos functions
Brad Anderson via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 17 15:59:26 PDT 2014
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
More information about the Digitalmars-d
mailing list