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?
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 wellbut 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?
A naming convention is a convention (generally agreed scheme) for naming things. Conventions differ in their intents, which may include to: Allow useful information to be deduced from the names based on regularities.
Why use naming conventions? Naming records consistently, logically and in a predictable way will distinguish similar records from one another at a glance, and by doing so will facilitate the storage and retrieval of records, which will enable users to browse file names more effectively and efficiently.
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 ranges
these 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 range
this 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With