Conventions/code/naming: Difference between revisions

From Woozle Writes Code
Jump to navigation Jump to search
m (Woozle moved page Ferreteria/coding to Conventions/coding without leaving a redirect: where it belongs)
No edit summary
Line 1: Line 1:
For now, this is just notes on conventions I want to use within the code.
I tend to use the following naming conventions within my code, more or less in keeping with the Apps variation of {{l/wp|Hungarian notation}}.
 
==Prefixes==
==Prefixes==
===Variable Prefixes===
===Variable Prefixes===
* '''n''': a count (int); use f for float
* '''f''': floating-point number
* '''k''' or '''K''': a constant, i.e. anything whose value should not (or cannot) change once defined
* '''n''': a count (int; use f for float)
* '''o''': object
* '''o''': object
** '''or''': a '''ref''' object (see Value Types)
** '''or''': a '''ref''' object (see Value Types)
Line 17: Line 18:
** '''cs''': static class (not intended to be instantiable; all methods static)
** '''cs''': static class (not intended to be instantiable; all methods static)
* '''ch''': a string that is always a single character
* '''ch''': a string that is always a single character
* '''f''': [DEPRECATED; use namespaces instead]: a Ferreteria class/trait/interface
* '''f''': [DEPRECATED; use namespaces instead]: a [[Ferreteria]] class/trait/interface
* '''if''': interface
* '''if''': interface
* '''t''': trait
* '''t''': trait
Line 23: Line 24:
''see also General Affixes''
''see also General Affixes''
===General Affixes===
===General Affixes===
In the prefix but not necessarily the first characters:
In the prefix but not necessarily as the first characters:
* '''db''': a database
* '''db''': a database
* '''rc''': a single-record class/object
* '''rc''': a single-record class/object
Line 29: Line 30:
* '''t''': a table class/object
* '''t''': a table class/object


These are generally used only for classes and objects. For classes, the <code>c</code> prefix comes first; for objects, these can take the place of the <code>o</code> prefix, and sometimes may be the entire name of the variable.
These may be used in declarations or variable names, but are generally used only for classes and objects. For classes, the <code>c</code> prefix comes first; for objects, these replace the <code>o</code> prefix, and sometimes may be the entire name of the variable.
==Value Types==
==Value Types==
* '''cell''' means access to a value in a named location (e.g. an array element)
* '''cell''' means access to a value in a named location (e.g. an array element)
* '''ref''' means a [[PHP/referencing|reference]]-container object (cReference)
* '''ref''' means a [[htyp:PHP/referencing|reference]]-container object (cReference)
* '''slug''' means a string which can unambiguously represent any expected value or state of a given item
* '''slug''' means a string which can unambiguously represent any expected value or state of a given item
** needed for representing record IDs in URLs, where one possible state is "new" (no ID yet)
** needed for representing record IDs in URLs, where one possible state is "new" (no ID yet)

Revision as of 14:11, 11 November 2021

I tend to use the following naming conventions within my code, more or less in keeping with the Apps variation of Hungarian notation.

Prefixes

Variable Prefixes

  • f: floating-point number
  • k or K: a constant, i.e. anything whose value should not (or cannot) change once defined
  • n: a count (int; use f for float)
  • o: object
    • or: a ref object (see Value Types)
    • os: a status object (see Value Types)
  • s: string
    • sc: string that is the name of a class
    • sq or sql: string that is formatted as SQL, or safe to be used within SQL

see also General Affixes

Declaration Prefixes

  • c: class
    • ca: abstract class (cannot be instantiated)
    • cs: static class (not intended to be instantiable; all methods static)
  • ch: a string that is always a single character
  • f: [DEPRECATED; use namespaces instead]: a Ferreteria class/trait/interface
  • if: interface
  • t: trait

see also General Affixes

General Affixes

In the prefix but not necessarily as the first characters:

  • db: a database
  • rc: a single-record class/object
  • rs: a recordset class/object
  • t: a table class/object

These may be used in declarations or variable names, but are generally used only for classes and objects. For classes, the c prefix comes first; for objects, these replace the o prefix, and sometimes may be the entire name of the variable.

Value Types

  • cell means access to a value in a named location (e.g. an array element)
  • ref means a reference-container object (cReference)
  • slug means a string which can unambiguously represent any expected value or state of a given item
    • needed for representing record IDs in URLs, where one possible state is "new" (no ID yet)
  • status means a presence-info object
    • preferably descended from cThingHolder
  • unit means something that knows its own name and has awareness of its container-object/structure
    • preferably a PortRow Unit object
  • value means a read-only value, assumed to exist (throws error if not)