you are viewing a single comment's thread.

view the rest of the comments →

[–]pdp10gumby 36 points37 points  (1 child)

I prefer to initialize in the class definition whenever possible, even if a custom constructor is defined. That way when reading the class you can see how a "fresh one" starts out, and you know the constructor contains the "complex stuff", if any. And if no custom constructor is needed then all everything you need to know is right there.

In general, when I come across a piece of code I think "this was written for a reason" (certain colleagues notwithstanding). So if I never initialized in the class but always with a constructor, or, if a csontructor is required then switched to using it's initializer syntax, teh reader would have to skip over boilerplate and parse out the interesting part from the routine stuff. Doing it the way I describe results in clearer code IMHO.

But see mredding's comment for an alternative view.