comp.lang.ada
 help / color / mirror / Atom feed
* Re: Finalization of package instance
  2000-01-18  0:00 Finalization of package instance Mario Amado Alves
  2000-01-18  0:00 ` Jeff Carter
@ 2000-01-18  0:00 ` Robert A Duff
  1 sibling, 0 replies; 8+ messages in thread
From: Robert A Duff @ 2000-01-18  0:00 UTC (permalink / raw)


Mario Amado Alves <maa@di.fct.unl.pt> writes:

> How do I define the finalization of an instantiation of a generic package?

Declare a controlled type, and put a single of object of the type in the
package body.  The finalization of this object can do whatever package
finalization you want to do.

- Bob




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Finalization of package instance
  2000-01-18  0:00 Finalization of package instance Mario Amado Alves
@ 2000-01-18  0:00 ` Jeff Carter
  2000-01-18  0:00   ` Matthew Heaney
  2000-01-19  0:00   ` Statements per function point Herv� BITTEUR
  2000-01-18  0:00 ` Finalization of package instance Robert A Duff
  1 sibling, 2 replies; 8+ messages in thread
From: Jeff Carter @ 2000-01-18  0:00 UTC (permalink / raw)


Mario Amado Alves wrote:
> 
> How do I define the finalization of an instantiation of a generic package?

Note that the instantiation of a generic package IS a package. The fact
that you have a generic is not important here. Instantiation takes place
at compile time.

> 
> For example, generic package Datalink initializes a connection with a
> database server; when the package instance dies, the connection must be
> closed (cleanly) via the proper procedure call. How does one automatize
> this? E.g.
> 
>   generic
>     Database_Server_Address: String;
>   package Datalink is
>     ...
>   end Datalink;
> 
> The body:
> 
>   package body Datalink is
> 
>     ...
> 
>   begin
> 
>     Connect(Database_Server_Address);
> 
>   finalize -- HERE, I WHICH THIS WAS POSSIBLE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> 
>     Disconnect(Database_Server_Address);
> 
>   end Datalink;
> 
> Then,
> 
>   procedure Main is
>     package Main_Data_Server is
>       new Datalink("some.address.net");
>   begin
>     ...
>   end Main
> 
> Now, when Main has complete running the disconnection should have been done
> automatically. Is there an idiom to accomplish this in Ada?

Ada provides finalization for types derived from
Ada.Finalization.Controlled and Ada.Finalization.Limited_Controlled, but
not for packages.

You have a couple of workarounds:

1. Provide a Disconnect operation and require the client to call it. I
find this unacceptable, but many systems have been successfully
implemented with this kind of finalization.

2. I assume that package Datalink provides some visible operations,
represented by "..." in your example. Provide a limited controlled type
that is a parameter to these operations:

with Ada.Finalization;
package Datalink is
   type Handle (Server_Address : access String) is limited private;

   procedure Op (Server : in Handle; ...);
   ...
private -- Datalink
   type Handle (Server_Address : access String) is new
   Ada.Finalization.Limited_Controlled with null record;

   procedure Finalize (Object : in out Handle); -- Disconnect here
end Datalink;

with Datalink;
procedure Something_That_Uses_Data_Link is
   Server_Address : aliased String := "some.address.net";
   Server : Datalink.Handle (Server_Address => Server_Address'access);
begin
   Datalink.Op (Server => Server, ...);
end;

I think this may be the best option.

3. In the body of Datalink, declare a controlled type and an object of
that type; the Finalize for the type does the disconnect. Datalink would
be generic, so each instance would have its own controlled object. This
can get you into trouble because a compiler may optimize away an unused
variable.

-- 
Jeff Carter
"Hello! Smelly English K...niggets."
Monty Python & the Holy Grail




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Finalization of package instance
  2000-01-18  0:00 ` Jeff Carter
@ 2000-01-18  0:00   ` Matthew Heaney
  2000-01-19  0:00     ` Jeff Carter
  2000-01-19  0:00   ` Statements per function point Herv� BITTEUR
  1 sibling, 1 reply; 8+ messages in thread
From: Matthew Heaney @ 2000-01-18  0:00 UTC (permalink / raw)


In article <388496B3.7E36F781@earthlink.net> , Jeff Carter 
<jrcarter010@earthlink.net>  wrote:

> 3. In the body of Datalink, declare a controlled type and an object of
> that type; the Finalize for the type does the disconnect.

This is the simplest of your solutions.


> Datalink would
> be generic, so each instance would have its own controlled object. This
> can get you into trouble because a compiler may optimize away an unused
> variable.

I think there's a new rule (I don't know the AI) that says a
Limited_Controlled object cannot be optimized away.

This issue has come up on CLA before; visit DejaNews to find the thread.

--
Philosophy may be ignored but not escaped; and those who most ignore
least escape.

David Hawkins





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Finalization of package instance
@ 2000-01-18  0:00 Mario Amado Alves
  2000-01-18  0:00 ` Jeff Carter
  2000-01-18  0:00 ` Finalization of package instance Robert A Duff
  0 siblings, 2 replies; 8+ messages in thread
From: Mario Amado Alves @ 2000-01-18  0:00 UTC (permalink / raw)
  To: comp.lang.ada

How do I define the finalization of an instantiation of a generic package?

For example, generic package Datalink initializes a connection with a
database server; when the package instance dies, the connection must be
closed (cleanly) via the proper procedure call. How does one automatize
this? E.g.

  generic
    Database_Server_Address: String;
  package Datalink is
    ...
  end Datalink;

The body:

  package body Datalink is

    ...

  begin

    Connect(Database_Server_Address);

  finalize -- HERE, I WHICH THIS WAS POSSIBLE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Disconnect(Database_Server_Address);

  end Datalink;

Then,

  procedure Main is
    package Main_Data_Server is
      new Datalink("some.address.net");
  begin
    ...
  end Main

Now, when Main has complete running the disconnection should have been done
automatically. Is there an idiom to accomplish this in Ada?

Thanks.

| |,| | | |RuaFranciscoTaborda24RcD 2815-249CharnecaCaparica 351+212976751
|M|A|R|I|O|                                                  mob 939354005
|A|M|A|D|O|DepartmentoDeInformaticaFCT/UNL 2825-114 Caparica 351+212958536
|A|L|V|E|S|                                                  fax 212948541
| | | | | |                 maa@di.fct.unl.pt                FCT 212948300



 Sent via Deja.com http://www.deja.com/
 Before you buy.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Finalization of package instance
  2000-01-18  0:00   ` Matthew Heaney
@ 2000-01-19  0:00     ` Jeff Carter
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff Carter @ 2000-01-19  0:00 UTC (permalink / raw)


Matthew Heaney wrote:
> 
> In article <388496B3.7E36F781@earthlink.net> , Jeff Carter
> <jrcarter010@earthlink.net>  wrote:
> 
> > 3. In the body of Datalink, declare a controlled type and an object of
> > that type; the Finalize for the type does the disconnect.
> 
> This is the simplest of your solutions.

I forgot to mention that the solution with the visible type requires
that the Initialize procedure for the type do the connect. Sorry.

> 
> > Datalink would
> > be generic, so each instance would have its own controlled object. This
> > can get you into trouble because a compiler may optimize away an unused
> > variable.
> 
> I think there's a new rule (I don't know the AI) that says a
> Limited_Controlled object cannot be optimized away.
> 
> This issue has come up on CLA before; visit DejaNews to find the thread.

I recall the thread, with the information that an unused controlled type
could be optimized away, but that GNAT doesn't. If there's a new AI
preventing it in general, that's good news.

-- 
Jeff Carter
"English bed-wetting types."
Monty Python & the Holy Grail




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Statements per function point
  2000-01-18  0:00 ` Jeff Carter
  2000-01-18  0:00   ` Matthew Heaney
@ 2000-01-19  0:00   ` Herv� BITTEUR
  2000-01-19  0:00     ` Ehud Lamm
  2000-01-19  0:00     ` Ted Dennison
  1 sibling, 2 replies; 8+ messages in thread
From: Herv� BITTEUR @ 2000-01-19  0:00 UTC (permalink / raw)
  To: jrcarter

Jeff,

I recall a message of yours on comp.lang.ada, a couple of days ago, saying
approximately that :
- Ada needs 41 statements to implement a function point, while
- C needs 128 statements.

I'm right in the process of trying to guess a whole development effort, for a
project that may actually start in the next coming months. I'm pushing for an Ada
choice as far as the language is concerned. For this I need concrete arguments.

My question is : where do these figures come from ? And as a bonus : where could
I find related ratios on mean project cost related to either line of code or
function point ?

Difficult question I agree.
But thanks in advance for any clue.

-- Herv�





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Statements per function point
  2000-01-19  0:00   ` Statements per function point Herv� BITTEUR
  2000-01-19  0:00     ` Ehud Lamm
@ 2000-01-19  0:00     ` Ted Dennison
  1 sibling, 0 replies; 8+ messages in thread
From: Ted Dennison @ 2000-01-19  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1162 bytes --]

In article <3885DE5D.F70C1A1E@alcatel.fr>,
  "Herv� BITTEUR" <Herve.Bitteur@alcatel.fr> wrote:
> Jeff,
> I'm right in the process of trying to guess a whole development
> effort, for a project that may actually start in the next coming
> months. I'm pushing for an Ada choice as far as the language is
> concerned. For this I need concrete arguments.
> My question is : where do these figures come from ? And as a bonus :
> where could I find related ratios on mean project cost related to
> either line of code or function point ?

Most metrics folks will tell you that any absolute figures are
meaningless outside of the orginazation in which they were collected.

That being said, if you are comparing the relative costs of development
in Ada vs. C, the following report is the one to read:

http://www.rational.com/sitewide/support/whitepapers/dynamic.jtmpl?doc_k
ey=337&borschtid=30404058791780322405

(If you have problems with the link, go to www.rational.com and search
for a paper titled "Comparing Development Costs of C and Ada")

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Statements per function point
  2000-01-19  0:00   ` Statements per function point Herv� BITTEUR
@ 2000-01-19  0:00     ` Ehud Lamm
  2000-01-19  0:00     ` Ted Dennison
  1 sibling, 0 replies; 8+ messages in thread
From: Ehud Lamm @ 2000-01-19  0:00 UTC (permalink / raw)


Look here:
Linkname: What Are Function Points? (Capers Jones)
URL: http://www.spr.com/library/0funcmet.htm
and follow the link about "language level"

The whole paper should be of interest to you.

Other links about metrics can be found on my Ada page.

A recent discussion on comp.software-eng had the topic of "estimating
programming effort." You maight want to try deja.

All in all, I am quite skeptic about all the "scientific methods." But
sometimes this is all you have. A good estimate by someone who knows the
system, env. etc. seems to me the best way...


Ehud Lamm mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <== My home on the web 
Check it out and subscribe to the E-List- for interesting essays and more!






^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2000-01-19  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-18  0:00 Finalization of package instance Mario Amado Alves
2000-01-18  0:00 ` Jeff Carter
2000-01-18  0:00   ` Matthew Heaney
2000-01-19  0:00     ` Jeff Carter
2000-01-19  0:00   ` Statements per function point Herv� BITTEUR
2000-01-19  0:00     ` Ehud Lamm
2000-01-19  0:00     ` Ted Dennison
2000-01-18  0:00 ` Finalization of package instance Robert A Duff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox