-
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
catch syntax is confusing (looks like an annotation) #2948
Comments
Removed Type-Defect label. |
Added this to the M1 milestone. |
The next rev of the spec (0.11) updates the catch syntax to resolve this issue and make it cleaner. Added Done label. |
News post for this update: http://news.dartlang.org/2012/06/darts-catch-syntax-revisited.html |
That is because it is neither. The word "on" was deemed too important in web APIs etc. |
This comment was originally written by @aam Correcting links to relevant issues: |
Added Done label. |
This issue was originally filed by sammcca...@google.com
Types are both used as annotations (don't affect behaviour) and as references (do affect behaviour), in different contexts:
Annotations:
T local = 42;
T method() { }
method(T param);
References:
new T();
x is T
List<T>
extends T
catch (T foo)
Note that catch syntax fits the pattern of an annotation, but it's actually a behaviour-affecting reference to the type!
This confuses people (myself, and others on the mailing list).
The catch syntax originates with languages that don't have this inconsistency, because types are enforced rather than annotations. In these languages, the most similar syntactic construct (method parameter declarations) is used for a pattern matching construct (overloading) similar to catch. This similarity is not present in Dart, so the similar syntax is misleading.
I think the following syntax is an improvement:
} catch (x is T) {
Pros:
* syntax is already reserved
* type appears at the end of the expression, like other type references
* meaning is obvious
Cons:
* looks like a boolean expression
* less familiar than current syntax to Java/C++/C# developers
There's probably even better syntax to be found, though.
The text was updated successfully, but these errors were encountered: