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

Discussions about design and architecture principles, including native JADE systems and JADE interoperating with other technologies
Patwos
Posts: 11
Joined: Mon Aug 17, 2009 11:05 am

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

Postby Patwos » Wed Aug 19, 2009 3:24 pm

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.

User avatar
Dino
Posts: 49
Joined: Wed Jun 24, 2009 6:55 am
Location: London
Contact:

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

Postby Dino » Wed Aug 19, 2009 8:50 pm

Ditto - I generally always include the lifetime in the create statement.

Dean.

User avatar
jadeloveslave
Posts: 4
Joined: Wed Jun 24, 2009 7:20 am

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

Postby jadeloveslave » Thu Aug 20, 2009 2:33 am

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.

User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

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

Postby ghosttie » Thu Aug 20, 2009 2:48 am

I also always explicitly set the lifetime for readability
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

allistar
Posts: 156
Joined: Fri Aug 14, 2009 11:02 am
Location: Mount Maunganui, Tauranga

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

Postby allistar » Thu Aug 20, 2009 9:26 am

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.

User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

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

Postby ghosttie » Thu Aug 20, 2009 9:34 am

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
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

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

Postby BeeJay » Thu Aug 20, 2009 10:23 am

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.

MaxRefactor
Posts: 3
Joined: Mon Jun 22, 2009 11:42 am

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

Postby MaxRefactor » Thu Aug 20, 2009 1:46 pm

So would we be better off without the default lifetime feature?

User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

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

Postby ghosttie » Fri Aug 21, 2009 1:21 am

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
I have a catapult. Give me all the money or I will fling an enormous rock at your head.


Return to “Design and Architecture”

Who is online

Users browsing this forum: No registered users and 5 guests

cron