Created
March 3, 2014 22:40
-
-
Save noondreams/9336155 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Composability | |
In your interfaces, try to use the simplest data structures that work and make | |
functions do a single, clear thing—if possible, they should be pure functions | |
(see Chapter 2). | |
For example, it is not uncommon for modules to provide their own | |
array-like collection objects, with their own interface for extracting elements | |
from such an object, and return those from functions that return collections | |
of things. Such objects cannot be passed to map or forEach. This is a case of | |
bad composability, since the module cannot be easily composed with algo- | |
rithms operating on arrays. | |
Another example would be a module for spellchecking text, which we | |
might need when we want to write a text editor. The spellchecker could be | |
made to operate directly on whichever complicated data structures the ed- | |
itor uses and directly call internal functions in the editor to have the user | |
choose between spelling suggestions. If we do that, the module cannot be | |
used with any other programs. On the other hand, if we define the spell- | |
checking interface so that you can pass it a simple string and it will return | |
the position in the string where it found a possible misspelling, along with | |
an array of suggested corrections, then we have an interface that could also | |
be composed with other systems. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment