Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated note on arrow notation #5854

Merged
merged 5 commits into from
May 24, 2024
Merged

Updated note on arrow notation #5854

merged 5 commits into from
May 24, 2024

Conversation

atsansone
Copy link
Contributor

Fixes #4582

@atsansone atsansone added the review.tech Awaiting Technical Review label May 21, 2024
@atsansone atsansone requested a review from munificent May 21, 2024 19:12
@dart-github-bot
Copy link
Collaborator

dart-github-bot commented May 21, 2024

Visit the preview URL for this PR (updated for commit 4229368):

https://dart-dev--pr5854-fix-4582-8dpff8m1.web.app

Comment on lines 52 to 58
Only _expressions_ can appear between the arrow (=\>) and the semicolon (;).
Expressions return values.
This means that you can't write code in a place that expects a value.
In the previous example,
`_nobleGases[atomicNumber] != null;` returns a boolean value.
The function then returns a value if the `atomicNumber` falls into
the noble gas range. The function does nothing but return a value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be careful with the term "return" as one might mistake it as "exit a function with a return value". Perhaps "evaluate" or "produce" might be a better term when referring to expressions?

Also, I think the distinction between an if statement and conditional expression is interesting. It shows an example of what you can't use with the arrow syntax.

Here's a potential alternative:

Only _expressions_ can appear between the arrow (=\>) and the semicolon (;).
Expressions are anything that evaluate to a value.
For example, you could use a [conditional expression][] but not an [if statement][].
In the previous example,
`_nobleGases[atomicNumber] != null` is an expression that evaluates
to `true` if `_nobleGases` has an entry with the key `atomicNumber`.

the semicolon (;). For example, you can't put an [if statement][]
there, but you can use a [conditional expression][].
Only _expressions_ can appear between the arrow (=\>) and the semicolon (;).
Expressions return values.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"return" -> "evaluate to" maybe?

there, but you can use a [conditional expression][].
Only _expressions_ can appear between the arrow (=\>) and the semicolon (;).
Expressions return values.
This means that you can't write code in a place that expects a value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say "code". Expressions are code. Maybe keep the reference to statements? e.g. "...you can't put a statement (for example an [if statement][]) after the arrow."

This means that you can't write code in a place that expects a value.
In the previous example,
`_nobleGases[atomicNumber] != null;` returns a boolean value.
The function then returns a value if the `atomicNumber` falls into
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function returns a value no matter what, it just returns true or false depending on atomicNumber.

@atsansone atsansone removed the request for review from munificent May 22, 2024 19:11
@atsansone atsansone assigned leafpetersen and unassigned munificent May 22, 2024
@atsansone
Copy link
Contributor Author

@leafpetersen , @loic-sharma : PTAL.

you could use a [conditional expression][] but not an [if statement][].
In the previous example,
`_nobleGases[atomicNumber] != null;` returns a boolean value.
The function then returns a boolean value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function always returns a boolean value. Maybe "The function then returns a boolean value indicating whether or not the atomicNumber..."?

For example,
you could use a [conditional expression][] but not an [if statement][].
In the previous example,
`_nobleGases[atomicNumber] != null;` returns a boolean value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would take the ; off of here. It's not part of the expression. _nobleGases[atomicNumber] != null is the expression (which produces a value). The ; is a terminator which separates the function declaration from the declaration which follows it.

Also, consider saying "produces a boolean value" or "evaluates to a boolean value" instead of returns, since return is usually associated with a function producing a value (which you capture in the next sentence).

@atsansone atsansone merged commit bb43daf into dart-lang:main May 24, 2024
10 checks passed
atsansone added a commit to atsansone/site-www that referenced this pull request May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review.tech Awaiting Technical Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Statement vs expression in => fat arrow explanation
5 participants