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

The spec needs to talk about abstract methods #32

Closed
apblack opened this issue Sep 16, 2015 · 13 comments
Closed

The spec needs to talk about abstract methods #32

apblack opened this issue Sep 16, 2015 · 13 comments

Comments

@apblack
Copy link
Contributor

apblack commented Sep 16, 2015

Are abstract declarations required? Or are they optional? And what is the semantics of abstract?

Personally, because I want to be able to use Grace for experimental as well as production coding, I would like abstract methods to remain optional. It would be fine for a dialect to prevent the instantiation of a class that contains an abstract method, but not for the base language.

This all needs to be specified.

@kjx
Copy link
Contributor

kjx commented Mar 7, 2016

@kjx
Copy link
Contributor

kjx commented Mar 9, 2016

check that local declns of abstract methods override traits

@apblack
Copy link
Contributor Author

apblack commented Mar 9, 2016

We agreed to start talking about required methods, rather than abstract methods.

@kjx
Copy link
Contributor

kjx commented Mar 14, 2016

@kjx
Copy link
Contributor

kjx commented Feb 11, 2018

A related point is that requires is not the same as abstract, I think.

It's not. The main difference is that a local definition of a required method is an absence that will be filled - any inherited definition will override a required method, while a local definition of an abstract method overrides any inherited definition.

I was keen earlier to switch back to abstract but now I think required semantics are the better ones - notably because as Kim says above, a local definition of a required method is a way to ensure the request will be dispatched on self, rather than writing self.x at the call site. #145..

To simplify the syntax, I'd just make required an annotation, an annotation that should also require the method body to be empty.

@kjx
Copy link
Contributor

kjx commented Feb 11, 2018

Oh yeah my other reason for preferring required is I think it works better with fully symmetric inheritance resolution --- no implicit overriding, you have to exclude something you want to override #137

@apblack
Copy link
Contributor Author

apblack commented Feb 12, 2018

To simplify the syntax, I'd just make required an annotation, an annotation that should also require the method body to be empty.

It's not a simplification, but I agree that it would be an improvement — if a method with an is required annotation has no body at all. Perhaps that's what you meant by requiring the method body to be empty.

The reason that I'm suggesting this is that the old syntax, where the body is { required } does provide a body, which ought to override any existing body. Whereas a declaration with no body at all (but with the is required annotation) is a statement that someone else should provide a body.

I related question is: what error should be generated when a required method is not provided? An object composition error at object construction time, or a NoSuchMethod exception at request time?

@kjx
Copy link
Contributor

kjx commented Feb 12, 2018

if a method with an is required annotation has no body at all

I think @apblack means:

method foo is required

where I think we're nominally at now is:

method foo required

what I currently suggest is:

method foo is required { }

because the other two cases make the method syntax irregular

@kjx
Copy link
Contributor

kjx commented Feb 12, 2018

what error should be generated when a required method is not provided? An object composition error at object construction time, or a NoSuchMethod exception at request time?

these should also be consistent. I assume @apblack wants a construction time error; I would prefer a dynamic error, or just not specifying it - if only because I could kid myself that in some non-existent dynamic IDE you should be able to run the code, drop into the debugger, and then supply the necessary error then.

The key issue here is: what invariants can the compiler (or checkers) assume about Grace programs.
Should the interpreter / code-generator ever have to see a "naked" required method, on an unresolved internal request. Are just types gradual, or program structures too?

We all seem to agree that nothing should see a syntactically incorrect methods. I take this as a matter of tradition.

@apblack
Copy link
Contributor Author

apblack commented Feb 12, 2018

What we are at now is

method foo { required }

because that's the same syntax as a normal declaration. What I' m proposing is that the syntax should be different from a normal declaration, because the semantics is also different.

@kjx
Copy link
Contributor

kjx commented Feb 12, 2018

Hmm the spec has one example

method id⟦T⟧ is required  { }

and one sentence that says the body is "required" which I thought meant required not { required }. The body being request for required is clearly not the right thing.

(Of course, if we removed all braces execpt for blocks (everything else just layout) then the deign issue goes away.)

@apblack
Copy link
Contributor Author

apblack commented Feb 12, 2018

You are right about that example; it's another one of the inconsistencies that we need to fix. The spec also says that required is a reserved word, whereas making it an annotation would mean that it is an identifier.

The Spec also says that

a required local method overrides an inherited method in the normal way

That's what we are discussing changing here, right?

I assume @apblack wants a construction time error

What I want is for the spec to explain the difference between saying nothing at all about foo and saying that method foo is required. One difference is that self.foo can be abbreviated as foo. Is that the only difference?

@kjx
Copy link
Contributor

kjx commented Feb 13, 2018

What I want is for the spec to explain the difference between saying nothing at all about foo and saying that method foo is required.

well that's probably a good idea :-)

One difference is that self.foo can be abbreviated as foo. Is that the only difference?

I don't know - someone needs to write down the whole semantics of inheritance --- including required, overrides, who knows what else --- in a comprehensible way. I've only got halfway there.

Depends on details of the semantics. I could imagine a world where you weren't allowed to write self.foo unless you had a local definition of foo or an inherited definition - you couldn't go "off piste".
If superclasses all have to be manifest, and you're eager about composition errors, that makes good sense to me.

It will I imagine do something about types, at least static types.
We carefully (so far) say almost nothing about typing across inheritance.

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

2 participants