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: 103376,2a34b7ad6c6a0774 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.nethere.com!news.nethere.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 11 Aug 2010 02:42:04 -0500 Newsgroups: comp.lang.ada Subject: Re: Efficiency of code generated by Ada compilers From: csampson@inetworld.net (Charles H. Sampson) Date: Wed, 11 Aug 2010 00:42:02 -0700 Message-ID: <1jn1a4o.1dfllwo1uin3imN%csampson@inetworld.net> References: User-Agent: MacSOUP/2.8.2 (Mac OS X version 10.4.11 (PPC)) X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-6B3fMz5tbLJDKhGPbOvHxutHZADy3GynwnwZL/AKQT2mcZkImCElxZTh8cpkTA5ljEhz1yqivpHVKRp!HVej7OsXIYnkeA4MEMQ/zOxfMaaeLNJr3Jouo/7O7iK19tc9ERRHDAZp1y4lVu2y5ThxdBZ6m1ZN!t8Wjxoe2E05q6sDr4W70EP7LaDBvSyY= X-Complaints-To: abuse@nethere.com X-DMCA-Complaints-To: abuse@nethere.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Xref: g2news1.google.com comp.lang.ada:13107 Date: 2010-08-11T00:42:02-07:00 List-Id: wrote: > > And it would be desirable, because in most cases the explicit > > "mod" (or "%") is more readable. > > I := Ring_Indices'succ(I); > vs > I := (I + 1) mod Ring_Size; > or > Bearing := Bearing + Turn_Angle; > vs > Bearing := (Bearing + Turn_Angle) mod 360; I'd be interested in hearing reactions to something I did. About a year ago I had reason to do something similar to the Bearing/Turn_Angle example. To avoid having to do a lot of background, I'll just restate what I did in terms of Bearing/Turn_Angle. Bearing and Turn_Angle as integers are way too inaccurate for the application I was working on, which involved real-time position calculations at a high rate. So Bearing and Turn_Angle were defined as two (distinct) types derived from Long_Precision. (They were defined as types because "Bearing" and "Turn_Angle" are non-specific nouns. See the Ada Style Guide.) I then overloaded "+" and "-" for (Bearing, Turn_Angle) arguments and Bearing return value. In those functions is where the mod 360 occurred. (Actually, mod 360.0, as it were.) There were two advantages to doing that. The more important was that previously both of the kinds of values were being represented as subtypes of Long_Precision and programmers would occasionally interchange them and cause big debugging problems. The second was removing the "mod" from sight, which allowed the programmers to simply think of taking a bearing, turning an angle, and getting the resulting bearing, without worrying about all the niceties that might be going on inside "+". Of course, new programmers coming on the project had to be taught about the overloads and that they should not be writing elaborate if-then-elses when they wanted to turn the ship. Charlie -- All the world's a stage, and most of us are desperately unrehearsed. Sean O'Casey