Re: Out parameters, References vs. Pointers (was: Proposal: use nsresult& outparams in constructors to represent failure)

2016-04-25 Thread Benjamin Smedberg
I used to be the module owner of our coding conventions, but I believe that
duty has now fallen on Nathan Froyd with the establishment of the new
module covering c++ idioms and usage, noted in this governance thread:
https://groups.google.com/forum/#!searchin/mozilla.governance/froyd/mozilla.governance/NwsV30-qaWc/I7WgNPqVDAAJ

--BDS

On Thu, Apr 21, 2016 at 12:01 PM, Jason Orendorff 
wrote:

> More evidence that our coding conventions need an owner...
>
> -j
>
>
> On Wed, Apr 20, 2016 at 10:07 PM, Kan-Ru Chen (陳侃如) 
> wrote:
>
> > Nicholas Nethercote  writes:
> >
> > > Hi,
> > >
> > > C++ constructors can't be made fallible without using exceptions. As a
> > result,
> > > for many classes we have a constructor and a fallible Init() method
> > which must
> > > be called immediately after construction.
> > >
> > > Except... there is one way to make constructors fallible: use an
> > |nsresult&
> > > aRv| outparam to communicate possible failure. I propose that we start
> > doing
> > > this.
> >
> > Current coding style guidelines suggest that out parameters should use
> > pointers instead of references. The suggested |nsresult&| will be
> > consistent with |ErrorResult&| usage from DOM but against many other out
> > parameters, especially XPCOM code.
> >
> > Should we special case that nsresult and ErrorResult as output
> > parameters should always use references, or make it also the default
> > style for out parameters?
> >
> > I think this topic has been discussed before didn't reach a
> > consensus. Based the recent effort to make the code using somewhat
> > consistent style, should we expend on this on the wiki?
> >
> >Kanru
> > ___
> > dev-platform mailing list
> > dev-platform@lists.mozilla.org
> > https://lists.mozilla.org/listinfo/dev-platform
> >
> ___
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Out parameters, References vs. Pointers (was: Proposal: use nsresult& outparams in constructors to represent failure)

2016-04-22 Thread Eric Rescorla
I agree with this.

FWIW, the Google style guide requires that reference params be const.
https://google.github.io/styleguide/cppguide.html#Reference_Arguments

-Ekr


On Thu, Apr 21, 2016 at 9:51 PM, Jeff Gilbert  wrote:

> Pointers are prefereable for outparams because it makes it clearer
> what's going on at the callsite. (at least indicating that something
> non-trivial is happening)
>
> On Wed, Apr 20, 2016 at 8:07 PM, Kan-Ru Chen (陳侃如) 
> wrote:
> > Nicholas Nethercote  writes:
> >
> >> Hi,
> >>
> >> C++ constructors can't be made fallible without using exceptions. As a
> result,
> >> for many classes we have a constructor and a fallible Init() method
> which must
> >> be called immediately after construction.
> >>
> >> Except... there is one way to make constructors fallible: use an
> |nsresult&
> >> aRv| outparam to communicate possible failure. I propose that we start
> doing
> >> this.
> >
> > Current coding style guidelines suggest that out parameters should use
> > pointers instead of references. The suggested |nsresult&| will be
> > consistent with |ErrorResult&| usage from DOM but against many other out
> > parameters, especially XPCOM code.
> >
> > Should we special case that nsresult and ErrorResult as output
> > parameters should always use references, or make it also the default
> > style for out parameters?
> >
> > I think this topic has been discussed before didn't reach a
> > consensus. Based the recent effort to make the code using somewhat
> > consistent style, should we expend on this on the wiki?
> >
> >Kanru
> > ___
> > dev-platform mailing list
> > dev-platform@lists.mozilla.org
> > https://lists.mozilla.org/listinfo/dev-platform
> ___
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Out parameters, References vs. Pointers (was: Proposal: use nsresult& outparams in constructors to represent failure)

2016-04-21 Thread Jeff Gilbert
Pointers are prefereable for outparams because it makes it clearer
what's going on at the callsite. (at least indicating that something
non-trivial is happening)

On Wed, Apr 20, 2016 at 8:07 PM, Kan-Ru Chen (陳侃如)  wrote:
> Nicholas Nethercote  writes:
>
>> Hi,
>>
>> C++ constructors can't be made fallible without using exceptions. As a 
>> result,
>> for many classes we have a constructor and a fallible Init() method which 
>> must
>> be called immediately after construction.
>>
>> Except... there is one way to make constructors fallible: use an |nsresult&
>> aRv| outparam to communicate possible failure. I propose that we start doing
>> this.
>
> Current coding style guidelines suggest that out parameters should use
> pointers instead of references. The suggested |nsresult&| will be
> consistent with |ErrorResult&| usage from DOM but against many other out
> parameters, especially XPCOM code.
>
> Should we special case that nsresult and ErrorResult as output
> parameters should always use references, or make it also the default
> style for out parameters?
>
> I think this topic has been discussed before didn't reach a
> consensus. Based the recent effort to make the code using somewhat
> consistent style, should we expend on this on the wiki?
>
>Kanru
> ___
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Out parameters, References vs. Pointers (was: Proposal: use nsresult& outparams in constructors to represent failure)

2016-04-21 Thread Jason Orendorff
More evidence that our coding conventions need an owner...

-j


On Wed, Apr 20, 2016 at 10:07 PM, Kan-Ru Chen (陳侃如) 
wrote:

> Nicholas Nethercote  writes:
>
> > Hi,
> >
> > C++ constructors can't be made fallible without using exceptions. As a
> result,
> > for many classes we have a constructor and a fallible Init() method
> which must
> > be called immediately after construction.
> >
> > Except... there is one way to make constructors fallible: use an
> |nsresult&
> > aRv| outparam to communicate possible failure. I propose that we start
> doing
> > this.
>
> Current coding style guidelines suggest that out parameters should use
> pointers instead of references. The suggested |nsresult&| will be
> consistent with |ErrorResult&| usage from DOM but against many other out
> parameters, especially XPCOM code.
>
> Should we special case that nsresult and ErrorResult as output
> parameters should always use references, or make it also the default
> style for out parameters?
>
> I think this topic has been discussed before didn't reach a
> consensus. Based the recent effort to make the code using somewhat
> consistent style, should we expend on this on the wiki?
>
>Kanru
> ___
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Out parameters, References vs. Pointers (was: Proposal: use nsresult& outparams in constructors to represent failure)

2016-04-20 Thread 陳侃如
Nicholas Nethercote  writes:

> Hi,
>
> C++ constructors can't be made fallible without using exceptions. As a result,
> for many classes we have a constructor and a fallible Init() method which must
> be called immediately after construction.
>
> Except... there is one way to make constructors fallible: use an |nsresult&
> aRv| outparam to communicate possible failure. I propose that we start doing
> this.

Current coding style guidelines suggest that out parameters should use
pointers instead of references. The suggested |nsresult&| will be
consistent with |ErrorResult&| usage from DOM but against many other out
parameters, especially XPCOM code.

Should we special case that nsresult and ErrorResult as output
parameters should always use references, or make it also the default
style for out parameters?

I think this topic has been discussed before didn't reach a
consensus. Based the recent effort to make the code using somewhat
consistent style, should we expend on this on the wiki?

   Kanru
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform