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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f25e853f410d55da X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Dynamicly declaring arrays (was: Time to join the fold?) Date: 1999/02/01 Message-ID: #1/1 X-Deja-AN: 439415380 Sender: matt@mheaney.ni.net References: <78abg4$cnc$1@its.hooked.net> <78i8s4$hth$1@its.hooked.net> <78iq2m$br9$1@nnrp1.dejanews.com> <794gg7$ib$1@nnrp1.dejanews.com> NNTP-Posting-Date: Mon, 01 Feb 1999 09:06:11 PDT Newsgroups: comp.lang.ada Date: 1999-02-01T00:00:00+00:00 List-Id: dennison@telepath.com writes: > In article , > Matthew Heaney wrote: > > dennison@telepath.com writes: > > > > > In a severe jam a declare block can be used to get a localized > > > constant string, or one of the ada.strings packages can be used. > > > > Rather odd to describe using a declare block to declare a string object > > only in a "severe jam," since this is the normal, intended usage! > > > > True, that is what they are there for. But my style is to avoid declare > blocks if I can help it. Typicaly I'd try to break off a proper subroutine > first. When I do use declare blocks, its usually just to provide a localized > exception handler (and in that case of course the "declare" isn't nessecary). > > I'm not entirely sure I can defend this aversion to declare blocks in a > rational way, so if anyone has a rationale as to why its perfecly acceptable > to have declare blocks liberally sprinkled throught their code, I'm all ears. The purpose of a declare block is to localize an object declaration, so you can minimize the distance between the declaration of object and its actual use. The purpose of a subprogram is algorithmic abstraction. A declare block is not an abstraction of an algorithm. I do "liberally sprinkle my code" with declare blocks, especially for declaring the result of a function that returns an unconstrained array (i.e. string). This localizes the object, and avoids an assignment of a string value to a string object, so there won't be any length mismatch problems. The point of this thread is about how to effect an ada mind-set. The liberal use of declare blocks is a common Ada idiom.