Last active
May 27, 2025 17:40
-
-
Save nirlanka/c60ffde0ba2c3ef8d6ce439eaa8ce0ef to your computer and use it in GitHub Desktop.
Simple mockup and experiment of what a "negative-space programming" assert situation can look like
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body style="background-color: #222; color: #fff;"> | |
<h1>Test assert everywhere</h1> | |
<script> | |
window.__libs__ = {}; | |
</script> | |
<script> | |
(() => { | |
function assert(/** @type {() => boolean} */ testFn, /** @type {string} */ textOnFail) { | |
try { | |
const isTestPass = testFn(); | |
if (!isTestPass) throw Error(`Assert failure: NOT ${textOnFail}`); | |
} catch (err) { | |
console.error('[ASSERT FAILURE]', err); | |
} | |
} | |
window.__libs__.assert = assert; | |
})(); | |
</script> | |
<script> | |
const { assert } = __libs__.assert; | |
const radioValue = ''; | |
assert(() => ['true', 'false'].some(x => x === radioValue), "a proper string version of the boolean."); | |
// | |
</script> | |
</body> | |
</html> |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body style="background-color: #222; color: #fff;"> | |
<h1>Test assert everywhere</h1> | |
<script> | |
window.__libs__ = {}; | |
</script> | |
<script> | |
(() => { | |
function assertTrue(/** @type {boolean} */ condition, /** @type {string} */ textOnFail) { | |
if (!condition) { | |
console.error(`[ASSERT FAILURE]: NOT ${textOnFail}`); | |
} | |
} | |
function assertTry(/** @type {() => boolean} */ testFn, /** @type {string} */ textOnFail) { | |
try { | |
const isTestPass = testFn(); | |
if (!isTestPass) throw Error(`Assert failure: NOT ${textOnFail}`); | |
} catch (err) { | |
console.error('[ASSERT FAILURE]', err); | |
} | |
} | |
window.__libs__.assert = { | |
assertTrue, | |
assertTry, | |
} | |
})(); | |
</script> | |
<script> | |
const { assertTry } = __libs__.assert; | |
const radioValue = ''; | |
assertTry(() => ['true', 'false'].some(x => x === radioValue), "a proper string version of the boolean."); | |
// | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment