什么是可靠的编程语言?
What is a sound programming language?
Dart is a sound language.
上面句子中的“声音”是什么意思?
我在其他主要编程语言中找不到任何类似的概念。任何人都可以举出一些其他 声音语言 的例子吗?
这与音频无关。
根据维基百科:
That is, if a type system is both sound (meaning that it rejects all incorrect programs) and decidable (meaning that it is possible to write an algorithm that determines whether a program is well-typed)
(比照https://en.wikipedia.org/wiki/Type_system#Static_type_checking)
有关词源的考虑,请参阅“健全性”。
TL;DR:在这种情况下,它的意思是“健壮”、“健康”。
What is soundness?
Soundness is about ensuring your program can’t get into certain invalid states. A sound type system means you can never get into a state where an expression evaluates to a value that doesn’t match the expression’s static type. For example, if an expression’s static type is String, at runtime you are guaranteed to only get a string when you evaluate it.
Strong mode, like the type systems in Java and C#, is sound. It enforces that soundness using a combination of static checking (compile errors) and runtime checks. For example, assigning a String to int is a compile error. Casting an Object to a string using as String will fail with a runtime error if the object isn’t a string.
Dart was created as an optionally typed language and is not sound. For example, it is valid to create a list in Dart that contains integers, strings, and streams. Your program will not fail to compile or run just because the list contains mixed types, even if the list is specified as a list of float but contains every type except floating point values.
In classic Dart, the problem occurs at runtime—fetching a Stream from a list but getting another type results in a runtime exception and the app crashes. For example, the following code assigns a list of type dynamic (which contains strings) to a list of type int. Iterating through the list and subtracting 10 from each item causes a runtime exception because the minus operator isn’t defined for strings.
The benefits of soundness
A sound type system has several benefits:
Revealing type-related bugs at compile time.
A sound type system forces code to be unambiguous about its types, so type-related bugs that might be tricky to find at runtime are revealed at compile time.
More readable code.
Code is easier to read because you can rely on a value actually having the specified type. In sound Dart, types can’t lie.
More maintainable code.
With a sound type system, when you change one piece of code, the type system can warn you about the other pieces of code that just broke.
Better ahead of time (AOT) compilation.
While AOT compilation is possible without strong types, the generated code is much less efficient.
Cleaner JavaScript.
For web apps, strong mode’s more restrictive typing allows dartdevc to generate cleaner, more compact JavaScript.
Bringing soundness to Dart required adding only a few rules to the Dart language. With strong mode enabled, the Dart analyzer enforces three additional rules:
Use proper return types when overriding methods.
Use proper parameter types when overriding methods.
Don’t use a dynamic list as a typed list.
在那种情况下,声音是一个形容词,意思是“状况良好”。
https://dictionary.cambridge.org/dictionary/english-japanese/sound
虽然健全的类型系统为开发人员提供了更大的信心,但它也使我们的编译器能够安全地使用类型来优化生成的代码。凭借稳健性,我们的工具通过静态和(需要时)运行时检查的组合来保证类型是正确的。没有健全性,类型检查只能到此为止,静态类型在运行时可能不正确。
Dart is a sound language.
上面句子中的“声音”是什么意思?
我在其他主要编程语言中找不到任何类似的概念。任何人都可以举出一些其他 声音语言 的例子吗?
这与音频无关。
根据维基百科:
That is, if a type system is both sound (meaning that it rejects all incorrect programs) and decidable (meaning that it is possible to write an algorithm that determines whether a program is well-typed)
(比照https://en.wikipedia.org/wiki/Type_system#Static_type_checking)
有关词源的考虑,请参阅“健全性”。
TL;DR:在这种情况下,它的意思是“健壮”、“健康”。
What is soundness?
Soundness is about ensuring your program can’t get into certain invalid states. A sound type system means you can never get into a state where an expression evaluates to a value that doesn’t match the expression’s static type. For example, if an expression’s static type is String, at runtime you are guaranteed to only get a string when you evaluate it.
Strong mode, like the type systems in Java and C#, is sound. It enforces that soundness using a combination of static checking (compile errors) and runtime checks. For example, assigning a String to int is a compile error. Casting an Object to a string using as String will fail with a runtime error if the object isn’t a string.
Dart was created as an optionally typed language and is not sound. For example, it is valid to create a list in Dart that contains integers, strings, and streams. Your program will not fail to compile or run just because the list contains mixed types, even if the list is specified as a list of float but contains every type except floating point values.
In classic Dart, the problem occurs at runtime—fetching a Stream from a list but getting another type results in a runtime exception and the app crashes. For example, the following code assigns a list of type dynamic (which contains strings) to a list of type int. Iterating through the list and subtracting 10 from each item causes a runtime exception because the minus operator isn’t defined for strings.
The benefits of soundness A sound type system has several benefits:
Revealing type-related bugs at compile time. A sound type system forces code to be unambiguous about its types, so type-related bugs that might be tricky to find at runtime are revealed at compile time.
More readable code. Code is easier to read because you can rely on a value actually having the specified type. In sound Dart, types can’t lie.
More maintainable code. With a sound type system, when you change one piece of code, the type system can warn you about the other pieces of code that just broke.
Better ahead of time (AOT) compilation. While AOT compilation is possible without strong types, the generated code is much less efficient.
Cleaner JavaScript. For web apps, strong mode’s more restrictive typing allows dartdevc to generate cleaner, more compact JavaScript.
Bringing soundness to Dart required adding only a few rules to the Dart language. With strong mode enabled, the Dart analyzer enforces three additional rules:
Use proper return types when overriding methods.
Use proper parameter types when overriding methods.
Don’t use a dynamic list as a typed list.
在那种情况下,声音是一个形容词,意思是“状况良好”。
https://dictionary.cambridge.org/dictionary/english-japanese/sound
虽然健全的类型系统为开发人员提供了更大的信心,但它也使我们的编译器能够安全地使用类型来优化生成的代码。凭借稳健性,我们的工具通过静态和(需要时)运行时检查的组合来保证类型是正确的。没有健全性,类型检查只能到此为止,静态类型在运行时可能不正确。