Honestly I think your problem is that there are too many perfectly reasonable names. All of these are OK, especially if they come with good docstrings.
estimateResult(data)
approximateResult(data)
quickResult(data)
fastResult(data)
previewResult(data)
calculateResult(data, timeLimit: number)
calculateResult(data, accuracy: number)
calculateResult(data, method: simulated | estimated | phone a friend | etc)
(For options 1 - 5, I'd also throw a docstring on calculateResult
to inform folks about the "fast" version.")
The "right" answer depends entirely on the context of the invoking code and the mindset of the person writing that code. What's the purpose of the faster result? Is it for the purpose of a preview? Is it for a learning or searching algorithm (like A*)? Can your "faster" version be considered a hueristic?
If so, all of these (and others) are also perfectly reasonable, if not more-so.
calculateResult_h(data)
calculateResultHeuristic(data)
calculateX(data, heuristic: true | false)
Alternatively, depending on your invocation context and purpose, you could return a result that contains both values, wherein the "final" result is "pending". You could even have the "final" result evaluate lazily (i.e., only if awaited). Using TS as an example:
const { preview, final } = calculateResult(data);
showResult(preview);
showNote("(Estimated. Calculating final result...)");
final.then(result => {
showResult(result);
showNote("(Final)");
});
There are so many perfectly sane options! You just need to figure out what pattern, purpose, and conception your caller has in their head.
So, ask yourself some questions. (Give the answers to your rubber duck — out loud, ideally.)
- What's in your caller's head?
- How did the person looking for the faster result ask you for it? Was it, "Hey, this is too slow. Can I get a preview result while the final result is churning away?" Was it, "Hey, we don't actually want wait on this level of precision. Can I just get a heuristic?" Or something else entirely?
- Have you discussed the naming question with the team or consumer?
- Is this a two-way door? (Can you easily change the name later if you don't like it?) ... If so, roll the dice and change it later if it causes confusion.
approximateResult(data)
? Answering this question probably needs a specific function name.approximateResult(data)
has the issue I mentioned which is that it doesn't indicate the drastic speedup. You may takecalculatePairwiseRelation(data)
as an abstract proxy for the function name if it helps.batchSize
that you believe gives the best tradeoff between performance and accuracy while letting callers choose to override it for improved accuracy or improved performance at the expense of the other?