Page 1 of 1

create statement: To add or not to add persistent/transient

Posted: Wed Aug 19, 2009 3:24 pm
by Patwos
At the risk of starting a religious war, what are people's view on the adding of the persistent or transient modifier to a create statement, irrespective of the class defined default persistence?

I personally always add whichever modifier is appropriate for my requirements in the method in question as it helps to self document the code and make your intentions crystal clear.

What are other people's views on this?

Pat.

Re: create statement: To add or not to add persistent/transient

Posted: Wed Aug 19, 2009 8:50 pm
by Dino
Ditto - I generally always include the lifetime in the create statement.

Dean.

Re: create statement: To add or not to add persistent/transient

Posted: Thu Aug 20, 2009 2:33 am
by jadeloveslave
I always use the lifetime modifer, for the very reasons you describe.

Although this may not be such a problem if you use a transaction agent or business object to create your persistent instances, it certainly makes things a lot easier when debugging or maintaining code.

Re: create statement: To add or not to add persistent/transient

Posted: Thu Aug 20, 2009 2:48 am
by ghosttie
I also always explicitly set the lifetime for readability

Re: create statement: To add or not to add persistent/transient

Posted: Thu Aug 20, 2009 9:26 am
by allistar
A client of mine has a framework where object creation is done through a single method on the Class class called "createObject", and that method takes a global constant for the lifetime (Lifetime_Transient, Lifetime_SharedTransient and Lifetime_Persistent). This single method allows us to put other logic in place, such as modifying the type of object being created at runtime for purposes of subschema customisation. Having the lifetime explicitly specified does allow for easier readability.

Re: create statement: To add or not to add persistent/transient

Posted: Thu Aug 20, 2009 9:34 am
by ghosttie
A client of mine has a framework where object creation is done through a single method on the Class class called "createObject", and that method takes a global constant for the lifetime (Lifetime_Transient, Lifetime_SharedTransient and Lifetime_Persistent). This single method allows us to put other logic in place, such as modifying the type of object being created at runtime for purposes of subschema customisation. Having the lifetime explicitly specified does allow for easier readability.
I like that idea. It would be even better if you could use something like NFS 36969 to enforce the policy that creates can only be performed using the createObject method

Re: create statement: To add or not to add persistent/transient

Posted: Thu Aug 20, 2009 10:23 am
by BeeJay
Ditto for me too. It definitely makes the code's intention more explicit. It also helps protect the code from being adversely affected by someone inadvertently, or deliberately, changing the default lifetime of the class.

Cheers,
BeeJay.

Re: create statement: To add or not to add persistent/transient

Posted: Thu Aug 20, 2009 1:46 pm
by MaxRefactor
So would we be better off without the default lifetime feature?

Re: create statement: To add or not to add persistent/transient

Posted: Fri Aug 21, 2009 1:21 am
by ghosttie
So would we be better off without the default lifetime feature?
Yeah, I think so - I think the benefits of slightly less typing are far outweighed by increased readability