Stephan van Hulst wrote:Let me qualify my statement in my own way: "Never EVER use static variables, with variable meaning that the value of the variable or the state of the object it references can change".
Even if the class is not intended to be thread-safe, static variables are just a no no.
"Disappointing" and "Utterly Horrible" are not equal.
Tim Holloway wrote:Suppose we need a factory that can produce a sequential key value.
Stephan van Hulst wrote:
Tim Holloway wrote:Suppose we need a factory that can produce a sequential key value.
Why? For what purpose? I can't easily think of a valid use case where this behavior isn't also dangerous.
"Disappointing" and "Utterly Horrible" are not equal.
Tim Holloway wrote:An extremely common case would be where you have a single-threaded app who is the sole writing client to a database where the primary key is a sequence number.
Another case would be if you needed a random number generator. Mathematical RNGs (see Knuth) start from a seed and each successive value is produced based on the preceding value. Which, of course means that they aren't truly random, but that's immaterial.
A more complex case might be a blockchain generator, where the last block is referenced by the next block to be generated.
That's the only sanctioned way to obtain such useful things as the HttpServletRequest, HttpServletResponse, HttpSession objects, [i]etc.[i] within JSF.
"Disappointing" and "Utterly Horrible" are not equal.
Tim Holloway wrote:1b. GUIDs are HORRIBLE database keys. They're effectively long random strings, so you cannot slice a database according to any logical function. Which can interfere with optimization and housekeeping.
They have no inherent sequence, so you'd better have at least one other unique chronometric field in the table if you want to be able to access by order added.
Use GUIDs as, say, invoice ID numbers and see how customers react.
The one thing GUIDs are good for is (virtually) ensuring that every record in the table has a truly Globally Unique ID, regardless of where it was originally created. And that's a great help when you have a system with multiple feeds, but not for most other applications.
2. Who passes around random number generators? Unless you are specifically looking for repeatability of "random" numbers on a per-thread basis in a multi-threaded environment, one RNG is all most people need, and there's no need to instance it.
3. See Item #2. It's even less likely that you want multiple instances of a generator for a blockchain. [...] Having more than one generator defeats the whole concept.
Which reminds me. The most popular logging classes also use static accessors to obtain the logger instance. Because, again, that avoids the need to explicity inject or construct them.
"Disappointing" and "Utterly Horrible" are not equal.
Stephan van Hulst wrote:Can you explain what you mean by that POJOs are not supposed to have infrastructure-related property mandates? Does that mean that I can't simply pass a logger(-factory) in a constructor?
"Disappointing" and "Utterly Horrible" are not equal.
Tim Holloway wrote:POJO means "Plain Old Java Object". Once you cannot arbitrarily substitute one bean for another, you've locked yourself in. You now have coupling issues and code reuse limitations. That doesn't mean that you cannot inject complex objects into a POJO, just that it means that you must not require a class of POJO objects to accept a specific property or properties, since then it's by definition no longer a POJO.
"Disappointing" and "Utterly Horrible" are not equal.
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|