Skip to content
This repository was archived by the owner on Oct 26, 2026. It is now read-only.

Establish Scijava-functions as an independent module - #29

Merged
hinerm merged 15 commits into
mainfrom
scijava/scijava-function/init
Jun 25, 2021
Merged

hinerm merged 15 commits into
mainfrom
scijava/scijava-function/init

Conversation

@gselzer

@gselzer gselzer commented Apr 16, 2021 •

Copy link
Copy Markdown
Member

This PR introduces a new module, scijava-functions, into the incubator. At the time of writing, this module contains only:

  • The basic functional interfaces (Computers, Functions, Inplaces, and Producer) used by Ops
  • The annotations (@Container, @Mutable) designed to be used with those Ops
    This partition is motivated by a desire to abstract the interfaces themselves from our particular use case. It is plausible that other developers might find our interfaces useful and would wish to use them without the baggage of Ops/the Ops matcher.

Points of discussion:

  • Is scijava-functions a suitable name? Can we think of a better one? It is a little confusing that the Computers interfaces are found in scijava-functions...
  • Do the Functions.ArityXAsN interfaces belong within scijava-functions? They have no dependence on/relationship to Ops, but would developers get any use out of them? We would also have to make them public (as they are currently protected)
  • The ops-related functionality within Computers/Inplaces/Functions has been repackaged within ComputerUtils/InplaceUtils/FunctionUtils (this is mostly referring to the match() methods. Should these classes continue to reside within org.scijava.ops.function, or should we move them into org.scijava.ops.util? We might also want to consider moving OpWrappers...
  • Do the annotations pertaining to Ops (@OpMethod/@OpField/@OpDependency, etc.) belong in this module as well? Anyone who wants to write Ops will need these annotations in addition to the interfaces enclosed in this module, however this module is spiritually independent of Ops; adding these annotations would remove that spirit.

@gselzer
gselzer requested review from ctrueden and hinerm April 16, 2021 17:33

@ctrueden ctrueden left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, and awesomely clean! 🏆

Here's what we discussed should be changed:

  • For simplicity, and because this module is highly unlikely to grow in size, let's dispense with the annotations subpackage, and just keep all seven .java files at the top level.
  • The package name will become org.scijava.function (singular) for consistency with Java core's functional interfaces package java.util.function.
  • Add a package-info.java explaining that the naming aligns with java.util.function and is all about functional interfaces, not to be confused with SciJava Ops's use of the term "function". Relatedly, we discussed whether to use a different term in Ops now, to avoid a name clash here, but, ultimately decided that keeping the name "function" is the "least bad" approach for a number of reasons.
  • Add ArityN interfaces to container classes, but without the matching part—just the interface adaptation part. See below.

Points for future consideration:

  • For FunctionUtils et. al matching methods: since they all are static but take an OpEnvironment as their first parameter, they are almost begging to be instance methods of OpEnvironment itself. The two main points against this are: 1) it greatly expands the OpEnvironment's API (but I'd argue not so greatly that it overwhelms callers, but rather empowers them to more easily match functions etc.); and 2) it "bakes in" three core functional op types more deeply. We need to be careful with (2) to avoid resulting in a system that does not support extensibility into additional functional types. But it might be worth the tradeoff here...
  • About OpWrapper: our thinking as of our discussion is that the org.scijava.ops.function package will go away, with the wrappers moved to join the matcher, because it's an implementation detail that we want to encapsulate, and is only used by the matcher.
  • We decided not to move the op annotation interfaces (OpClass, OpMethod, OpField) into scijava-function, because they feel like bloat. However, they cannot live in scijava-ops as currently structured either, because then anyone who wants to use them will inherit bad dependencies (e.g. guava, javassist, therapy... 🤢) We agreed (reluctantly) that we need a separate Ops API module. The questions to ponder are: 1) how to name it? (scijava-ops-api and scijava-ops-engine?) 2) which classes exactly belong in API vs impl module? Reviewing all the logic currently in scijava-ops one by one will be needed.
Interface adaptation for n-ary
Functions.Arity3<I1, I2, I3, O> myFunc = ....
Functions.ArityN<O> myFuncN = Functions.nary(myFunc);

public static Functions.ArityN<O> nary(Functions.Arity3<?, ?, ?, O> f) {
  return new ArityN<>() {
	Functions.Arity3<Object, Object, Object, O> func;

	public Arity3AsN(Functions.Arity3<Object, Object, Object, O> func) {
		this.func = func;
	}

	public O apply(Object... ins) {
		// Consider doing more safety checks here, but I'm initially inclined against...
		//if (ins[0] genericinstanceof func's first param type) and .... and length matches...
		return func.apply(ins[0], ins[1], ins[2]);
	}

	public Function getFunction() {
		return func;
	}
  }
}
public static Functions.ArityN<O> nary(Functions.Arity4<?, ?, ?, ?, O> f) { ... }
... code generated ...

@gselzer

gselzer commented May 13, 2021

Copy link
Copy Markdown
Member Author

Time commitment: 1 week

@gselzer
gselzer force-pushed the scijava/scijava-function/init branch 3 times, most recently from 1ea0333 to 7eaeb40 Compare May 18, 2021 17:19
@gselzer

gselzer commented May 18, 2021

Copy link
Copy Markdown
Member Author

@ctrueden I have resolved all bullet points resulting from our discussion, and have also deleted the org.scijava.ops.function package. As of this writing, ComputerUtils/FunctionUtils/InplaceUtils have been moved to org.scijava.ops.util, and OpWrappers have been moved to org.scijava.ops.matcher. I think that our other two "points for further consideration" deserve their own issues (and the third point is likely covered by scijava/scijava#59), so I think we are all good to go here?

@gselzer
gselzer requested a review from ctrueden May 18, 2021 18:57
@gselzer

gselzer commented May 20, 2021

Copy link
Copy Markdown
Member Author

As of this comment, all commits build with passing tests

@gselzer
gselzer force-pushed the scijava/scijava-function/init branch from 99b0eb1 to 5fb1a5e Compare June 25, 2021 19:48
@hinerm
hinerm merged commit 9b25e68 into main Jun 25, 2021
@ctrueden
ctrueden deleted the scijava/scijava-function/init branch November 20, 2021 01:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

3 participants