Better HN
topnewbestaskshowjobs
Log inSign up

askmrsinh

2 karma · joined Sep 13, 2021 (5y ago) · 2 submissions

Submissions

comment 1y ago · link · parent

Constants are useful for reasoning about code, but anyone who focuses only on making everything an immutable is missing the point. The main goal should be achieving referential transparancy.

It can be perfectly fine to use mutable variables within a block, like a function when absolutely needed - for example, in JavaScript's try catch and switch statements that need to set a variable for later use. As long as these assignments are local to that block, the larger code remains side-effect free and still easy to reason about, refactor and mantain.

https://rockthejvm.com/articles/what-is-referential-transpar...

comment 1y ago · link · parent

Why not do:

const y = x ? true : false;