コード匂い86 -変なconst配列
4132 ワード
const何か定数を宣言します.変異するか?
予想外の副作用. 偶然の複雑さ. より良い言語を使う 用途spread operator サンプルコード
変異 ジャバスクリプト 結論
クレジット
TL;DR: Don't rely on languages cheating about directives.
問題
解決策
サンプルコード
間違い
const array = [1, 2];
array.push(3)
//array => [1, 2, 3]
//Wasn't it constant ?
//constant != immutable ?
右
const array = [1, 2];
const newArray = [...array,3 ]
//array => [1, 2] Didn't mutate
//newArray = [1, 2, 3]
検出
これが「言語機能」であるので、明示的に禁止することができます.
タグ
const array = [1, 2];
array.push(3)
//array => [1, 2, 3]
//Wasn't it constant ?
//constant != immutable ?
const array = [1, 2];
const newArray = [...array,3 ]
//array => [1, 2] Didn't mutate
//newArray = [1, 2, 3]
これが「言語機能」であるので、明示的に禁止することができます.
タグ
結論
我々は常に我々のデザインの不可用性を支持しなければならなくて、副作用で余分の世話をしなければなりません.
詳しい情報
クレジット
写真でZorik D on Unsplash
ありがとうございました.
マキシ・コンティ
@ MCSET 1
…' const '配列は変更可能ですか?WTF!もう一つのコード匂い?あなたはどう思いますか.
午後13時06分- 2021年8月24日
Correctness is clearly the prime quality. If a system does not do what it is supposed to do, then everything else about it matters little.
バートランドマイヤー
ソフトウェア工学大引用
マキシ・コンティ・ Dec 28 ' 20・ 13分読む
#codenewbie
#programming
#quotes
#software
この記事はCodesmellシリーズの一部です.
あなたのコードの臭い部分を見つける方法
マキシ・コンティ・ May 21 ' 21・ 4分読む
#codenewbie
#tutorial
#codequality
#beginners
Reference
この問題について(コード匂い86 -変なconst配列), 我々は、より多くの情報をここで見つけました
https://dev.to/mcsee/code-smell-86-mutable-const-arrays-46ag
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
Correctness is clearly the prime quality. If a system does not do what it is supposed to do, then everything else about it matters little.
ソフトウェア工学大引用
マキシ・コンティ・ Dec 28 ' 20・ 13分読む
#codenewbie
#programming
#quotes
#software
あなたのコードの臭い部分を見つける方法
マキシ・コンティ・ May 21 ' 21・ 4分読む
#codenewbie
#tutorial
#codequality
#beginners
Reference
この問題について(コード匂い86 -変なconst配列), 我々は、より多くの情報をここで見つけました https://dev.to/mcsee/code-smell-86-mutable-const-arrays-46agテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol