Lea Verou, PhD on Nostr: The idea behind prefer-const is well intentioned: if you plan to never reassign a ...
The idea behind prefer-const is well intentioned: if you plan to never reassign a variable, make it a constant to declare your intent upfront, reducing cognitive load.
But intent is crucial here. Good code expresses *intent*, not coincidence.
Yet linters try to enforce this rule by looking at the current snapshot of the code and asserting that if a variable currently _happens_ to not be reassigned, it means you MUST formalize this as a restriction so that it can never be reassigned! 🙃
Published at
2024-12-06 21:57:46 UTCEvent JSON
{
"id": "0c1621dfe3c2780df6a56444c989a0831d956f269adb9e8704de83ba6f99ecbb",
"pubkey": "effca4793b2710c9d391f2af243fc7228b446437e13c605b2ee931d03319336f",
"created_at": 1733522266,
"kind": 1,
"tags": [
[
"imeta",
"url https://cdn.masto.host/frontendsocial/media_attachments/files/113/608/044/247/932/729/original/8faa7ea7b09cb308.png",
"m image/png"
],
[
"proxy",
"https://front-end.social/@leaverou/113608115288413314",
"web"
],
[
"proxy",
"https://front-end.social/users/leaverou/statuses/113608115288413314",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://front-end.social/users/leaverou/statuses/113608115288413314",
"pink.momostr"
],
[
"-"
]
],
"content": "The idea behind prefer-const is well intentioned: if you plan to never reassign a variable, make it a constant to declare your intent upfront, reducing cognitive load.\n\nBut intent is crucial here. Good code expresses *intent*, not coincidence.\n\nYet linters try to enforce this rule by looking at the current snapshot of the code and asserting that if a variable currently _happens_ to not be reassigned, it means you MUST formalize this as a restriction so that it can never be reassigned! 🙃\nhttps://cdn.masto.host/frontendsocial/media_attachments/files/113/608/044/247/932/729/original/8faa7ea7b09cb308.png\n",
"sig": "318632f3b84fb6f4be9b505319267152efef56c946a10acde443b7b3f91ee7d3606a2461b61b8b9ad4b99357260fdada2802cb355698e6687d961707c3dd4645"
}