List of Phobos functions that allocate memory?

Jonathan M Davis jmdavisProg at gmx.com
Fri Feb 7 19:42:00 PST 2014


On Saturday, February 08, 2014 02:41:54 bearophile wrote:
> Jonathan M Davis:
> > The problem is that you need to check it. This is _slower_ than
> > exceptions in the normal case,
> 
> Right, but verifying the correctness of the Unicode encoding of a
> string probably on average requires much more than time than
> testing a single conditional. So I think this tiny added time is
> acceptable.

But why even do it in the first place then? The code is cleaner and less 
error-prone if it uses exceptions. The only argument I can see being made for 
not using exceptions with decode is efficiency, because it's more cumbersome 
to use if it's returning error values of some kind rather than just throwing 
in the rare case that there's a Unicode decoding error. It's also more error-
prone than using exceptions, because most code will just skip checking the 
result. That's one of the big reasons that error codes are generally a bad 
idea.

But since decode has to do the same validity checks whether it returns an 
invalid dchar or a Nullable!dchar or if it throws, I don't see why not having 
the exception buys us anything. It just makes the API worse.

- Jonathan M Davis


More information about the Digitalmars-d mailing list