例(JavaScriptの場合):
//Not that I would ever add a method to a base JavaScript prototype...
//(*wink nudge*)...
Array.prototype.lastIndex = function() {
return this.length - 1;
}
console.log(array[array.lastIndex()]);
vs
console.log(array[array.length - 1]);
技術的に言えば、後者の方法は1つ少ない文字を使用しますが、マジックナンバーも使用します。確かに、この場合、読みやすさは実際には影響を受けないかもしれませんが、マジックナンバーは最悪です。どちらを使用するのが良いですか?