That would be most useful - apart from that, I would probably suggest using named function parameters (also in calls), and to make the name of the variable self-explanatory, including any units (e.g. by appending a corresponding suffix).
Anything that may need to be customized should probably be a variable (if necessary, with a default value) - any logic that may need to be overridden, would benefit from taking an optional "predicate", which is a fancy word for a callback function that can be passed to the function to apply external logic, I think you are familiar with the concept due to your shader work:
untested pseudo code:
- Code: Select all
var myUsefulAPI = func(x,y, condition) {
# this will call the condition function and pass in the x,y arguments
return condition(x,y);
}
var myANDLogic = func(a,b) {return a and b;}
var myORLogic = func(a,b) {return a or b;}
var myEQUAL = = func(a,b) {return a == b;}
var result = myUsefulAPI(100,100, myEQUAL);
print(result);