Created
July 31, 2024 23:20
-
-
Save psenger/1f235fc30a0981636ec321c8ff107c42 to your computer and use it in GitHub Desktop.
[Negative State Programming] #JavaScript
This file contains 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
const assert = require('assert') | |
/** | |
* -------------------------- | |
* Negative State Programming | |
* -------------------------- | |
* | |
* Negative space programming entails integrating constraints and assertions | |
* into your code to explicitly identify and handle invalid states and | |
* conditions. This approach ensures that errors are detected and addressed | |
* promptly, preventing unintended behaviors from spreading throughout the | |
* system. By adopting this method, you improve the software's reliability | |
* while also clearly documenting the developer's intentions, thereby | |
* providing both validation and communication benefits. | |
**/ | |
function add( a, b ) { | |
assert(typeof a === 'number', 'a should be a number'); | |
assert(typeof b === 'number', 'b should be a number'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment