Hacker News new | past | comments | ask | show | jobs | submit login

> I really dislike classes that are only partially configured on construction, and then you have to call other methods to complete their initialization.

What is "partially configured" after all? IMHO this dichotomy is just a headache brought to you by yours truly, OOP (or rather, syntactically enforced OOP). Personally I don't want to spend the rest of my life pondering such philosophical questions. Or dealing with all the consequences, like constructor exceptions, forced dynamic allocation because static doesn't work without initialization, etc, pp.




To me the question isn't a philosophical one, but a practical one. The more states an object has, the more special cases you have to handle, the more likely you are to get one wrong. The more methods an object has that can only be used when the object is in a particular state, the more likely the user of the class it to make a mistake.


Sure, but states are just there, and acting like they weren't can even increase complexity. For example, RAII basically eliminates the "memory is allocated bit uninitialized" state by means of enforcing an automatic transition, at the cost of being no longer able to allocate many objects sratically.


C++ doesn’t believe in “partially constructed”. The real world sometime has this unfortunate event but your code is supposed to deal with it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: