Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

JavaScript still is often extended via inheritance, such as classes and modules. This is unfortunate because inheritance is the opposite of simple, putting things together instead of taking them apart.

One addition that could greatly improve simplicity is assignable blocks. A block provides scope, much like a function, but accepts no input and returns nothing. Most functions I write take no input and return undefined because I only need them for code reuse by reference.

Imagine code like this:

    if (expression) myBlock else otherBlock;


What's the benefit over myBlock() and otherBlock()


You can write code withou the curly braces, but is generally considered a bad practice.

    if (expression) myBlock() else otherBlock()
is really

    if (expression) {myBlock();} else {otherBlock();}
In that case a block is still there and not reused. Both the semantics and structure are different if the block itself were reused. You could extend the above like so:

    if (expression) {myBlock();x+=1;} else {otherBlock();}
If instead the block were reused that would not work. A finer degree of separation is imposed by reference that reenforces separated structures by name. Separation is the foundation of simplicity. It also makes for code that is easier to read like a natural language sentence.


I'm still not following. Why would you want to reuse blocks (scopes?) rather than code?




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: