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

Loosen return type guidelines for local functions #6165

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/content/effective-dart/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -1200,10 +1200,10 @@ makeGreeting(String who) {
}
```

Note that this guideline only applies to *named* function declarations:
top-level functions, methods, and local functions. Anonymous function
expressions infer a return type from their body. In fact, the syntax doesn't
even allow a return type annotation.
Note that this guideline only applies to *non-local* function declarations:
top-level functions, and methods. Local functions and anonymous function
Copy link
Member

@lrhn lrhn Oct 24, 2024

Choose a reason for hiding this comment

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

Maybe "top-level functions, static functions and instance methods".

I don't usually call static functions "methods", although I guess "static method" is commonly used for them. (I think it's a Java way of phrasing it, which began because they don't/didn't have plain functions at all. Dart always had functions, so methods is only something objects have. But sensible people can disagree on that, and usually do.)

Also, "method" doesn't really cover getters. Whether "function" does can be discussed, the spec does use "function" about both methods, getters and setters. (And "method" only about non-getter, non-setter functions.)

Maybe, compromising for brevity,

top-level, static and instance methods and getters. ...

(Not setters, since you should omit their return type.)

expressions infer a return type from their body. In fact, the anonymous function
syntax doesn't even allow a return type annotation.


### DO annotate parameter types on function declarations
Expand Down