http://wiki.dlang.org/DIP25

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Tue Dec 30 22:04:28 PST 2014


On Tue, 30 Dec 2014 21:28:32 -0800
Andrei Alexandrescu via Digitalmars-d <digitalmars-d at puremagic.com>
wrote:

> The alternate hypothesis is "ref" is being misused. "ref" is for 
> propagating changes into the arguments. It should be rare that code does 
> not actually care for that. Unlike in C++, ref is seldom needed for 
> optimizing copies away. -- Andrei
slightly derailing comment: the small annoyance of `ref` is that it
hides the fact that i'm passing argument by reference. i still can't
fully convince myself that i should use `ref` instead of explicit
pointer, 'cause:

  void foo (ref int a);
  void bar (int a);

  // and the following calls looks all the same T_T
  int a;
  foo(a);
  bar(a);

but:

  void foo (int* a);
  void bar (int a);

  // wow, we don't even need to look at the signatures to find
  // that `foo` wants a reference and that it therefore can
  // modify `a`!
  int a;
  foo(&a);
  bar(a);

another "cosmetic issue" that bugs me alot.

p.s. and with pointers it's easy to write something like this:

  auto parseNumber (string s, bool* error=null);

yes, i know about exceptions... which blocks `@nogc`. not yummy.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20141231/33e10af6/attachment.sig>


More information about the Digitalmars-d mailing list