Is this a good practise,or it just depends?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The only time it might make sense not to initialize would be if you are going to default-construct large numbers of POD objects in performance-critical code and then populate them with valid data afterwards — e.g. if you were going to create an array of one million objects, and then populate the array’s objects with valid data. In that scenario you might want to avoid the initialization, since it’s a waste of CPU cycles to zero everything out when you’re only to overwrite it again afterwards.
But if you do that, be sure to put /* LOTS OF EYE-GRABBING COMMENTS */ in your class’s .h file warning the user about what you are doing and why, and document it thoroughly in any other programmer’s documentation you maintain. Tracking down uninitialized-value bugs isn’t much fun…