Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualuglybdavis

Posted 15 November 2012 - 11:52 AM

If you think the best place to do it is the constructor, then the best place to do it is the constructor!
Code is very objective and personal, what makes sense for one person might not for another. The only way to find out what the best way is to try.

Me, i always separate construction and initialization. It makes sense to me. I often find myself needing to take different paths to initialize something (IE, make an object from nothing vs deserialize the object form a datastream). I don't want to waste time initializing an object in the constructor if the deserialization step is going to overwrite those changes anyway. Or the more common thing is i don't delete objects unless i absolutely have to. When i don't need an object i don't delete it, i pass it back to the object factory which adds it to an array of dead objects. Then when i need a new object, one of these dead objects is given back to me and i just re-initialize it with new data. This helps avoid extra allocations / memory fragmentation. Useful for the devices i develop for.

Jump in head first, try what you think is best and if you find a better way later just change it Posted Image

#1uglybdavis

Posted 15 November 2012 - 11:48 AM

If you think the best place to do it is the constructor, then the best place to do it is the constructor!
Code is very objective and personal, what makes sense for one person might not for another. The only way to find out what the best way is to try.


Me, i always separate construction and initialization. It makes sense to me. I often find myself needing to take different paths to initialize something (IE, make an object from nothing vs deserialize the object form a datastream). I don't want to waste time initializing an object in the constructor if the deserialization step is going to overwrite those changes anyway.

Jump in head first, try what you think is best and if you find a better way later just change it :)

PARTNERS