"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
William P O'Sullivan wrote:I've had this philosophical argument for years (decades?).
For example: boolean isDoorOpen(...)
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Arrays.equals(), which is designed to compare arrays element by element, is a great idea but, in my view, is seriously flawed because it hides useful information about the result (ie, where the difference was found).
Seetharaman Venkatasamy wrote:* high level people always prefer false, true rather 0,1
just my thought ...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote: For starters, if it did, all its equals() methods would be one-liners.Winston
Winston Gutkowski wrote:such as Arrays.equals(), are generally written for developers, not "high-levellers".
Seetharaman Venkatasamy wrote:sorry, if I misunderstood your post
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:I've recently run into this with a class of mine that contains an array.
Arrays.equals(), which is designed to compare arrays element by element, is a great idea but, in my view, is seriously flawed because it hides useful information about the result (ie, where the difference was found). If it wasn't, I could use to implement both equals() and compareTo() optimally.
Let's assume for a moment that it returns the index of the element that is different, or -1 if they are all the same (the usual pattern for indexOf() methods).
I could then implement my equals() method based on Arrays.equal(myArray) < 0, and my compareTo() method would only need to compare the element at the returned index; if it returns -1, then my compareTo() can return 0.
Steve
Winston Gutkowski wrote:My contention is exactly as stated in the subject: Methods should return as much information as possible.
It's one of the reasons I hate methods that return booleans - like contains().
I much prefer ones like List.indexOf(), because it returns not only a value that indicates whether the List contains the object, but also where it is.
Matthew Brown wrote:Interesting discussion. Mind if I disagree?
For me, there's a difference between information and meaning. I want the most meaningful method in the context I'm interested in, because that makes the intent of my code clearer. Which, I suppose, means that I'd like both methods to exist. Both are better in different contexts.
A good (if slightly trivial) example is in the collection classes. If you're checking whether a list is empty, do you use list.isEmpty() or list.size() == 0? I'd use the former, because it makes the intent very clear - I want to know whether there's anything in the list. The latter approach says I'm comparing the size to something, that happens to be zero in this case.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:What do you want to give to the outside world? A contains() method, or the means to make a contains() method?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Dennis Deems wrote:
Winston Gutkowski wrote:What do you want to give to the outside world? A contains() method, or the means to make a contains() method?
What's wrong with having both? If I require the index, I'll use indexOf. If I do not require the index, I'll use contains, which expresses my intent with more clarity than indexOf(elem) >= 0.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
fred rosenberger wrote:I think I fundamentally disagree with "as much as possible". You could return a LOT of information. ... That is a lot more than what I want when i ask "are they different".
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here