final methods

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

final methods

K K Subbu
All,


How does one enforce finality of methods in Squeak?

I noticed that methods like Object>>basicSize have instructions in
comments not to override these, but what if these methods do get
overridden/extended during compilation (perhaps by accident or oversight).

Can we use a dummy primitive in these methods to mark them as final?

Regards .. Subbu

Reply | Threaded
Open this post in threaded view
|

Re: final methods

marcel.taeumel
Hi Subbu,

you cannot. :-) That's a good thing.

As you mentioned, you can document the specific role of a particular method to inform the programmer about side effects. Also, you can add tests that check for such "contracts" in the system. Well, for really dangerous stuff, there might be a hard-coded guard in compiler class. Yet, such guards can easily be overruled by custom compilers.

Best,
Marcel

Am 04.03.2019 02:16:38 schrieb K K Subbu <[hidden email]>:

All,


How does one enforce finality of methods in Squeak?

I noticed that methods like Object>>basicSize have instructions in
comments not to override these, but what if these methods do get
overridden/extended during compilation (perhaps by accident or oversight).

Can we use a dummy primitive in these methods to mark them as final?

Regards .. Subbu



Reply | Threaded
Open this post in threaded view
|

Re: final methods

timrowledge


> On 2019-03-04, at 8:49 AM, Marcel Taeumel <[hidden email]> wrote:
>
> Hi Subbu,
>
> you cannot. :-) That's a good thing.

Exactly. There is no possible reason to adopt such a ridiculous idea from lesser languages.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
A fool and his money are soon partying



Reply | Threaded
Open this post in threaded view
|

Re: final methods

Bert Freudenberg
In reply to this post by K K Subbu
On Mon, Mar 4, 2019 at 2:16 AM K K Subbu <[hidden email]> wrote:
All,


How does one enforce finality of methods in Squeak?

I noticed that methods like Object>>basicSize have instructions in
comments not to override these, but what if these methods do get
overridden/extended during compilation (perhaps by accident or oversight).

Can we use a dummy primitive in these methods to mark them as final?

There is no way to enforce this from inside the method, since if it is overridden in a subclass, the VM never even looks at that method.

We do warn users about accidentally overriding some methods, in particular anything defined in Behavior / ClassDescription / Metaclass. This works simply by having the browser check if the method you're trying to accept is "scary" (see isScarySelector:).

We could do something similar for methods that you really should not override (like #basicSize, #== etc).

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: final methods

Hannes Hirzel
On 3/4/19, Bert Freudenberg <[hidden email]> wrote:

> On Mon, Mar 4, 2019 at 2:16 AM K K Subbu <[hidden email]> wrote:
>
>> All,
>>
>>
>> How does one enforce finality of methods in Squeak?
>>
>> I noticed that methods like Object>>basicSize have instructions in
>> comments not to override these, but what if these methods do get
>> overridden/extended during compilation (perhaps by accident or
>> oversight).
>>
>> Can we use a dummy primitive in these methods to mark them as final?
>>
>
> There is no way to enforce this from inside the method, since if it is
> overridden in a subclass, the VM never even looks at that method.
>
> We do warn users about accidentally overriding some methods, in particular
> anything defined in Behavior / ClassDescription / Metaclass. This works
> simply by having the browser check if the method you're trying to accept is
> "scary" (see isScarySelector:).
>
> We could do something similar for methods that you really should not
> override (like #basicSize, #== etc).
+1

> - Bert -
>