ProfileGem icon indicating copy to clipboard operation
ProfileGem copied to clipboard

Review code style, refactor functions into namespaces

Open dimo414 opened this issue 10 years ago • 3 comments

Original report by Michael Diamond (Bitbucket: dimo414).


Reference https://google.github.io/styleguide/shell.xml

The Google Style Guide suggests using :: to delimit function namespaces, but that prevents tab-completion¹ (perhaps that's an advantage?). . seems to be a common choice which does enable tab-completion.

¹ See Bash FAQ E13 and https://stackoverflow.com/a/12495727

dimo414 avatar Dec 10 '15 20:12 dimo414

Original comment by Michael Diamond (Bitbucket: dimo414).


There are really a couple different namespaces to support:

  • __pgem::: truly private, used only internally by ProfileGem (e.g. the functions in privateGemFunctions.sh and other helpers)
  • _pgem_: Utility functions intended to be used by gems
  • pgem_: User-facing functions intended to be called interactively

dimo414 avatar Aug 22 '17 20:08 dimo414

Original comment by Michael Diamond (Bitbucket: dimo414).


Gems should also have standard namespaces:

  • __foo_gem:: for foo.gem's private fields
  • _foo_gem_ for fields that will be accessed by other gems
  • User-facing functions and variables should not be namespaced

dimo414 avatar Nov 03 '17 05:11 dimo414

Original comment by Michael Diamond (Bitbucket: dimo414).


Different plan, along the lines of bash-cache:

  • pg::_foo for private helper functions
  • pg::foo for non-interactive functions such as those used by gems
  • pgem_foo for user-facing functions

Gems should similarly use a bar:: namespace (where "bar" is the name of the gem) for non-user-facing functions.

NB pg is a standard Unix command, so pg shouldn't be used directly.

dimo414 avatar Jun 04 '18 06:06 dimo414