The two seem the same to me:
- a convenience is a helper
- a helper is a convenience
When is it good to use the one or the other term?
Functions have two main purposes: aiding code reusability and breaking down a task into smaller logical units. Functions that do not aid code reusability are helper functions; their sole purpose is to “help” a single function by cleaning the code and making the logic clearer. The opposite of a helper function is a library function, which focuses on code reuse.
Source: Cunningham & Cunningham
whereas:
A convenience function is a non-essential subroutine in a programming library or framework which is intended to ease commonly performed tasks.
Source: Wikipedia
So:
-
A helper function which is not a convenience function would be any function which breaks down a task into smaller logical units without aiding code reusability and without having a goal of easing a commonly performed task.
For example, a specific task T may require to perform action A and action B. Refactoring may lead to three functions:
T()
,A()
andB()
, given that it may not make too much sense to callA()
without callingB()
just after that. -
A convenience function which is not a helper function would ease commonly performed tasks without breaking down a task into smaller logical units.
For instance, if many persons are calling the task T₁ immediately followed by the task T₂, a convenience function would be T₃ which will simply call T₁, then T₂. Here,
T₃()
doesn’t “help” a single function, and doesn’t break down any task into smaller logical units: it simply regroups two currently used tasks.
They’re just terms. In most scenarios, they are interchangeable.
In general though, a convinience function is one that just helps you do something you can already do, albeit with less typing. An overload that forwards with the usual defaults for example.
A helper often is some new functionality that doesn’t really belong somewhere so it’s off on its own, but still helps out.
At least as I’d use them, the two are actually more or less opposites.
A convenience function is (at least close to) a pure interface function–something that only provides a nicer, more convenient interface for client code to use. A classic example would be a front-end for a recursive function such as a Quicksort:
Quicksort(array a) {
QuicksortImplementation(a, 0, a.size());
}
A helper function, by contrast, normally isn’t visible at all. In object oriented programming, for example, it’ll typically be implemented as a private method/member function.
class X {
public void foo() {
// beginning of `foo`
if (some_condition)
helper();
// remainder of foo
}
private void helper() {
// do some relatively minor service for foo()
}
};
In both cases, however, there is usually the basic idea that the helper/convenience function provides only a small part of the overall functionality. There is also at least the connotation that the helper/convenience function is really only intended to be used in conjunction with one other primary function. It’s usually not particularly general or reusable, just a part of its primary function that needs to be (or is more convenient when) written as a separate function for one reason or another.
1