On Thu, Dec 4, 2014 at 11:28 AM, Robert O'Callahan <rob...@ocallahan.org>
wrote:

> On Thu, Dec 4, 2014 at 12:35 PM, Seth Fowler <s...@mozilla.com> wrote:
>
> > I’d like to change the coding style guide to let us make out-params more
> > obvious by using an ‘o’ prefix for their name instead of an ‘a’. For
> > example,
> >
> > nsresult Modify(int aCount, size_t aSize, char* oResult);
> >
> > This will make it clear just from the declaration of a function or method
> > which parameters are out-params. XPCOM requires us to use out-params a
> lot,
> > and I’ve found that determining when it’s happening often requires me to
> > look at the code for the method, especially since we frequently use
> pointer
> > arguments for efficiency or because the argument is optional.
> >
> > Seems to me like a substantial gain in readability for little or no cost.
> >
>
> I think this would be a slight improvement but the place where I really
> want out-parameters to be visible is at the caller, not the callee.
>

I guess, to make it clear at caller side, and force the compiler to check
it as much as possible, the best way would be having a template class e.g.
Out<> which holds a reference to the target variable, and giving it proper
implicit conversion, e.g. Out<T> can be implicitly converted to T& but not
inversely. With that, I guess we can use it directly in new code, and the
usage in caller will be compatible with the existing functions.

Might be something like this:
https://gist.github.com/upsuper/322bde839f3552ff7e3b

- Xidorn
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to