-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 06/01/2010 04:16 PM, Justin Harris wrote:
I was just burned pretty bad by a subtle bug and want to share some
general thoughts with folks. The core of the issue that I had was that
the Config class (which is not static) held a static map that represents
the internal state of the object. Additionally, this static map was
only initialized upon the first creation of a Config object. This
doesn't really cause much harm in a deployed environment, but it caused
a lot of pain in our unit test suite -- specifically why one of the
tests would pass when run by itself, and yet failed when run in the
larger test suite.
But why is this the case? is it that we are changing the config in one
test? If a test changes the config, they should change it BACK.
So I think that the lesson learned is: Don't use static
anything. Or,
I wouldn't go as far as saying "don't use static anything", I still
think
there are some uses for it. Like all code we just need to be careful
how we use things. Using static doesn't necessarily make the code bad
just like not using static doesn't make the code good.
at the very least, treat static classes/variables as a code smell,
and
really try to justify it before throwing it in. One of the really nice
aspects of Guice is its ability to abstract away how the dependencies of
a component are created, and I think we should defer to the framework
for e.g. creating objects as singletons for optimization purposes.
Since we are using Guice, it does make sense that we would use it to
create a singleton of the Config, but how does that affect the custom
modules we load in the Config to configure Guice? Is this a chicken
and the egg problem?
What do you guys think? Am I overreacting? :)
See above, and static's aren't always bad.
- --
jesus m. rodriguez | jesusr(a)redhat.com
principal software engineer | irc: zeus
red hat systems management | 919.754.4413 (w)
rhce # 805008586930012 | 919.623.0080 (c)
+---------------------------------------------+
| "Those who cannot remember the past |
| are condemned to repeat it." |
| -- George Santayana |
+---------------------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora -
http://enigmail.mozdev.org/
iEYEARECAAYFAkwFb6YACgkQvJZ57YntiYN3GwCfbvv1qQsj9wQv7LJgCC4STvhJ
/poAnip3xxAGjvbg09zzEwgZVYi/MlpH
=H/Uy
-----END PGP SIGNATURE-----