Skip to content

Everything should be an expression #55

Closed
@DartBot

Description

@DartBot

This issue was originally filed by mprz1024@gmail.com


Why have statements and expressions when everything could be an expression? They are both special language forms to implement certain features such as conditions or looping, but some of them are chosen to be called statements and are artificially limited as to where they are allowed or that they cannot return values. (Note that many expressions return empty/null values too.) Statements are like expressions with additional restrictions for the heck of it.

A far more powerful, flexible approach is to make everything an expression that may fit anywhere; expressions being sequenced with semicolons in the case you need to evaluate several of them in a row. It does not have to affect the way you write anything with statements; it just supersedes it by allowing you to write more flexible programs. Functional programmers and people coming from similar backgrounds would love this feature. Expressivity matters a lot when writing complex software for many of us, and Dart has a chance to keep a popular, well-known syntax but go a step further (and give yet another reason to switch).

So my suggestion is to transform all statements into expressions returning either nothing or the last evaluated value (which would be useful for if, loops, functions and so on). It would also make the language simpler to define, and the ternary operator would be no longer necessary since there's if.

Metadata

Metadata

Assignees

Labels

area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).closed-not-plannedClosed as we don't intend to take action on the reported issuetype-enhancementA request for a change that isn't a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions