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: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: What do you think about this? Date: Wed, 24 Jun 2015 15:30:28 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <9894cde7-2cf8-4060-be65-857812ad7b09@googlegroups.com> <17436268-aceb-461f-bdcf-eee8436cd0e6@googlegroups.com> <86y4jaqzdx.fsf@stephe-leake.org> <86oak5qulb.fsf@stephe-leake.org> <78882aed-4063-409b-a92e-6025c3097a52@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 24 Jun 2015 22:29:09 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="a3855fbfe1a666be9aefba0563039ed5"; logging-data="7660"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18P1M2U/MeziJDyCzn4L8SqdUj/rX9PY+Q=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: <78882aed-4063-409b-a92e-6025c3097a52@googlegroups.com> Cancel-Lock: sha1:9POPrP9BO4WUtE5/8KjPdVL3aSc= Xref: news.eternal-september.org comp.lang.ada:26464 Date: 2015-06-24T15:30:28-07:00 List-Id: On 06/24/2015 01:50 PM, Laurent wrote: > On Wednesday, 24 June 2015 19:20:28 UTC+2, Jeffrey R. Carter wrote: > >> I only looked at the main-program procedure, but my comments are >> >> * Inconsistent use of blank lines > > Where? What would be a consistent use? I remember reading some online text > about the correct formatting and whatever but I have already forgotten where > and what. If you a referring to the declaration of the different objects > inside the Generate procedure, well those I would like to hide beneath the > carpet because it looks awful. Not sure if the compiler will find them > there. You have to decide for yourself why you use blank lines, and then use them for that purpose. Blank lines have no meaning to the compiler, so you use them to help the reader. When should you have a blank line? When should you have 2 blank lines? I personally use blank lines to separate compound statements from adjacent lines with the same indentation level. >> * Inconsistent indentation > > Where? Why? I don't pay special attention to the indentation. Type something, > select it and Tab. GPS makes the rest. Sometimes that fails completely. If you don't care about indentation, why do you have any? Again, indentation is to help the reader. Usually the indentation level should reflect the nesting level of the statement. At the Ada Launch, Ichbiah talked about what he called "comb structures", and how statements are indented to show that they are nested in such structures. Examples of comb structures are procedure George is | | begin | | exception | | end George; if C1 then | | elsif C2 then | | elsif C3 then\ | | else | | end if; Some combs only have 2 teeth: Forever : loop | | end loop; The '|' lines are replaced in real code with declarations or statements nested inside the comb structure, and indented > It is returning a bounded String because I have problems with types of > Strings and I am quite pissed because of that. The bounded one is doing the > things automagically, like I think it should be. But thats only my opinion. > The only thing which is missing is an automagical adaption of the length. > > Sort of a dynamical allocating: > > So Example_A : Bound_String := "123" so the Example_A'Length = 3 > Example_B: Bound_string:= "Only a test" Example_B'Length = 11 Note your inconsistent use of whitespace here. Example_A has spaces on both sides of ':' and ":="; Example_B on on the right. > Without having to define a maximum length in an instantiation before you can > actually use it. But it should be possible to modify it later on.(IIRC in > Java it is different) And being the same type so that no conversion at all is > required. > > Perhaps Standard.Strings is doing that? No idea. String is declared as type String is array (Positive range <>) of Character; It's an unconstrained type just like any other unconstrained type. Some languages have strings that are special, and users cannot declare a type like them, but in Ada they are just the same as any other array. Your confusion is likely from expecting String to have special properties; if you can stop thinking that way then String will probably make more sense. Of course, String objects have to be constrained: S1 : String (7 .. 9); S2 : String := "Only a test"; S1 is explicitly constrained, while S2 gets the constraints of its initialization value (1 .. 11). Once constrained, the bounds of String object cannot change. You can change the contents, but not the length, so you can say S2 (1 .. 4) := "Just"; -- S2 is now "Just a test" because the array value on the right has the same length as the array object on the left (4). You can't say S2 := "123"; because the array value on the right has a length of 3, which is not the same as the object on the left (11); In your case you have a function sort of like function F return Bounded_String is R : Bounded_String; begin -- F R := +(A & B & C); return R; end F; where A, B, and C are of type String. You could eliminate R and just say return +(A & B & C); You use this in a call to a file operation such as Create: Create (Name => +F, ...); The parameter Name is of type String. What you could have done is function F return String is -- No declarations begin -- F return A & B & C; end F; and then Create (Name => F, ...); I hope that helps make things clearer. -- Jeff Carter "Well, a gala day is enough for me. I don't think I can handle any more." Duck Soup 93