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=0.6 required=5.0 tests=BAYES_00,TO_NO_BRKTS_FROM_MSSP autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,45b47ecb995e7a3 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-14 07:59:54 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!feed.textport.net!newsranger.com!www.newsranger.com!not-for-mail Newsgroups: comp.lang.ada From: Ted Dennison References: <3B6F1B2F.4FC3C833@gsde.hou.us.ray.com> <5ee5b646.0108071819.6e84e33d@posting.google.com> <3_Xc7.45$NM5.84779@news.pacbell.net> Subject: Re: Ada Idioms Progress Preview Message-ID: X-Abuse-Info: When contacting newsranger.com regarding abuse please X-Abuse-Info: forward the entire news article including headers or X-Abuse-Info: else we will not be able to process your request X-Complaints-To: abuse@newsranger.com NNTP-Posting-Date: Tue, 14 Aug 2001 10:59:38 EDT Organization: http://www.newsranger.com Date: Tue, 14 Aug 2001 14:59:38 GMT Xref: archiver1.google.com comp.lang.ada:11918 Date: 2001-08-14T14:59:38+00:00 List-Id: In article , Ole-Hjalmar Kristensen says... > >Ted Dennison writes: > >> It frees you from that problem in *some* cases. I find that most of the time >> I don't change the string, so I can declare it perfectly sized. When you do >> that, you are not storing the length explicitly, but rather implicitly in >> the array bounds. As others have mentioned, you also don't have to iterate .. >But you usually don't need to know the length of the string, precisely >because it has a sentinel value at the end :-) OK. Now you are just being perverse. :-) My point was, which is better: Not having to know the length because it is in a sentinel value at the end, or not having to know the length because it is in an attribute? Considering that the attribute can be read in one instruction (sometimes, it will even be staticly available to the compiler), while the sentinel must be laboriously searched for every time, I think the answer to this question is quite clear. >Perfectly-sized C string are no problems either: > >char x[] = "a perfect string"; True, they just do you no good. :-) >I was thinking of the case where you cannot statically allocate a >perfectly sized string, which pops up whenever you have to get >variable sized strings from somewhere, as you describe below. Agreed. But its a *rare* case. Unfortunately, one of the places it pops up regularly is in newbie code. Also, I would not say that this issue "pops up whenever you have to get variable size strings from somewhere". In intent, this statement is probably a tautology. The only true "variable-sized" strings are those that you may need to modify after creation for some reason. I find those quite rare, and in most cases avoidable by simply creating new strings in which to store the modified version of the old. I'd rather say that it pops when you are getting a string from some source and the interface author (for whatever reason), didn't provide you a string-return function interface. The other time it pops up is when you have to pass a string upward or across scope boundries (it can't be localized to the scope in which its length is decided), and the solution of doing a "new String'(watever)" is undesirable for some reason. All other times you can do just fine by waiting to declare the string until its length can be known. >Btw., I'm not saying that C strings are superior in general or trying >to start a war, just that there are cases when using a sentinel value >makes sense. The only time I could see it making sense is when the only time you will ever need to know a length is for terminating looping string operations. Even then, the only advantage you have is that the length only needed one byte for its encoding, rather than a full machine word. But even that slim advantage relies on Ada's 'Range being dynamic, which is not always the case. In *every* other case, it is an inferior solution. --- T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html home email - mailto:dennison@telepath.com