On Sunday, 8 February 2015 20:56:17 UTC+2, Stefan Ram wrote:
> Öö Tiib <
oot...@hot.ee> writes:
> >Major problem is that those solutions solve next to nothing. For example
> >information that automatic passenger counting system does overflow 'long'
> >with counted passengers is uninteresting because sane limits to that value
> >are way smaller than 'LONG_MAX'. It is indeed possible that for
> >something 2 147 483 647 is useful limit ... but for me it is rather hard
> >to imagine what it is.
>
> When you write a counting routine, you just need to specify its limits
> in the contract, whatever those limits might be: Version 1:
>
> /* This routine must not be called more often then 10 times */
> increment_passenger_count();
>
> Version 2:
>
> /* This routine must not be called more often then 10000000000000000000000 times */
> increment_passenger_count();
>
> Both versions are perfectly fine as long as the limit is clearly
> documented.
In what sense of perfection? Neither of the limits feels correct;
both feel way too odd. I either do not understand the purpose or
the documentation is defective or the requirements are gathered by
idiot. It would be irresponsible to code it away blindly and not to
consult rest of the team that is involved.
> The Ariane 4 had a subroutine with a velocity limitation. It was
> documented, too, but kind of »hidden« in the middle of a multi-page
> document. The oversight of this limitation than lead to the
> explosion of the Ariane 5 when that routine was re-used.
>
> This was not even UB. Instead the routine even /did/ detect
> the overflow and throw an exception IIRC. Ie., it was all
> »super clean«. Only problem was that there was no proper
> handler for that exception, so the exception reached the
> general top-level exception handler which terminated
> the process. In this case, however, ironically, everything
> would have been fine, if the exception would just have been
> ignored or not been created in the first place. In a sense,
> it was the well-intentioned overflow-detection that made
> the rocket explode.
>
> So, when the client does not react properly, even detection of
> overflow by the routine does not help.
If the software does not handle the situations then it does
not matter if it is saturated overflow, exception thrown or usual
undefined behavior. It will not work. You can have three or more
alternative systems that vote for mutual decision and you can keep
backup system warm for each that takes over on case of failure but
if all of those do not handle the situation then nothing helps.
> Lesson learned was that limitations of routines needs to
> be documented in a prominent place. And there, Java has an
> edge with JavaDoc, because it makes cleare where to write
> the documentation.
What edge? C++ community has had Doxygen and AFAIK both it and
JavaDoc were released 1997. The first document generator was
perhaps by Donald Knuth in 1981 ... nothing to do with Java.
Documentation is helpful but it does not write software.
Java has edge that Java's exception specifications work.
In C++ it is too easy to forget about exceptions since language
is unhelpful about those.