From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Bob Duff Newsgroups: comp.lang.ada Subject: Re: function Is_Open (File : File_Type) return Boolean; :Text_io Date: Wed, 28 Oct 2015 16:36:09 -0400 Organization: A noiseless patient Spider Message-ID: <87d1vy3f46.fsf@theworld.com> References: <87twpd2qlo.fsf@theworld.com> <1pj15r7pul7f1.15qgdyrc8k133$.dlg@40tude.net> <87pp0030c1.fsf@theworld.com> <135hiczk56x02.1xixcme8btbl4.dlg@40tude.net> <1dzlgoh4u2j7t$.1un3dfy0oeigd$.dlg@40tude.net> <190shqocxd87d$.1d68ghgqgbvfs$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="9e4a124ceb0e8a60134d2d30eac9ea6f"; logging-data="6978"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XlBJ7KuI2FnjOBIbfqmbE" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:Ny1p5ZPUIJM922LOqgAurvMqpog= sha1:qhXX0TgI+r4/zPR2RLvWWwOrXZM= Xref: news.eternal-september.org comp.lang.ada:28099 Date: 2015-10-28T16:36:09-04:00 List-Id: "Dmitry A. Kazakov" writes: > On Wed, 28 Oct 2015 12:06:33 +0100, Georg Bauhaus wrote: >> However, another use of predicates is to document assumptions. > > Documenting *shall* have *no* run-time effects. Really?! In C, we can write: int num_gizmos = 0; // num_gizmos is always between 0 and 1024. In Ada, we can write: type Gizmo_Count is range 0 .. 2**10; Num_Gizmos: Gizmo_Count := 0; IMHO, documenting the 0..1024 requirement in executable code is much better than using a comment: - It's more likely to be correct, especially if we have a good test suite. The comment just says what the original programmer thought was true. Maybe they were wrong. More likely, they were right, but subsequent changes elsewhere made the comment wrong. - If I'm debugging a specific bug, and the run-time checks on Num_Gizmos don't fail, I know the problem isn't caused by an out-of-bounds value of that variable. Even if the "range 0..2**10" is wrong, it's not the cause of THIS bug. - English comments can be ambiguous -- sometimes "between" means inclusive of the end points, sometimes exclusive (although we can guess "inclusive" in this case). On the other hand, I know exactly what ".." means. By the way, what exactly do you mean by "shall"? A native speaker of English doesn't usually use that word, except in legal documents and the like. You seem to use the word "shall" to express opinions about the way things ought to be, which seems like an odd usage to me. - Bob