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

Proposal: Type inferred default value #7737

Closed
alrz opened this issue Dec 30, 2015 · 4 comments
Closed

Proposal: Type inferred default value #7737

alrz opened this issue Dec 30, 2015 · 4 comments

Comments

@alrz
Copy link
Contributor

alrz commented Dec 30, 2015

Currently, if you want to use default values you have to specify the exact type for default operator,

public T F<T>(CancellationToken ct = default(CancellationToken)) => default(T);

However, compiler could infer the desirable type from the target,

public T F<T>(CancellationToken ct = default) => default;

#1419 rules can also help to infer the best type for the resultant default value.

@lachbaer
Copy link
Contributor

I think it is better to leave the default keyword as a 'function', when inside a body.

First, it is concise, not one time a 'function' another time a 'keyword';

Second, it is better to always write down, what default is returned; maybe one time it may be the class, the other time it may be a derived class.

verbosity is one of the advantages of C#, just see the 'superfluid' abstract keyword on the before the class keyword, because it is clear that it must be an abstract class, as at least one function inside is abstract - greetings from C++ ;-)

For instanciation, like in the optional parameter above, it could really ease typing and reading the code.

@alrz
Copy link
Contributor Author

alrz commented Feb 23, 2016

@lachbaer Your argument can be applied to var, verbosity is good as long as it's not reduntant. And this has nothing like what abstract implies. default has been always a keyword and not a "function". And also, you don't need to always omit the type (like what you said, you can use it only for default parameters as a convention), as for var which you can simply prefer verbosity and don't use it. It's more of a preference — you may or may not prefer conciseness.

@lachbaer
Copy link
Contributor

@alrz Don't take me too literal, that's why I put function in hyphens :-)

@alrz
Copy link
Contributor Author

alrz commented Mar 21, 2017

Moved to dotnet/csharplang#102

@alrz alrz closed this as completed Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants