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,7ae8393ad9100e97 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.204.129.78 with SMTP id n14mr458828bks.5.1324083830988; Fri, 16 Dec 2011 17:03:50 -0800 (PST) MIME-Version: 1.0 Path: jh9ni20226bkb.0!nntp.google.com!news2.google.com!goblin1!goblin.stu.neva.ru!news.tornevall.net!news.jacob-sparre.dk!pnx.dk!jacob-sparre.dk!ada-dk.org!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Ada2012 : When to use expression functions rather than function bodies? Date: Fri, 16 Dec 2011 19:03:46 -0600 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <1s7pzkf4hmdl5.15o0cmwoy5alh$.dlg@40tude.net> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1324083829 4352 69.95.181.76 (17 Dec 2011 01:03:49 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Sat, 17 Dec 2011 01:03:49 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Date: 2011-12-16T19:03:46-06:00 List-Id: "Dmitry A. Kazakov" wrote in message news:1s7pzkf4hmdl5.15o0cmwoy5alh$.dlg@40tude.net... > On Fri, 16 Dec 2011 04:25:09 -0800 (PST), Martin wrote: > >> Are there any good arguments for *not* replacing all simple, single >> line functions that don't [directly] access package body state >> information with expression functions? > > 1. Readability > 2. Proper encapsulation (to have interface and implementation separated) > 3. Re-use (the same function must be refactored) > 4. Maintainability (because of 1..3) > 5. Safety (proper bodies are defined on the context where they have no > access to the caller's context, otherwise than through parameters) > 6. Deployment (proper bodies can be put into a library, have versions etc) > 7. It is not Ada Umm, an expression function is just another (shorter) way to write a function body, so it hard to imagine that there is any difference. Using them to replace a function body *in place* is completely harmless. I suppose you are talking about the use of expression functions directly in a specification (without an explicit body), which is a totally separate issue. There, I tend to agree with you in the sense that they ought to be used in moderation. The intent was to use them for things like accessors for private components where there is no real value to the separate body. For those sorts of uses, the issues you talk about above don't arise. (How could you "refactor" Obj.Field??). Moreover, everything in the private part is part of the implementation anyway; you're still enforcing that separation so long as the expression functions are in the private part. Randy.