D naming conventions: How is Phobos organized?
I'm making my own little library of handy functions and I'm trying to follow Phobos's naming convention but I'm getting really confused. How do I know where things would fit?
Exam开发者_高级运维ple:
If there was a function like foldRight
in Phobos (basically reduce
in the reverse direction), which module would I find it in?
I can think of several:
std.algorithm
: Because it's expressing an algorithmstd.array
: Because I'm likely going to use it on arraysstd.container
: Because it's used on containers, rather than single objectsstd.functional
: Because it's used mainly in functional programmingstd.range
: Because it operates on ranges as well
but I have no idea which one would be a good choice -- I could give a convincing argument for at least 3 of them.
What's the convention?
std.algorithm
: yep and you can implement it like reduce!fun(retro(r))this module specifies algorithms that run on sequences
std.array
: no because it can also run on other rangesthese are helper functions that run only on build-in arrays
std.container
: no because it doesn't define a data structure (like a treeset)this defines data structures that are not build in into the language (for now a linked list, a binary tree and a deterministic array in terms of memory management)
std.functional
: no because it doesn't operate on a function but on a rangethis one takes a function and returns a different one
std.range
: no because it doesn't define a range or provide a different way to iterate over one
the lack of a clear structure is one of my gripes with the phobos library TBH but really reading the first paragraph of the docs should tell you quite a bit of where to put the function
精彩评论