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

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

问题描述

我在编译器类,我们的任务是从头开始创建我们自己的语言.目前我们的困境是是否包含null"类型.null 提供什么目的?我们团队中的一些人认为这不是绝对必要的,而其他人则支持 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 年.当时,我是设计第一个综合型对象引用系统面向语言(ALGOL W).我的目标是为了确保所有使用引用应该是绝对安全的,自动执行检查由编译器.但我无法抗拒输入空值的诱惑参考,只是因为它是如此易于实施.这导致无数的错误,漏洞,和系统崩溃,其中有可能造成十亿美元的过去四十年的痛苦和伤害年.近年来,一些程序分析器,如 PREfix 和Microsoft 中的 PREfast 已用于检查参考文献,如果出现则给出警告它们可能是非空的.最近的编程语言,如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.

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

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