Skip to content

Instantly share code, notes, and snippets.

@nirlanka
Last active May 27, 2025 17:40
Show Gist options
  • Save nirlanka/c60ffde0ba2c3ef8d6ce439eaa8ce0ef to your computer and use it in GitHub Desktop.
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
<!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>
<!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