CRUD Method Naming Guidelines - adsicks/gambas-json GitHub Wiki

Background

CRUD refers to the four basic functions of persistent storage. It also describes the basic functions used to interact with an object representing such data. This term has resurfaced with the popularity of RESTful API’s and describe the basic functionality of such API’s and their relationship to the underlying data.

Self-documenting code allows programmers to focus their creativity on designing good logical structures without creating ambiguity in the palate of tools available in a given context. Precision in naming class methods is important to this process. Using the CRUD framework as a guide, here are some precise definitions of various words commonly used to name classes. This will demonstrate the subtle differences between how programmers interpret these names and what they expect these methods to do.

These naming guidelines should be used for all objects:

  • Storage layer
  • Representational layer
  • API layer
  • GUI/UI layer.

Creation Methods

New – Creates an empty document that can accept entities.

Create – Creates an empty instance of an entity. Paramount to the New keyword in OOP.

Add – Adds an existing entity to the recordset. Takes parameters such that it can insert at a given point or append to the end. e.g., add(key, value, Optional parent).

Insert – Inserts an existing entity to a given location. e.g., Insert(key, value, parent).

Append – Adds an existing entity to the end of a recordset. e.g., Append(key, value).

Replicate – Creates a copy of the entire object into another object.

Read Methods

Browse – Returns all records from the top level.

Read – Returns a named value.

View – Returns the names of a subtree without the value.

Update Methods

Edit – Changes the data in a given record.

Update – Commits the current edits to the object.

Process – Uses procedural logic to edit the contents of zero or more records.

Delete Methods

Delete – Deletes the reference to the record from the hash table. Usually has an Undelete method and mechanism, but maybe not always.

Remove – Removes the record from the object and moves the copy to another location. Tantamount to a cut to the clipboard.

Destroy – Deletes all references and data associated with the record. Not recoverable as Delete might be.