Should I always/ever/never initialize object fields to default values?

Think long term maintenance.

  • Keep the code as explicit as possible.
  • Don’t rely on language specific ways to initialize if you don’t have to. Maybe a newer version of the language will work differently?
  • Future programmers will thank you.
  • Management will thank you.
  • Why obfuscate things even the slightest?

Update: Future maintainers may come from a different background. It really isn’t about what is “right” it is more what will be easiest in the long run.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)