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

catch syntax is confusing (looks like an annotation) #2948

Closed
DartBot opened this issue May 8, 2012 · 10 comments
Closed

catch syntax is confusing (looks like an annotation) #2948

DartBot opened this issue May 8, 2012 · 10 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug
Milestone

Comments

@DartBot
Copy link

DartBot commented May 8, 2012

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.

@anders-sandholm
Copy link
Contributor

Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented May 9, 2012

I agree the use of types in the catch syntax is at odds with the rest of the language.


Set owner to @gbracha.
Added Accepted label.

@gbracha
Copy link
Contributor

gbracha commented May 29, 2012

Added this to the M1 milestone.

@gbracha
Copy link
Contributor

gbracha commented Jun 19, 2012

The next rev of the spec (0.11) updates the catch syntax to resolve this issue and make it cleaner.


Added Done label.

@gbracha
Copy link
Contributor

gbracha commented Jun 20, 2012

Analyzer issue #3576
VM issue #3577
dart2js issue #3578

@sethladd
Copy link
Contributor

@DartBot
Copy link
Author

DartBot commented Aug 8, 2012

This comment was originally written by @mhausner


Gilad, the spec does not say whether "on" is a reserved word or a built-in identifier. Please update the spec accordingly.


Added NeedsInfo label.

@gbracha
Copy link
Contributor

gbracha commented Aug 8, 2012

That is because it is neither. The word "on" was deemed too important in web APIs etc.

@DartBot
Copy link
Author

DartBot commented Aug 14, 2012

This comment was originally written by @aam


Correcting links to relevant issues:
  Analyzer http://code.google.com/p/dart/issues/detail?id=3756
  VM http://code.google.com/p/dart/issues/detail?id=3757
  dart2js http://code.google.com/p/dart/issues/detail?id=3758

@gbracha
Copy link
Contributor

gbracha commented Aug 14, 2012

Added Done label.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Aug 14, 2012
@DartBot DartBot added this to the M1 milestone Aug 14, 2012
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants