site-www icon indicating copy to clipboard operation
site-www copied to clipboard

Language tour should clarify relationship between callable classes and functions

Open mraleph opened this issue 6 years ago • 2 comments

In Dart 2 we changed how callable classes work

class WannabeFunction {
  call(String a, String b, String c) => '$a $b $c!';
} 

typedef void RealFunction(String a, String b, String c);

main() {
  var wf = new WannabeFunction();
  var out = wf("Hi","there,","gang");
  RealFunction rf = wf;  // since Dart 2 this means: rf = wf.call
  print('$out');
}

This is not mentioned in the language tour and might be confusing.

We used to have the whole article about emulating functions on the site - but it seems to have been deleted?

mraleph avatar Nov 05 '19 23:11 mraleph

Yep, I should fix that part of the language tour.

About the emulating functions article... It looks like the latest version is saved here: https://web.archive.org/web/20190402210311/www.dartlang.org/articles/language/emulating-functions

When we did the dart.dev work we removed a bunch of low-readership articles that had no owners and/or source code tests. (Having everything be tested will be important as we switch to non-nullable types.) Also, taking a quick look at the article, I suspect it makes some claims about the design philosophy of Dart that are no longer true.

@mraleph if you think the topics in this article still belong on dart.dev, and you're willing to mark up the article and provide test files for the code, I'd be happy to apply those changes and publish the content (somewhere) on dart.dev.

kwalrath avatar Nov 06 '19 00:11 kwalrath

In case we decide to reinstate the article's content, the discussion/links here might be handy: #600

kwalrath avatar Nov 06 '19 00:11 kwalrath

This work will be handled in https://github.com/dart-lang/site-www/issues/4267. Closing.

atsansone avatar Apr 05 '23 21:04 atsansone