This is a very open-ended question, so my answer will try to be as general as possible...
Doing work in constructors isn't as "bad" as it used to be years ago when exception handling wasn't as prevalent and evolved as it is today. You'll notice that the Google Tech talk primarily looks at constructors from a Testing perspective. Constructors have been historically very very difficult to debug so the speaker is correct that doing as little as possible in a constructor is better.
With that said, you'll notice that he's also touching on dependency injection/the provider pattern which is notorious for complicating constructors. In such a case, leaving ONLY provider/DI code in the constructor is preferred. Again, the answer depends on what patterns you're using and how your code "fits" together.
The entire point of using a constructor is to create a neat object that can be used immediately; i.e. new Student("David Titarenco", "Senior", 3.5)
. There's no need to do david.initialize()
as it would be entirely silly.
Here's some of my production code, for example:
Config Conf = new Config();
Log.info("Loading server.conf");
Conf.doConfig();
In the above case, I decided not to do anything with the constructor (it's empty) but have a doConfig()
method that does all the disk i/o; I've often thought that the doConfig()
method is just pointless and I should do everything in the constructor. (I only check out the config file once, after all.)
I think that it's entirely dependent on your code and you shouldn't think that putting "stuff" in your constructor is a bad thing. That's what constructors are for! Sometimes we get carried away with OOP (getThis
, setThat
, doBark
) when really all a class needs to do is a load a config file. In such cases, just put everything in the constructor and call it a day!