开发者

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 algorithm
  • std.array: Because I'm likely going to use it on arrays
  • std.container: Because it's used on containers, rather than single objects
  • std.functional: Because it's used mainly in functional programming
  • std.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 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜