-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Comments
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() { |
@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: It might be better to open a different bug for scoped object extensions. |
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. |
See the comment that WontFixed it:
|
I opened it myself, see https://code.google.com/p/dart/issues/detail?id=9991 |
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.
The text was updated successfully, but these errors were encountered: