Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D naming conventions: How is Phobos organized?

Tags:

d

phobos

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?

like image 731
user541686 Avatar asked Aug 07 '11 20:08

user541686


People also ask

Is naming a 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 do we have naming conventions?

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.


1 Answers

  • 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

like image 166
ratchet freak Avatar answered Sep 29 '22 11:09

ratchet freak