Replies: 1 comment
-
Review of chosen namesThe chosen short names for words to fetch and store a pin are good — they are similar to The chosen long names don't obey to a single convention: some of them have Common considerationsFor memory operations, usually I rely on a presupposition that read operations are used more frequently than write operations. So I use "!" or other prefix for write operation names, and the empty prefix for read operation names. For example, I don't use For operations on pins, statistics can differ. But anyway, write instruction names should be more heavy than read, since they are to change a state. A common convention for words that have side effects (that change a state) and for combinators is that their names are verbs. Their name forms can be as follows: The names for words without side effects are usually nouns: A noun can be a compound noun. Word set for operations on pinsFor this set of words a naming format can be
Usually I use the verb set for an idempotent action. For comparison, when the verb put or write is used, it refers a nonidempotent action. Some shorthandsProbably, in many use cases you know in advance a level or mode to set on a pin, so a more convenient words for that can be introduced:
NB: the verbs sink, rise, settle are used for words that statically know how to change an object (a pin). In the latter case it is specified via the "adverb" part of the name. An alternative verb for settle could be adjust. Separate namespace for the operations on pinsIt should be noted that the names of this word set are constructed around the noun pin that is used as a proper name, and it actually determines a separate namespace for this word set. So it's a good idea to factor out this namespace explicitly into a separate word list. If I would use a separate namespace (a separate word list) for operations on pins, for example the namespace
I use a recognizer for such a syntax. Separate namespace for each pinWe have a small number of pins, and each of them is probably used for its own unique aim in our application. If I would use a separate namespace for each pin (that is highly likely), or use a pin selector, it can looks like the following:
Where NB: this set of methods is actually a closure (in some sense) of the common set of methods over a selected pin. This closure should be generated automatically for each pin from a common model or template. |
Beta Was this translation helpful? Give feedback.
-
A naming that others may have faced. The Arduino framework has a set of well-known functions for general purpose I/O pin control, such as
pinMode
,digitalWrite
, anddigitalRead
. If you didn't use the same names, because they are quite long and don't fit Forth conventions, what names did you choose?So far I have chosen;
m!
orgpio-mode
for pinMode, ( mode pin -- ),p!
orgpio-pin!
for digitalWrite, ( value pin -- ),p@
orgpio-pin@
for digitalRead, ( pin -- value ),a!
orpwm-pin!
for analogWrite, ( value pin -- ),a@
oradc@
for analogRead, ( pin -- value ).Beta Was this translation helpful? Give feedback.
All reactions