D naming conventions: How is Phobos organized?
Asked Answered
C

1

15

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?

Example:

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?

Contagium answered 7/8, 2011 at 20:43 Comment(0)
G
17
  • 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

Gingrich answered 7/8, 2011 at 21:16 Comment(1)
+1 I really didn't expect to get back sensible explanations, but they seem to make sense (for the most part anyway). Thanks!Contagium

© 2022 - 2024 — McMap. All rights reserved.