On 09/08/2009 23:37, Andre Poenitz wrote:
On Sun, Aug 09, 2009 at 06:19:43PM +0200, you...@lyx.org wrote:
Author: younes Date: Sun Aug  9 18:19:43 2009 New Revision: 30947 URL:
http://www.lyx.org/trac/changeset/30947

Log: Text::Inset(): now returns a reference in order to make clear
that the owner is mandatory.

One of the things I learned recently is that code gains clarity if
passing by-ref or by-pointer is based on type, not in the fact whether
the thing can be zero or not

I understand that this is pretty much diametral to what is customarily
taught, but it is so much easier to remember 'a Buffer is not (easily)
copyable, so pass it by pointer' as opposed to 'this particular Buffer
instance cannot be zero at this particular time, so I hope the function
accepting it as argument already knows it and therefore takes a
reference'.

Indeed, I like the mandatory aspect of passing a reference as in "I don't want the caller to test for pointer nullity".

Pointer-or-reference-by-type also reduces "line noise" if form of
'*' and'&' to a minimum. And the basic rule "reference if copyable
(i.e. string, Paragraph, ...), pointer if not (Buffer, BufferView, ...)"
is really easy to remember.

Just food for thought.

I'll think about it...

Abdel.

Reply via email to