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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: Community Input for the Maintenance and Revision of the Ada Programming Language Date: Tue, 12 Sep 2017 23:04:46 +0200 Organization: A noiseless patient Spider Message-ID: References: <915874b5-52c0-4aa8-9023-82fddedb816f@googlegroups.com> Reply-To: nonlegitur@notmyhomepage.de Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 12 Sep 2017 21:04:47 -0000 (UTC) Injection-Info: reader.eternal-september.org; posting-host="466ec3cb9e5dcb851adc975461b40bef"; logging-data="29297"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18jYkBMD1YB9CWNncA1RjDNsA4PQ+O917Y=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: <915874b5-52c0-4aa8-9023-82fddedb816f@googlegroups.com> Cancel-Lock: sha1:fD4QcCQp9HS2uQ4DROVkRtStVog= Xref: news.eternal-september.org comp.lang.ada:48089 Date: 2017-09-12T23:04:46+02:00 List-Id: On 11.09.17 20:49, Tarjei Jensen wrote: > It is time to get counted strings into the standard. > > The key to counted strings is that they need to be first class objects. The compiler must know how to handle them. Just like it would do when it handles integers or reals of different sizes. You don't have to overload := in order to assign a byte sized integer to a word sized integer. And you don't need to overload operators to add or subtract them. 1. procedure Integer_2 is 2. type I16 is range 0 .. 100 with Size => 16; 3. type I32 is range 0 .. 100_000 with Size => 32; 4. X16 : I16; 5. X32 : I32; 6. begin 7. X32 := 100_000; 8. X16 := I16 (X32); | >>> warning: value not in range of type "I16" defined at line 2 >>> warning: "Constraint_Error" will be raised at run time 9. X16 := 100_000; | >>> value not in range of type "I16" defined at line 2 >>> static expression fails Constraint_Check 10. end Integer_2; So, an Ada compiler handles this by explaining that one cannot simply assign any number to any numeric variable. In the first case, even type conversion is diagnosed to be a predictably bad idea. > I strongly believe that implementing it as a general Ada feature will be ineffective. I know that it will be tempting to do so, but RESIST!!!!!! > > I also believe that educators will welcome such a move. Especially those who remember Turbo Pascal. > Educators have done enough harm by iterating what you suggest. Low level strings for high level needs? Strings? Group pressure and imitation make educators force students into using string literals and string I/O heavily. Professional programming makes me think that there shouldn't be any plain strings in any of today's programs. They can be replaced by typed objects that are modeled observing their use case. Then, all the trouble of representation using strings is hidden behind the walls of an ADT and if you make a new string based ADT, you'll be forced to think about what it shall mean to perform a type conversion. I'm not sure compilers can take care of that. If they can ease string handling, that's good, but not the end. And Ada can already help with this, see below. But text types can be expected to be more expressive and less hardware-ish than any plain composite of whatever characters. Consider this analogy. When using numbers, many programmers will have a range or set in mind, and some operations. Limits are a first lesson which running a programs will teach when it exceeds them. Big integers are not an option whenever they do not match number representations in I/O. Bytes and words, OTOH---these are any number of what are typically octets---are used in bit fiddling, not so much when performing "+". Besides, when talking about numbers, saying "bytes" and "words" can only be justified by crowd misuse. I'll be surprised if more than a few programmers even know the definition of "byte" in C. "Word"? Everyone feels justified, however, because everyone else around them creates the same assumption based results. Why teach that again? Note that in case you find a good reason for using strings, it is quite possible to use a storage pool. Then, from this pool, simply use allocators: X := new Message' ("Help me"); Y := new Messagio'("Aiuta me"); -- entering Little Italy: X := Y; So, if you want to perpetuate the hazards of strings, ask the ARG for a ready made storage pool for strings.