reef-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergiy Matusevych <sergiy.matusev...@gmail.com>
Subject Re: Is it a good idea for toString() to return null?
Date Tue, 05 Jan 2016 19:46:45 GMT
Hi folks,

Here's my $0.02:

1) toString() is an overloaded method, and it *always* should return a
String.
2) toString() results should be composable, i.e. an expression a.toString()
+ b.toString() should never thorow, and always produce a String.

I don't really know how we want to implement a deep toString() for all the
underlying fields of an object, but on the outside we should always return
a String.

Cheers,
Sergiy.




On Tue, Jan 5, 2016 at 11:32 AM, Markus Weimer <markus@weimo.de> wrote:

> On 2016-01-05 09:34, Mariia Mykhailova wrote:
> > Any opinions? Personally I feel we shouldn't return a special value
> > for an otherwise good class which for whatever reason failed to
> > serialize, so we should either fall back to old conversion style or
> > throw an exception
>
> We can't change the definition of `toString()`, so that is out of the
> question. We also don't want to return `null`. I think throwing an
> exception is in order here:
>
> If we silently fix the serializer with hand written code, we then have
> to maintain this forever, negating the benefits of a serialization
> library in the first place. At the same time, this code really should
> never throw exceptions in real use. Hence, getting a bug report for when
> it does seems very useful :-)
>
> Markus
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message