Skip to content

Add typedef void VoidCallback(); to dart:core #27791

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

Closed
abarth opened this issue Nov 10, 2016 · 7 comments
Closed

Add typedef void VoidCallback(); to dart:core #27791

abarth opened this issue Nov 10, 2016 · 7 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue core-n library-core type-enhancement A request for a change that isn't a bug

Comments

@abarth
Copy link
Contributor

abarth commented Nov 10, 2016

Would it be possible to add the follow declaration to dart:core

typedef void VoidCallback();

I keep needing this typedef and it seems ugly to redeclare it in every package.

Thanks!

/cc @floitschG

@lrhn lrhn added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core type-enhancement A request for a change that isn't a bug labels Nov 10, 2016
@a14n
Copy link
Contributor

a14n commented Nov 10, 2016

The func package already contains some predefined typedef. VoidFunc0 in this case.

@abarth
Copy link
Contributor Author

abarth commented Nov 10, 2016

I guess I'm a weird duck in that I'm writing code that can't depend on packages.

@krisgiesing
Copy link

The func package is marked as 'discontinued', does that affect the decision here?

@lrhn
Copy link
Member

lrhn commented Dec 3, 2018

I'm guessing the reason the func package is discontinued is that the language has added syntax for expressing function types directly. You can now write void Function() anywhere you would write VoidCallback and get the same result, without any need to import or declare the type.

We don't plan to add function type aliases for simple types like this, we recommend just usig the function type syntax.

@lrhn lrhn closed this as completed Dec 3, 2018
@lrhn lrhn added the closed-not-planned Closed as we don't intend to take action on the reported issue label Dec 3, 2018
@Hixie
Copy link
Contributor

Hixie commented Jan 22, 2019

:-(

void Function() does not make it clear that it is intentional that the type used in one place matches the type used in another. Also, it's less readable than VoidCallback.

@lrhn
Copy link
Member

lrhn commented Jan 23, 2019

I tend to disagree about the readability. Reading void Function() tells me exactly what the function type is, where reading VoidCallback means I have to look up what it actually means - like how many arguments it accepts.

@Hixie
Copy link
Contributor

Hixie commented Jan 23, 2019

Mostly it's less readable just because function signature literals are hard to read in general (they have multiple keywords, parentheses, etc) vs a single word. I agree that VoidCallback is less self-documenting (though that's not that much of a problem in practice since we expose our documentation aggressively).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue core-n library-core type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

7 participants