Walter Gabrielsen Iii wrote:From the tutorial you can see what I mean, the way Java handled the consumer-producer pattern before the concurrency package existed, make a calling thread wait until a primitive value, a flag, tests true:
And, the concurrency package is full of classes that contain many patterns such as this one, only improved, plus many more, that were once built from scratch (would you consider these new concurrent classes to be wrapper objects?).
It's not only newer languages which have no primitives. Eiffel, which dates from about 1985, has INTEGER etc classes. And to make things more interesting, the more recent versions of C# have changed their primitives to objects. I don't know what that does for backward compatibility, however.Jesper de Jong wrote: . . . Other, more modern programming languages (for example Scala and Ruby) have no special primitive types; things like Int and Float are objects, . . .
Did somebody in a tutorial really write == false? You doubtless already know not to use such a construct.Walter Gabrielsen Iii wrote: . . .. . .
Martin Vajsar wrote:I also don't quite agree with your claim that people are often creating their own custom, mutable wrapper classes for primitives. I neither ever created, nor needed one.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:
Martin Vajsar wrote:I also don't quite agree with your claim that people are often creating their own custom, mutable wrapper classes for primitives. I neither ever created, nor needed one.
I have, for use as Map values that get increased quite a bit. Instead of getting a Map value, unboxing it, increasing it, boxing it again, putting it back in the Map, you can have one single object that you get, increase, and be done with it. Apache Commons even has a package with these classes, org.apache.commons.lang3.mutable.
Campbell Ritchie wrote:Did somebody in a tutorial really write == false? You doubtless already know not to use such a construct.
That should be spelt d-e-f-i-n-i-t-e-l-yMatthew Brown wrote: . . . (Probably
)
The only reason ! works there is because that is how it is designed to workWalter Gabrielsen Iii wrote: . . . The only reason "!" might work . . .
Walter Gabrielsen Iii wrote:Why should you not use equality tests with booleans?
I think boolean in Java is a psudo-type, unlike the +1/-1 contrast in some other languages, accessed through the keywords true and false.
Walter Gabrielsen Iii wrote:With '!' , you're just inverting the boolean value before you test it. Then you run your condition, let's say the value is true, to run when it sees false, and, in the other case, when the value is false the condition runs when it sees true.
Martin Vajsar wrote:There is conceptually nothing like "inverting before testing",
Mike Simmons wrote:
Martin Vajsar wrote:There is conceptually nothing like "inverting before testing",
Hunh? Sure there is. The ! operator inverts the boolean value before it's tested in the while statement.
Martin Vajsar wrote:I meant that such concept does not exist in the language specification. I'd say it is better to think in terms of boolean expressions, which undoubtedly is how the while statement is defined in JLS.
Martin Vajsar wrote:If someone gets too used to the idea that the ! operators inverts the test of the while statement, parsing a statement like while (!a && b) might suddenly be less straightforward than it need be.
Walter Gabrielsen Iii wrote: . . . unlike the +1/-1 contrast in some other languages, accessed through the keywords true and false.
Campbell Ritchie wrote:
Walter Gabrielsen Iii wrote: . . . unlike the +1/-1 contrast in some other languages, accessed through the keywords true and false.
What +1/-1 contrast? I know of no language which uses +1/-1. I know of a lot which use 1 and 0, or -1 and 0, for true and false respectively, however. And using -1/0 or 1/0 is much more error-prone than having separate boolean types. Agreed, the boolean data type probably does store 1/0 or -1/0 somewhere, but the language specification wisely keeps such details safely hidden where we can't interfere with them and mess them up![]()
Walter Gabrielsen Iii wrote:Oh, I think I should clarify something for anyone who is learning the concurrency package, the CubbyHole class above, posted earlier, which is an example of Java's wait()/notify() model, this model can also be implemented with the concurrent package, specifically the java.util.concurrent.locks.Condition interface and subclasses: await()/signal() model.
Nor do it. I know some which use -1 for TRUE, however. Because you can use a bitwise complement operator to turn it into FALSE, which is 0. I never knew C/C++ used negative for FALSE; I thought it was 0 for FALSE and non-zero for TRUE.Walter Gabrielsen Iii wrote:. . . I don't know what language uses -1 as false. . . .
Consider Paul's rocket mass heater. |