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

Extension Methods #9984

Closed
justinfagnani opened this issue Apr 17, 2013 · 6 comments
Closed

Extension Methods #9984

justinfagnani opened this issue Apr 17, 2013 · 6 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug

Comments

@justinfagnani
Copy link
Contributor

Besides all the usual arguments for extension methods, they would help tremendously with filling in gaps in core libraries and reduce the pressure to include every feature, allowing us to keep the core libraries slim.

Extension methods in Dart should be type-based, and scoped to a library, so that only libraries that import the extensions can call them.

@justinfagnani
Copy link
Contributor Author

One particularly useful case for extension methods is with unittest matchers. Right now the expect syntax is:

expect(value, matcher);

While most dynamic languages have unittest libraries that use a fluent syntax:

expect(value).matcher();

We could use noSuchMethod and some kind of registration to provide this, but that makes static analysis impossible. Extension methods would enable this while still being statically analyzable:

import 'package:my_matchers/my_matchers.dart';

main() {
  expect(value).myMatcher();
}

@justinfagnani
Copy link
Contributor Author

Closing as deuplicate of issue #13


Added Duplicate label.
Marked as being merged into #13.

@jmesserly
Copy link

@justin, the bug you merged this with was closed because it specifically asks for C# extension methods. Those won't work in Dart: they dispatch on the static type.

However, similar ideas can work for dynamic languages:
http://wiki.ecmascript.org/doku.php?id=strawman:scoped_object_extensions

It might be better to open a different bug for scoped object extensions.

@justinfagnani
Copy link
Contributor Author

I assumed that Gilad didn't close the issue just because C# uses the static type. He says:

"Some of these mechanisms depend on static typing (as in C# or Haskell's type classes) some do not (class boxes, selector namespaces)"

And of course, the ES proposal is linked in that bug too. I'll talk to Gilad and see if I should reopen.

@jmesserly
Copy link

See the comment that WontFixed it:

C# extension methods rely on mandatory static typing. That is not an option in Dart.
LINQ like mechanisms can be added to a language by other means. We might consider something in this space down the line.
Status: WontFix

@jmesserly
Copy link

I opened it myself, see https://code.google.com/p/dart/issues/detail?id=9991

@justinfagnani justinfagnani added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report labels Apr 18, 2013
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants