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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,8d8e831905c2cf39 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!news.tornevall.net!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: My first solution Date: Wed, 15 Jun 2011 12:43:15 -0700 Organization: TornevallNET - http://news.tornevall.net Message-ID: References: <3420583b-a063-4634-9989-580888e38eee@f2g2000yqh.googlegroups.com> NNTP-Posting-Host: ceb11f4e2b31e603780c7000aa6a79af Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: 7a3271c4b4171aa25f58c014e60d948b X-Complaints-To: abuse@tornevall.net User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 X-Complaints-Language: Spoken language is english or swedish - NOT ITALIAN, FRENCH, GERMAN OR ANY OTHER LANGUAGE! In-Reply-To: <3420583b-a063-4634-9989-580888e38eee@f2g2000yqh.googlegroups.com> X-UserIDNumber: 1738 X-Validate-Post: http://news.tornevall.net/validate.php?trace=7a3271c4b4171aa25f58c014e60d948b X-Complaints-Italiano: Non abbiamo padronanza della lingua italiana - se mandate una email scrivete solo in Inglese, grazie X-Posting-User: 0243687135df8c4b260dd4a9a93c79bd Xref: g2news1.google.com comp.lang.ada:19860 Date: 2011-06-15T12:43:15-07:00 List-Id: On 06/14/2011 11:01 PM, juanmiuk wrote: > > function Format_Num ( Width_Num : Integer; What does it mean to call this function with Width_Num not in Positive? Using an appropriate subtype in cases like this helps document how the subprogram should be used. > The_Number : Integer ) return > String is > > Temp_Length : My_Num := My_Num'Image(The_Number)'Length; > Separador : String := (Width_Num - Temp_Length) * ' '; These are both never assigned to, so they can be declared as constants. While this can assist the compiler in optimization, its primary benefit is letting the reader know you never change these. Note that the Left parameter of Ada.Strings.Fixed."*" is subtype Natural. This will raise Constraint_Error if Width_Num - Temp_Length < 0. This helps define what subtype Width_Num should be, indicates some comments are probably needed to describe a precondition [Width_Num >= My_Num'Image (The_Number)'Length], and perhaps points to some ways the function can be improved [if Width_Num < My_Num'Image (The_Number)'Length, return My_Num'Image (The_Number)?] "Separador" would probably be named "Padding" in English. > for I in My_Num range 1 .. 10 loop for I in My_Num loop What you have done here is effectively duplicate the functionality of Ada.Text_IO.Integer_IO.Put. -- Jeff Carter "Spam! Spam! Spam! Spam! Spam! Spam! Spam! Spam!" Monty Python's Flying Circus 53