The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

What exactly is finalize?

What exactly is Finalize?  Java uses it as the name of a function called to do cleanup, rather like a destructor.

But would it make sense to use the work in a more general context?

I am designing an API and basically the transaction can be thought of like this:

Begin();
.... do stuff ....
End();

Problem is, in the particular context of this API that End() really ought to allow for some "... do stuff ..." inside it.  So I have a design something like:

Begin();
... do stuff ...
StartToEnd();
... do more end-related stuff ...
ReallyEnd();

And I was struggling to give this concise names.  I came up with:

Begin();
... do stuff ...
Finalize();
... do more end-related stuff ...
End();

But I was a bit scared of using that word for fear of confusing people who have heard the term around (in a Java context; this happens to be a C++ API).

Any synonmyns for that almost-end-point?  Or does Finalize() make clear sense to you folks reading this board (without any domain knowledge of the type of transaction being needed)?

Thanks in advance for the sage advice upon how obvious this overloading of the word 'Finalize' is!
i like i
Thursday, December 09, 2004
 
 
Maybe you're looking for something like the

try {
... do stuff
} catch ( xxx ) {
... handle error
} finally {
... clean up, always called
}

construct from (Visual) C++ and C#?
Martin Karlsson Send private email
Thursday, December 09, 2004
 
 
If your API is to be used from Java then I really don't think you should use the word Finalize if it has a meaning in that language. It will confuse some poor soul somewhere, and he/she/it will curse you to the end of their days. Isn't it "Commit", or am I not understanding what you mean?

Thursday, December 09, 2004
 
 
Need a name for "startToEnd"?

How about "preCommit"?

Slightly offtopic, don't don't depending on finalize to clean up your objects. It's not guaranteed to run at any particular time. In an enterpise application with lots of memory, the garbage collector rarely gets called. If you're depending on finalize to close database connections or file handles, you'll end up holding them for a long, long time.
Luke Francl Send private email
Thursday, December 09, 2004
 
 
If you really mean something like a 'transaction', then perhaps something like

BeginTransactino()
...
PrepareToCommit()
...
CommitTransaction()

which would make your intentions pretty clear, and perhaps Prepare could even be optional?
sdg Send private email
Thursday, December 09, 2004
 
 
sdg, exactly.

I use 'Begin()' and 'End()' because the transition describes a time-line.

The PreEnd() would indeed be optional.

Please, any other naming suggestions would be most welcome; I don't fear that I'll have too many to choose from!

Thanks everyone,
i like i
Friday, December 10, 2004
 
 
How about

BeforeBegin()
Begin()
BeforeEnd()
End()

OR

BeforeStart()
Start()
BeforeEnd()
End()

Or maybe even

Step1()
Step2()
Step3()
Step4()

;-)
Dave C Send private email
Friday, December 10, 2004
 
 
begin()
do something
cleanup()
clean up what you did
end()
Dark Murbin Send private email
Friday, December 10, 2004
 
 
you could also try conclude or complete !
Dark Murbin Send private email
Friday, December 10, 2004
 
 
I use the try...catch...finally approach, as Martin described above, fairly often, though I sometimes omit the catch. That insures the finally clause always runs, even if an exception is thrown. For example,

Resource resource = getResource();
try
{
    useResource(resource);
}
finally
{
    releaseResource(resource)
}

It's very rare for me to call finalize(), since the above construct is usually better.
Julian
Saturday, December 11, 2004
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz