尤川豪   ·  5年前
445 貼文  ·  275 留言

「null」是造成軟體產業十億美元損失的錯誤設計?

看到 Quora 一篇問答「What line of code changed the world of programming?」

其中一個 1k upvote 的答案是

https://qr.ae/TUh9mL

object = null;

這是我一個代價十億美元的錯誤。我在 1965 年發明了 null reference。

我原先目標是要確保所有 reference 都絕對安全,由 compiler 自動檢查型別。但是我抗拒不了把 null reference 加進型別系統裡面的誘惑,因為實作起來實在很簡單。這導致了之後無數的程式錯誤、資安漏洞、系統當機。大概在過去 40 年間造成了業界十億美元的損失與傷害。

  分享   共 5,388 次點閱
共有 2 則留言
尤川豪   ·  5年前
445 貼文  ·  275 留言

其實我看不太懂。是不是說,null 的存在讓 compiler 沒有辦法 100% 在 compile 時確保每個變數的型別都是被正確使用?

 
尤川豪   ·  5年前
445 貼文  ·  275 留言

看到更多文章 這段描述倒是很好理解

https://softwareengineering.stackexchange.com/questions/12777/are-null-references-really-a-bad-thing

The problem is that because in theory any object can be a null and toss an exception when you attempt to use it, your object-oriented code is basically a collection of unexploded bombs.

 
按了喜歡:
您的留言
尤川豪
445 貼文  ·  275 留言

Devs.tw 是讓工程師寫筆記、網誌的平台。隨手紀錄、寫作,方便日後搜尋!

歡迎您一起加入寫作與分享的行列!

查看所有文章