JADE Environment Development Ideas

What's new in the upcoming JADE release?

IMPROVED DEVELOPER EFFICIENCY. ENHANCED SECURITY. SMOOTHER INTEGRATION

The JADE 2022 release meets tomorrow’s business demands.


Start your update to JADE's latest release

Type Method Improvements

Having used the type methods in a few scenarios now, we've identified issues with using type methods in a dynamic manner when we don't have or can't afford to create an instance of the object. A basic example of this was discussed on the JADE forums, which we could workaround by faking the OID and calling the type method explicitly (after casting the fake OID), but we've identified another scenario since where we'd like to invoke a type method dynamically using just a reference to the Type via sendMsg/sendTypeMsg.

When I first seen the 'sendTypeMsg' method, I instinctively thought it's purpose/intent would be for invoking a type method from the instance of Type it was associated with. However, sendTypeMsg is defined on Object (not Type), so when calling a method in a sendMsg style, you have to know in advance whether it's going to be an instance or type method you need to invoke.

If/when existing methods are changed to be a type method, it has the potential for breaking things if they're called from elsewhere via Object::sendMsg.

To resolve these issues, I believe the following is needed:

  • Change Object::sendMsg methods to support calling both instance & type methods, rather than the caller needing to make the distinction.
  • Move Object::sendTypeMsg methods to Type and change them so they can be used to invoke a type method by name dynamically in context of the receiver (rather than the type class).

Presumably, the JADE Plant will be concerned about the risk of any existing references to Object::sendTypeMsg being broken as a result of fixing this. I don't think there's much to worry about here as it doesn't really make sense to me why you'd need to use this method if you've got an instance to begin with.

When calling a type method from an instance method, I also find it frustrating that we have to write it as:

selfType@typeMethod(...);

Whereas we should be able to call a type method seamlessly from an instance method. Without this, we're forced to change existing method references to use this syntax when we change an existing instance method to be a type method (and vice versa if we change back).

  • Kevin Saul
  • Jun 17 2019
  • Shipped (2020)
  • Attach files
  • Mathew Hylkema commented
    September 09, 2020 00:24

    Hi Kevin, that is correct, invokeTypeMethod will invoke the specific method you provide it rather than using polymorphism to determine which method to call (the same as invokeMethod).

    Re: call unqualified type methods from instance methods, yes, we have eased the compiler checks to allow type methods to be called from instance methods without the need for "selfType@" qualification. It will act the same as if it was qualified with selfType@, meaning reimplementation's will be called etc.

  • Kevin Saul commented
    August 19, 2020 04:33

    Hi Matt,

    I take it invokeTypeMethod will invoke the specific method supplied (like Object::invokeMethod), regardless of it being re-implemented in context of the particular Type/receiver (which you may be trying to skip over).

    Just to confirm re: last section of the idea, will we be able to call type methods seamlessly from instance methods without the selfType@ now?

  • Mathew Hylkema commented
    August 19, 2020 03:36

    For the upcoming 2020 JADE release, we have added the following method re-implementations to the Type class:

    • Type::sendTypeMsg(message: String): Any;

    • Type::sendTypeMsgWithParams(message: String; paramList: ParamListType): Any;

    • Type::sendTypeMsgWithIOParams(message: String; paramList: ParamListType io): Any;

    These will allow type methods to dynamically be invoked using the type they are defined on (without needing an instance of that Type). The decision was made not to remove the Object::sendTypeMsg implementations, as this has the potential to break existing systems.

    Additionally, we have adding the following Type class methods to complement the Object::invokeMethod methods:

    • Type::invokeTypeMethod(targetContext : ApplicationContext; targetTypeMethod : Method; paramList : ParamListType): Any;

    • Type::invokeIOTypeMethod(targetContext : ApplicationContext; targetTypeMethod : Method; paramList : ParamListType io): Any;

    These methods can be used in the same manner as the Object::invokeMethod methods, except will invoke the target type method using the receiver type instance (without needing an instance of that Type).