On Tue, Jan 7, 2014 at 12:53 PM, Robert O'Callahan <
rob...@ocallahan.org> wrote:
>
> We have a lot of places where we write "void Method() { ... }" all on one
> line for trivial setters and getters. I wonder if we should permit that.
The conclusion for this question was "no", but I will ask for it to be
reconsidered.
In bug 1014377 I'm converting MFBT to Gecko style. Here are some real
one-line functions that I would have to convert to four lines each:
> static T inc(T& aPtr) { return IntrinsicAddSub<T>::add(aPtr, 1); }
> static T dec(T& aPtr) { return IntrinsicAddSub<T>::sub(aPtr, 1); }
> static T or_( T& aPtr, T aVal) { return __sync_fetch_and_or(&aPtr, aVal); }
> static T xor_(T& aPtr, T aVal) { return __sync_fetch_and_xor(&aPtr, aVal); }
> static T and_(T& aPtr, T aVal) { return __sync_fetch_and_and(&aPtr, aVal); }
> static ValueType inc(ValueType& aPtr) { return add(aPtr, 1); }
> static ValueType dec(ValueType& aPtr) { return sub(aPtr, 1); }
When it comes to questions of style, IMO clarity should trump almost
everything else, and spotting typos in functions like this is *much*
harder when they're multi-line.
Furthermore, one-liners like this are actually pretty common, and
paving the cowpaths is often a good thing to do.
Thoughts?
Nick