Skip to content

Clarify that assert error expressions are lazy-evaluated #52337

Open
@yjbanov

Description

@yjbanov

Flutter heavily relies on assert statements to keep framework and app code on rails. They make apps slower in debug mode, but in exchange the developer gets the benefit of a less buggy app in production.

A descriptive error message is an important part of an assertion. However, frequently the expression to generate the error message is costly. Most assertions succeed and therefore there's no need to waste resources on computing the error message.

It seems most Dart language implementations evaluate error message expression lazily, and only when the assertion fails. This is great! However, the docs don't mention this about the assert keyword: https://dart.dev/language/control-flow#assert.

If this lazy evaluation feature was called out in the language docs, it would incentivize developers to provide better error messages.

Include a permanent link to the error if possible: https://dart.dev/language/control-flow#assert

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-documentationPrefer using 'type-documentation' and a specific area label.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions