ceylon / ceylon-spec

DEPRECATED
Apache License 2.0
108 stars 34 forks source link

Syntactic sugar for annotations? #783

Open FroMage opened 11 years ago

FroMage commented 11 years ago

Compare:

import ceylon.language.model { Annotation }

shared annotation final class Annot() satisfies Annotation<Annot> {}
shared annotation Annot annot() => Annot();

With:

public @interface Annot{}

We need to seriously consider how to make it easier for people to write annotations.

quintesse commented 11 years ago

I don't feel that a specialized feature like annotations needs to have a syntax that is "as short as possible". Especially because annotations by themselves don't do anything, you'll always have to have some meta model handling in your code.

Now if we can come up with something nice I'm not going to be against it of course, but maybe a future implementation of "anonymous classes" could already help out a bit, eg:

shared annotation Annot annot() => class () satisfies Annotation<Annot> {}

Also, maybe marking something (Annot) with annotation could already by default imply satisfies Annotation<Annot>? Giving you:

import ceylon.language.model { Annotation }

shared annotation final class Annot() {}
shared annotation Annot annot() => Annot();

and the (theoretical) short form of:

shared annotation Annot annot() => class () {}

That isn't so bad, is it?

tombentley commented 11 years ago

"anonymous classes" could already help out a bit

But if the annotation class is anonymous, how can it be obtained at runtime?

maybe marking something (Annot) with annotation could already by default imply satisfies Annotation<Annot>

Wow, so now the presence of an annotation can affect the satisfies clause? I don't think that's a good idea at all.

FroMage commented 11 years ago

This is for 1.1, no need to rush for a solution ;)

gavinking commented 11 years ago

Wow, so now the presence of an annotation can affect the satisfies clause?

Well, in fairness, Java's constructs like enum and @interface work exactly that way. I don't see why it being an annotation means we could not do the same thing.

gavinking commented 11 years ago

This is for 1.1, no need to rush for a solution ;)

No. It's for 1.2 (if ever).

FroMage commented 11 years ago

Right, but I didn't find that milestone yet ;)

FroMage commented 10 years ago

Looks like this one was closed by accident.