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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.90.202 with SMTP id by10mr47473631pab.39.1438282275224; Thu, 30 Jul 2015 11:51:15 -0700 (PDT) X-Received: by 10.140.47.68 with SMTP id l62mr697093qga.42.1438282275172; Thu, 30 Jul 2015 11:51:15 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!feeder1.cambriumusenet.nl!82.197.223.103.MISMATCH!feeder3.cambriumusenet.nl!feed.tweaknews.nl!209.85.213.216.MISMATCH!f3no5066111igg.0!news-out.google.com!78ni309qge.1!nntp.google.com!z61no4241971qge.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 30 Jul 2015 11:51:14 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=81.203.145.32; posting-account=AFCLjAoAAABJAOf_HjgEEEi3ty-lG5m2 NNTP-Posting-Host: 81.203.145.32 References: <2df4698f-4c8e-457c-822d-209cb2f8ab5e@googlegroups.com> <014427b1-ff7a-4a69-82e6-0330af77ed96@googlegroups.com> <1438244829.17005.26.camel@obry.net> <0a8104af-4ebb-4d82-92e5-6ba7289272ce@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <262cbf86-25a0-4802-b72e-ec6e650e1dc7@googlegroups.com> Subject: Re: Running a preprocessor from GPS? From: EGarrulo Injection-Date: Thu, 30 Jul 2015 18:51:15 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:27235 Date: 2015-07-30T11:51:14-07:00 List-Id: On Thursday, July 30, 2015 at 8:12:13 PM UTC+2, Jeffrey R. Carter wrote: > On 07/30/2015 04:51 AM, EGarrulo wrote: > > > > Exactly! And: > > > > Printf ("Mr %Arg you have won %Arg dollars!\n", Surname, Amount); > > > > is much more readable than: > > > > Put ("Mr "); > > Put (Surname); > > Put (" you have won "); > > Put (Amount); > > Put (" dollars!"); > > New_Line; > > A nice strawman argument. No one would ever write that. Depending on what Printf > does with Amount, one would either write > > Ada.Text_IO.Put_Line (Item => "Mr " & Surname & " you have won" & > Money'Image (Amount) & " dollars!"); > > or > > Ada.Text_IO.Put (Item => "Mr " & Surname & " you have won "); > Money_IO.Put (Item => Amount, ...); > Ada.Text_IO.Put_Line (Item => " dollars!"); > > both of which I find easier to read than the Printf call. OK. Now please write the code so that it could be easily adapted to a different language by possibly swapping the arguments that are fed to the output string (this may not cover all existing languages, but it could be good enough). I would reimplement Printf to accept a format with positional arguments, like "Mr %1 you have won %2 dollars!\n". Then I would define a new format string for the alternative output and I would be done. This was possible because a solution based on a formatting procedure recognizes that output should easily adaptable, something that hard-coded concatenations of strings are not.