http://wiki.dlang.org/DIP25

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Wed Dec 31 13:34:09 PST 2014


On Wed, 31 Dec 2014 09:40:17 +0000
Tobias Pankrath via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> > 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.
> 
> You could preallocate the exception or use an out parameter.

i can do alot of things here... and something is not possible with
`ref`. this will not work:

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

ther is no way to point ref to dummy temp by default, sure, i can write
two functions:

  auto parseNumber (string s, out bool error);
  auto parseNumber (string s) { bool dummy; return parseNumber(s, dummy); }

see how it's turning to messy code with copypasta? the thing is that
`ref` params can't be ommited by specifying `null` here, and there is
no `dummy` placeholder for refs. the same is true for `out`s, of
course.

and preallocating exception is loosing valuable information about the
place where that exception was thrown. or i have to write a module
which emulates `new` for exception objects and don't forget to check if
it is "D exception" or "my exception" in `catch` block, so i can
manually release my exceptions. ah, i'd better go with my ugly pointers.
-------------- 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/3e5a6f01/attachment.sig>


More information about the Digitalmars-d mailing list