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 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,38fc011071df5a27 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-31 02:24:36 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!fu-berlin.de!uni-berlin.de!dialin-145-254-036-245.arcor-ip.NET!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ideas for Ada 200X Date: Sat, 31 May 2003 11:27:01 +0200 Organization: At home Message-ID: References: <6a90b886.0305262344.1d558079@posting.google.com> <3ED41344.7090105@spam.com> <3ED46D81.FF62C34F@0.0> <3ED46E07.4340CABC@0.0> <3ED4F3FD.A0EF7079@alfred-hilscher.de> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: dialin-145-254-036-245.arcor-ip.net (145.254.36.245) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: fu-berlin.de 1054373074 7612701 145.254.36.245 (16 [77047]) User-Agent: KNode/0.7.1 Xref: archiver1.google.com comp.lang.ada:38182 Date: 2003-05-31T11:27:01+02:00 List-Id: Russ wrote: > Stephen Leake wrote in message > news:... >> 18k11tm001@sneakemail.com (Russ) writes: >> >> > > Occasionally I run into code that looks something like: >> > > >> > > production_total( total_class ).shift( shift_index ) := >> > > production_total( total_class ).shift( shift_index ) + count; >> > > >> > > That would read a lot cleaner as: >> > > >> > > production_total( total_class ).shift( shift_index ) += count; >> > >> > Couldn't have said it better myself. >> >> What is wrong with having a style guide that says: >> >> "If you have statements like >> production_total( total_class ).shift( shift_index ) := >> production_total( total_class ).shift( shift_index ) + count; >> >> you must write an appropriate Increment function, and use it instead" > > Because it's one hell of a lot easier, not to mention less > error-prone, to just use +=. That's what Ada is all about. > > I don't blame anyone for disliking ++, but += should be your friend. > >> Problem solved; no need for language change or compiler support. > > Yes, but it's far from the best and simplest solution. > >> > And let's not forget that +=, -=, etc. also allow for more efficient >> > in-place vector/matrix operations because they avoid the need for a >> > temporary. If you don't understand this, that's OK, but please don't >> > argue with me because you will be wrong. >> >> Same argument; a package that provides vector/matrix math must provide >> an appropriate in-place Increment function. >> >> Ada is about ease of reading, _not_ about ease of writing. > > += improves readability too! Which is clearer, > > A += B > > or > > Add(A,B) > > The latter doesn't make clear what exactly is being done. Is the > result ending up in A or B? Yes, you can write something that would be > a bit clearer, like > > Add ( Into=>A, Add=>B ) > > but it still would not be as clear or as elegant as A += B. > > In-place operations on a variables are so fundamental that they > deserves their own syntax. If you can't handle that, what kind of > "programmer" are you? Maybe yes, maybe not. Consider generics. If you have several kinds of operations, you have to pass all of them as the parameters of a generic. You never know what would be useful in the next implementation of the generic body. So generic type Matrix is private; function "+" (L, R : Matrix) return Matrix; function "++" (L : Matrix) return Matrix; procedure "+=" (L : in out Matrix; R : Matrix); ... If you add here two additional types Element, and Vector, you will spend the rest of your life just completing this specification! (:-)) -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de