MIT 6.031 Reading 1: Static Checking

这篇阅读主要讨论了静态检查的概念,包括静态类型、动态类型和无检查。Java作为静态类型的示例,强调了静态检查如何在编译阶段发现错误,如语法错误、参数类型错误等。文章指出,虽然静态检查能检测类型错误,但无法捕获运行时特定值引起的错误,如除零错误或数组越界。此外,还讨论了整数除法和溢出的问题,以及浮点数类型的特殊值。文章最后提到了数组、列表以及变量的可变性和文档注释的重要性。
摘要由CSDN通过智能技术生成

MIT 6.031

Reading 1: Static Checking

Types

  • primitive types:
    • int
    • long
    • boolean
    • double
    • char
  • object types:
    • String
    • BigInteger

Static Typing

Java is a statically-typed language

static checking
Support for static typing in dynamically-typed languages
  • after Python 3.5, it allows you to declare type hints
# Python function declared with type hints
def hello(name: str)->str:
	return 'Hi, ' + n

Static checking, dynamic checking, no checking

  • static checking: the bug is found automatically before the program even runs
    • syntax errors
    • wrong number of arguments: Math.sin(30, 20)
    • wrong argument types: Math.sin("30")
    • wrong return types
  • dynamica c
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值