null的目的是什么? [英] What is the purpose of null?

查看:371
本文介绍了null的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编译器类中,我们的任务是从头开始创建我们自己的语言。目前我们的困境是是否包括一个'null'类型。 null提供什么目的?我们的团队中的一些人认为这不是绝对必要的,而其他人只是为了提供额外的灵活性,pro-null。

I am in a compilers class and we are tasked with creating our own language, from scratch. Currently our dilemma is whether to include a 'null' type or not. What purpose does null provide? Some of our team is arguing that it is not strictly necessary, while others are pro-null just for the extra flexibility it can provide.

你有什么想法,特别是为或反对null?
您是否曾创建过需要null的功能?

Do you have any thoughts, especially for or against null? Have you ever created functionality that required null?

推荐答案

Null:十亿美元错误。托尼·霍尔:


我称之为十亿美元的错误。
这是1965年的null
引用的发明。当时,我是
设计第一个综合类型
系统用于对象中的引用
面向语言(ALGOL W)。我的目标
是确保所有使用
引用应绝对安全,
检查由编译器自动执行
但我无法抵抗
引入一个null
引用的诱惑,只是因为它很容易实现
。这导致
无数的错误,漏洞,
和系统崩溃,有
可能导致$十亿美元
痛苦和损坏在过去四十
年。最近几年,一些
程序分析器像PREfix和
PREfast在微软已经用于
检查引用,并给出警告,如果
有风险他们可能是非-null。

最近的编程语言如
Spec#已为
非空引用引入了声明。这是
解决方案,我在1965年拒绝。

I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years. In recent years, a number of program analysers like PREfix and PREfast in Microsoft have been used to check references, and give warnings if there is a risk they may be non-null. More recent programming languages like Spec# have introduced declarations for non-null references. This is the solution, which I rejected in 1965.

这篇关于null的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆