What is reliability?
Sound is that your program cannot get into certain unacceptable states. A sound type system means that you can never get into a state in which an expression evaluates to a value that does not match a static type expression. For example, if the static type of the expression is String, at run time you are guaranteed to get only the string when evaluating it.
Strong mode, such as type systems in Java and C #, sounds. It provides this reliability using a combination of static checks (compilation errors) and runtime checks. For example, assigning a String to int is a compilation error. Dropping an object into a string using String will result in a runtime error if the object is not a string.
Dart was created as an optionally typed language and does not sound. For example, you can use integers, strings, and streams to create a list in Dart. Your program will not compile or run only because the list contains mixed types, even if the list is specified as a float list, but contains all types except floating point values.
In the classic Dart, a problem occurs at runtime - fetching a Stream from the list, but getting a different type causes an exception at runtime, and the application 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 element throws a runtime exception because the minus operator is not defined for strings.
Reliability Benefits A sound type system has several advantages:
Identify type-related errors at compile time. The sound type system forces the code to be unique with respect to its types, therefore type errors that can be difficult to find at runtime are displayed at compile time.
More readable code. Code is easier to read because you can rely on a value of a particular type. Types cannot lie in sound Dart.
More convenient code. When using a sound type system, when you change one piece of code, the type system can warn you about other pieces of code that just broke.
Compilation is better ahead of time (AOT). Although compiling AOT is possible without strong types, the generated code is much less efficient.
More pure JavaScript. For web applications, strong more restrictive typing modes allow dartdevc to generate cleaner, more compact JavaScript.
Building resistance to Darth, you need to add just a few rules to the Dart language. When the strong mode is on, the Dart analyzer fulfills three additional rules:
Use the correct return types when overriding methods.
Use the correct parameter types when overriding methods.
Do not use a dynamic list as a typed list.