Input parameter dependency

IDFCNS-17
TitleFunction input arguments must be independent.
PriorityStrongly recommended
Severity level5
DescriptionFunction input arguments must be independent, and the function must not assume a dependency between them.
RationaleAssuming a dependency between independent input parameters reduces the robustness of the code. Conversely, if the inputs to a function are dependent, treating them as independent also reduces robustness.

Avoid:

function [meanV, meanA] = getMeanVandA(velocities, distances, timePts)
meanV = sum(distances) ./ sum(timePts);
meanA = velocities(end) ./ sum(timePts);
end

function vectorOut = processVector(vectorIn, vectorLength)
for iIdx = 1 : vectorLength
    vectorOut(ii) = processScalar(vectorIn(ii));
end
end

Instead use:

function [meanV, meanA] = getMeanVandA(distances, timePts)
meanV      = sum(distances) ./ sum(timePts);
velocities = distances ./ timePts;
meanA      = velocities(end) ./ sum(timePts);
end

function vectorOut = processVector(vectorIn)
for iIdx = 1 : length(vectorIn)
    vectorOut(ii) = processScalar(vectorIn(ii));
end
end