Pop quiz 2 answer question.

From: R. Clayton <rclayton_at_monmouth.edu>
Date: Thu, 8 Mar 2012 09:25:22 -0500
  The FindBugs site describes it as "ST: Write to static field from instance
  method (ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD) This instance method writes
  to a static field. This is tricky to get correct if multiple instances are
  being manipulated, and generally bad practice.", a close match to my answer.

First, there's no arguing pop-quiz grades.

Second, the findbugs explanation doesn't make sense.  To what does "multiple
instances" refer?  It can't refer to the static field, because there's only one
static field.  It can't refer to the class instances because, while there are
several of them, they are manipulating the static field; they are not being
manipulated themselves.  What else is there to refer to?

Third, assuming we can assign some kind of meaning to the findbugs explanation,
why is it "tricky to get correct?" (And what does it mean to be "correct,"
which turns out to be a hard question, one that Java gets mostly wrong).  Why
is it considered bad practice?  Used in the way (we imagine) findbugs
describes, a static field is effectively a limited-scope global variable, and
that's usually considered both bad style and bad practice, but so what?
There's an answer more directly relevant to the class, which is why I gave the
verbal clue about covering the answer to the pop quiz in the lectures, and why
I gave the pop quiz at all.
Received on Thu Mar 08 2012 - 09:25:23 EST

This archive was generated by hypermail 2.2.0 : Fri Mar 09 2012 - 22:12:35 EST