
On Aug 29, 2011, at 3:09 PM, Phil Endecott wrote:
Gordon Woodhull wrote:
If I had to write a conversion function, I would rather write it as an overload of a general-purpose converter, rather than giving it some ugly typeA2TypeB name.
Why is e.g. rgb_to_cmyk() "ugly"?
cmyk_t cmyk = rgb_to_cmyk( rgb ); That's why. Compare: cmyk_t cmyk = cmyk_from_rgb( rgb );
Is it because it is C, and C syntax is ancient history that must be purged from modern C++?
In the absence of parameterization in the caller (where the called function must be a template), a plain function has the advantage of looser coupling: You only need the function prototype in scope, whereas to call a function template you need to have the specialization, (each of) which in turn needs the template declaration. If you touch the header defining the template (or something else it includes), every user of every specialization needs to be recompiled. Then again, I'm biased, since one of the compilers I support sometimes refuses to inline functions when templates are involved, and larger include sets dramatically slow down compiling, because I/O is expensive. I agree with consistent naming, but I don't see <> and :: as inherently superior punctuation to _. Josh