The term will be used as a method name. The method is called when a part of the user interface is hidden (or removed), and it is used to reset values to default and dispose objects that will not be used any more.
Possible names are: release, remove, dispose, clear etc.
Which do you think is the most appropriate?
10
I use :
- initialize()
- terminate()
I find it the more appropriate:
- it’s hard to not see it in code, because it’s both long words (I don’t use init)
- it’s correct english (AFAIK)
- in my head, terminate avoids ambiguity. It doesn’t match begin (which matches end), start (which matches stop), create (which matches destroy), setup (which matches unset), load (which matches unload) etc.
Some people could find it a question of taste though.
9
I typically go with either Finalize, Destroy, or Terminate depending on what the objects function is.
For the case you describe, Finalize is what I would go with based on my scheme.
4
I like release
for a method that disposes of objects and other resources (e.g. as preparation for destruction). I would choose reset
for a method that resets values to default.
If the “default” state doesn’t require any resources, then reset
may be able to call release
to perform that part of its operations.
close()
No-one has proposed close() yet. Java 7 has a new “try with resources” feature. A class that gets cleaned up automatically has to implement java.lang.AutoCloseable which has a single close() method. shutdown() or cleanup() might be good too.
Not finalize()
finalize() means something specific to the garbage collector in Java, and the way it works is a little weird. I would stay away from finalize() unless you want exactly what Java does with finalize().
2
I’d say it depends on if the action is optional or required (without leaking resources), and if the language supports constructors/destructors. For optional cases I use:
- clear
- reset
- hide (in UI context)
In other cases where the opposite action is required (in languages without constructors/destructors, or when the destructor doesn’t release the resource), I use:
- init – fini
- initialize – deinitialize
- create – destroy
In your case I think I would prefer hide
. It can still release memory/resources if it wants to – the important thing is that it is optional, i.e. that the destructor would take care of it if you didn’t.
I quite like ‘destroy’. Couldn’t be clearer unless you’re writing a video game or something.
1
and it is used to reset values to default and dispose objects that
will not be used any more.
reset
seems like a good term if you’re resetting the object to defaults. reinitialize
could also be appropriate if the use of this object is similar to what initialize
does. It sounds like this method will dispose other objects, not the one that’s receiving the message, in which case either of the above should be fine. If you’re really doing the opposite of init
and preparing the receiver to be destroyed, dispose
would be a good choice.
My first thought was tear down, but that is used in many testing frameworks. Finalize and dispose have similar problems. Reset, or clean up both seem like good choices. Reinitialize makes it clear it goes back to the initialized state, which would be good if the state you go back to is the initial state.
Just make sure your term isn’t overloaded in your current context.
2
http://www.wordhippo.com/what-is/the-opposite-of/initialize.html
I would go with finalize. However I think it is a little bit dependent the exact use case: e.g. If you use it mainly to to release resources, close connections, files then release would be more meaningful.
If you are looking for a notion for general use, or standardize, I would choose some less meaningful, something with no special meaning like release, or remove.
The concept of init vs (whatever) is similar to (constructor vs destructor), or in java finalize.
(Note: If the language has the concept construct and destruct objects, its little or no need to use init(). )
1
If the object the method is being called on will cease to be used, I would just use the standard destructor. That doesn’t sound like the case, though, so rather than getting too generic, a better name is probably something like hide()
if the object itself is being hidden or hideUserInterfacePart()
if composed objects are being hidden.