Skip to content

Instantly share code, notes, and snippets.

@psenger
Created July 31, 2024 23:20
Show Gist options
  • Save psenger/1f235fc30a0981636ec321c8ff107c42 to your computer and use it in GitHub Desktop.
Save psenger/1f235fc30a0981636ec321c8ff107c42 to your computer and use it in GitHub Desktop.
[Negative State Programming] #JavaScript
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