IssueRaiser

Remove dynamic type

### Proposal Dart should remove the `dynamic` type for stricter type-safety, better performance and less support for bad practices. ### Justification The use of `dynamic` is a bad practice, often even referred to as such in the documentation: - "`dynamic`: Indicates that you want to disable static checking. Usually you should use `Object` or `Object?` instead." (https://dart.dev/language/built-in-types) - "Dynamic calls are treated slightly different in every runtime environment and compiler, but most production modes (and even some development modes) have both compile size and runtime performance penalties associated with dynamic calls." (https://dart.dev/tools/linter-rules/avoid_dynamic_calls) However, there are ways to bypass `dynamic` calls and implicit casts for your own projects using lints (e.g. with strong-mode). But this does not solve the problems that the support for `dynamic` has for the Dart language in general. Firstly, it results in worse performance of the compiled code, since more inefficient runtime checks are required. (I'm not an expert on Dart compilers, so correct me if I'm wrong on this point). Secondly, the support of `dynamic` prevents other features that many developers would like to use in a type-safe object-oriented language. For example, `private`, `protected` and `public` modifiers are not possible because they could not support `dynamic` types except through very inefficient runtime checks (dart-lang/sdk#33383). In general, Dart tries to be

Posted by maeddin on Jul 4, 2023, 3:20 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.2,500 issues0 comments

support (Software)

Remove dynamic type

maeddinJul 4, 2023, 3:20 PM

### Proposal Dart should remove the `dynamic` type for stricter type-safety, better performance and less support for bad practices. ### Justification The use of `dynamic` is a bad practice, often even referred to as such in the documentation: - "`dynamic`: Indicates that you want to disable static checking. Usually you should use `Object` or `Object?` instead." (https://dart.dev/language/built-in-types) - "Dynamic calls are treated slightly different in every runtime environment and compiler, but most production modes (and even some development modes) have both compile size and runtime performance penalties associated with dynamic calls." (https://dart.dev/tools/linter-rules/avoid_dynamic_calls) However, there are ways to bypass `dynamic` calls and implicit casts for your own projects using lints (e.g. with strong-mode). But this does not solve the problems that the support for `dynamic` has for the Dart language in general. Firstly, it results in worse performance of the compiled code, since more inefficient runtime checks are required. (I'm not an expert on Dart compilers, so correct me if I'm wrong on this point). Secondly, the support of `dynamic` prevents other features that many developers would like to use in a type-safe object-oriented language. For example, `private`, `protected` and `public` modifiers are not possible because they could not support `dynamic` types except through very inefficient runtime checks (dart-lang/sdk#33383). In general, Dart tries to be

Comments (0)

No comments yet. Start the discussion.

Comment on this issue