There is an unwritten contract that getters should not have such side effects; IMHO if a getter is doing this, the getter is broken, and should not be named "getXXX".  Use something else like "find", "determine", "create" -- in other words, if a getter wants to do fancy tricks, that's fine, but it must be careful to ensure side effects don't influence the result.

--John

On 04/12/2023 18:55, Michael Strauß wrote:
Side effects are not limited to race conditions. A getter might return
a different value every time, or it might execute code other than
simply returning a value, or a lazy evaluation scheme might cause
other code to be executed. The point is, we don't know that at the
call site, we'd need to inspect what the getter actually does.


On Mon, Dec 4, 2023 at 6:47 PM Andy Goryachev <andy.goryac...@oracle.com> wrote:
This might be different.



If we can guarantee that the access to the underlying variable(s) is single 
threaded - then no.  But we had at least one bug recently in JFXPanel where two 
threads were involved.  Those cases need to use a very different access 
pattern(s), depending on the exact circumstances.



-andy

Reply via email to