Comment On Three's a Crowd

Key and value, yin and yang, me y me compadre: all pairs. Most coders have had times when one return value is just not enough. Some sugary languages allow you to create and return arrays on the fly; others are not so helpful, forcing developers to allocate structs or return arrays of pointers. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: [CodeSOD] Three's a Crowd

2007-01-02 10:10 • by Mark Steward
Very Adams-esque.

Re: [CodeSOD] Three's a Crowd

2007-01-02 10:15 • by Earl Purple
109199 in reply to 109197

There are 3 types of developers, those who can count and those who can't.

 

Re: [CodeSOD] Three's a Crowd

2007-01-02 10:16 • by woah!

s|Pair|Crowd|g

 CAPTCHA: paste

Re: [CodeSOD] Three's a Crowd

2007-01-02 10:19 • by Imperceptus
plz tell me this is a joke.

Re: [CodeSOD] Three's a Crowd

2007-01-02 10:20 • by Annon

That was redundant...

That was redundant...

Re: [CodeSOD] Three's a Crowd

2007-01-02 10:21 • by snoofle

Perfect! Now I know how to return results from:

   enum Boolean {

TRUE,
FALSE,
FILE_NOT_FOUND
};

Re: [CodeSOD] Three's a Crowd

2007-01-02 10:32 • by Kreiger
Oh, i get it! The WTF is that it isn't immutable. :)

Re: [CodeSOD] Three's a Crowd

2007-01-02 10:36 • by rycamor
I'm struggling to imagine just how this was used. Maciek, if you are here, please provide us some examples.

Re: [CodeSOD] Three's a Crowd

2007-01-02 10:38 • by rycamor
Derrick Pallas:

On the plus side, he can claim that his pair is 50% bigger than mine.

But of course, you can retort "But you don't really have a pair, do you?".
 

Re: [CodeSOD] Three's a Crowd

2007-01-02 10:39 • by v.
Derrick Pallas:

... me y me compadre: ...


wtf?

Re: [CodeSOD] Three's a Crowd

2007-01-02 10:57 • by NameNotFoundException
109215 in reply to 109210

You guys have no clue. This is a very elegant and useful structure. Not only can you now return arbitrary objects (you can even return more than one null, for example), it even supports nesting! You can easily build trees from pairs (aka "prees"), and by adding just one little method: Pair getRest(), you can emulate a cool variation of functional-style list programming - in Java! This amazing invention is the mother of all data structures! Can't you see this? Ignorant fools...

 

Re: [CodeSOD] Three's a Crowd

2007-01-02 10:58 • by seer
109216 in reply to 109208
Best guess is that it originally returned 2 items, then someone needed an additional item, and rather than rename it correctly, or perhaps change to some array of args to make it generic, they just added another field. Lazy good-for-nothing ... (it's too early in the year for this)

Re: [CodeSOD] Three's a Crowd

2007-01-02 11:00 • by seer
109217 in reply to 109215
Anonymous:

You guys have no clue. This is a very elegant and useful structure. Not only can you now return arbitrary objects (you can even return more than one null, for example), it even supports nesting! You can easily build trees from pairs (aka "prees"), and by adding just one little method: Pair getRest(), you can emulate a cool variation of functional-style list programming - in Java! This amazing invention is the mother of all data structures! Can't you see this? Ignorant fools...

A ternary pair tree? A tree-o-nulls? I love it! Actually, a proper pair-implementation could still provide the extra args

Re: [CodeSOD] Three's a Crowd

2007-01-02 11:20 • by B for Bored

Its obviously the threesome class' public name.

Captcha stfu

...NO U 

Re: [CodeSOD] Three's a Crowd

2007-01-02 11:34 • by Mikademus
109223 in reply to 109209
Anonymous:
Derrick Pallas:

On the plus side, he can claim that his pair is 50% bigger than mine.

But of course, you can retort "But you don't really have a pair, do you?".


Even better, he has a

  • PairEx?
  • Trair?
  • Pair2?
  • Pair3?

As for renaming them to reflect their usage and intention:

  • Pair_Company (two items)
  • Pair_Crowd (three items)

Re: [CodeSOD] Three's a Crowd

2007-01-02 11:41 • by IceFreak2000
FWIW, the .NET framework provides this exact same object (albeit correctly named) as System.Web.UI.Triplet (alongside the equally useful System.Web.UI.Pair). Quite why they're buried in the System.Web.UI namespace is beyond me though.

Re: [CodeSOD] Three's a Crowd

2007-01-02 11:46 • by MGS

Maybe 'Pair' is the plural usage and it's just a data structure to hold up to three pair...
    getFirstPair()

    getSecondPair() 

    getThirdPair() 

etc. 

 I could see that being useful.  Sort of.
 


 

Re: [CodeSOD] Three's a Crowd

2007-01-02 11:50 • by KattMan
109227 in reply to 109224

Well, I guess you could get a partriage in a pair three.

Or perhaps this Au Pair is lookng for a Menage a Trios.

Re: [CodeSOD] Three's a Crowd

2007-01-02 12:13 • by tea
109232 in reply to 109207

Anonymous:
Oh, i get it! The WTF is that it isn't immutable. :)

 I almost sprayed tea all over my keyboard after reading that.  I've learned my lesson - don't sip tea (or any liquid for that matter) while reading the daily WTF [captcha].

Re: [CodeSOD] Three's a Crowd

2007-01-02 12:21 • by DanixDefcon5
109234 in reply to 109232

You know ...

That sounds awfully like my college teacher asking us to arrange teams consisting in "pairs of three".

Oh, and that was a Computer Science-related teacher... maybe he helped with this code?

Re: [CodeSOD] Three's a Crowd

2007-01-02 12:24 • by Whiskey Tango Foxtrot? Over.
109236 in reply to 109210
Anonymous:
Derrick Pallas:

... me y me compadre: ...


wtf?

He probably heard "me y mi compadre" somewhere and, not knowing spanish, spelt it phoenetically.

Re: [CodeSOD] Three's a Crowd

2007-01-02 12:39 • by newfweiler

It was coded by the producer of Car Talk.

 "Welcome back to the third half of Car Talk with us, Click and Clack ...."

 

Re: [CodeSOD] Three's a Crowd

2007-01-02 12:50 • by WeatherGod
So, who's on Second?

Re: [CodeSOD] Three's a Crowd

2007-01-02 12:53 • by Dim Whit as int = 0
109244 in reply to 109224
They are used for storing objects in the viewstate

Re: [CodeSOD] Three's a Crowd

2007-01-02 12:54 • by KattMan
109245 in reply to 109242

Anonymous:
So, who's on Second?

No, Who's on first.

Re: [CodeSOD] Three's a Crowd

2007-01-02 12:55 • by tanisha
109246 in reply to 109224

IceFreak2000:
FWIW, the .NET framework provides this exact same object (albeit correctly named) as System.Web.UI.Triplet (alongside the equally useful System.Web.UI.Pair). Quite why they're buried in the System.Web.UI namespace is beyond me though.

 

Guess: The guy who needed the Triplet was in the Web.UI team and wasn't allowed to modify any other namesapces. Either he'd go through a series
of meetings, at various levels of the .NET project managements, to approve a modification to the right namespace or do it in System.Web.UI and get it over with.

 

Re: [CodeSOD] Three's a Crowd

2007-01-02 12:58 • by aikii
I think all they wanted is some kind of predicate : object1, operator, object2 ( like ("jim" "owns" "doggie") , ("doggie" "is a" "dog"), ... ), so they describe problems and solve them in a prolog-like approach.  Or like RDF statements. But then they came with an awfully confusing naming convention, the mother of all WTFs ;-)

Why make it easy!

2007-01-02 12:59 • by [Si]dragon
Why simply return a Collection instance when you can hard code a fixed
number of fields into a badly named class!  Brilliant.

Re: [CodeSOD] Three's a Crowd

2007-01-02 13:13 • by jackass

You really have to wonder what their class that only deals with two variables is called.

Re: [CodeSOD] Three's a Crowd

2007-01-02 13:21 • by Calli Arcale
109252 in reply to 109234
Anonymous:

You know ...

That sounds awfully like my college teacher asking us to arrange teams consisting in "pairs of three".

Oh, and that was a Computer Science-related teacher... maybe he helped with this code?

My high school gym teacher used to say "line up in pairs of three", but stopped long before I arrived in his class.  My uncles had seen to that.  Years before, they had repeatedly infuriated him by getting their buddies to line up in groups of six when he'd say that.

He never did figure out (or admit to figuring out) why they were lining up in sixes, but at least he stopped saying "pairs of three".  :p

He was also fond of saying, "If it fits the shoe, wear it."  Interesting guy, but not for any intended reasons....
 

Re: [CodeSOD] Three's a Crowd

2007-01-02 13:23 • by Twon
As someone who has a looming problem like this in code he's now responsible for, I can say with near certainty that this was caused by plain old scope creep. The clear answer is instead of naming classes things like FooPair, just start with FooNTuple and let the future take its inevitable course.

Re: [CodeSOD] Three's a Crowd

2007-01-02 13:24 • by MGS
109254 in reply to 109247

Anonymous:
I think all they wanted is some kind of predicate : object1, operator, object2 ( like ("jim" "owns" "doggie") , ("doggie" "is a" "dog"), ... ), so they describe problems and solve them in a prolog-like approach.  Or like RDF statements. But then they came with an awfully confusing naming convention, the mother of all WTFs ;-)

 

Wow. That's, like, an obfuscated WTF!

 
878470?
 

Re: [CodeSOD] Three's a Crowd

2007-01-02 13:41 • by VGR
109257 in reply to 109216

Anonymous:
Best guess is that it originally returned 2 items, then someone needed an additional item, and rather than rename it correctly, or perhaps change to some array of args to make it generic, they just added another field. Lazy good-for-nothing ... (it's too early in the year for this)

More generic is the opposite of what they should have done.  I'd much rather have java.awt.Point and java.awt.Dimension than a single (theoretical) PairOfInts class.  Writing small but meaningful struct-like classes for aggregate return values is trivial and the only reason not to do it is, as you said, laziness.

Re: Why make it easy!

2007-01-02 13:44 • by John Bigboote
109258 in reply to 109248

Anonymous:
Why simply return a Collection instance when you can hard code a fixed
number of fields into a badly named class!  Brilliant.

 

Depending on the type of collection class used, you may need to dynamically resize (or "grow") the collection. The nice part about the code snippet is that, if the number of objects is fixed, you will never need to grow a pair. 

Re: [CodeSOD] Three's a Crowd

2007-01-02 13:48 • by Island Usurper
109259 in reply to 109250
jackass:

You really have to wonder what their class that only deals with two variables is called.

 

I bet it's "Singleton". 

Re: [CodeSOD] Three's a Crowd

2007-01-02 13:51 • by John Bigboote
109261 in reply to 109259
Anonymous:
jackass:

You really have to wonder what their class that only deals with two variables is called.

 

I bet it's "Singleton". 

 

In keeping with the genital theme, my money's on "Unit." 

Re: [CodeSOD] Three's a Crowd

2007-01-02 13:56 • by Enteprisey Habkost
That's not really Enterprisey. In our company, we've implemented a pair that is around 33.33% bigger than this one, and has double the size of standard, non-enterprisey pairs.

Re: [CodeSOD] Three's a Crowd

2007-01-02 14:05 • by jkohen
109265 in reply to 109236
Whiskey Tango Foxtrot? Over.:
Anonymous:
Derrick Pallas:

... me y me compadre: ...


wtf?

He probably heard "me y mi compadre" somewhere and, not knowing spanish, spelt it phoenetically.


You mean "yo y mi compadre," don't you? But that's unpolite, when enumerating people, you are supposed to name yourself last, as in: "mi compadre y yo".

 

Back on topic, I've seen latex gloves coming in "pairs of three" so you had an extra one in case one broke in the middle of your dish washing. Maybe this was a glove factory stock system?

Re: [CodeSOD] Three's a Crowd

2007-01-02 14:17 • by MGS
109270 in reply to 109265
Anonymous:

Back on topic, I've seen latex gloves coming in "pairs of three" so you had an extra one in case one broke in the middle of your dish washing. Maybe this was a glove factory stock system?

So the third glove had the thumb in the middle? 

Re: [CodeSOD] Three's a Crowd

2007-01-02 14:27 • by aquanight
109272 in reply to 109207
Anonymous:
Oh, i get it! The WTF is that it isn't immutable. :)


Except, according to the OP, this class is inspired by the STL pair class, which is also mutable (according to glibc's headers, anyway).

Re: [CodeSOD] Three's a Crowd

2007-01-02 14:28 • by A
That must be for the parity information...

Re: [CodeSOD] Three's a Crowd

2007-01-02 14:31 • by MGS

WTF?

 Why is there a posting for a business development job in the Non-WTF job listings? Aren't these all supposed to be software development jobs?

"Senior Director Development, Select Service Hotels"

 [CAPTCHA: wtf] 

Indeed!

Re: [CodeSOD] Three's a Crowd

2007-01-02 14:33 • by Rudolf

Wow... if only all languages had Tuple's, that could save a lot of time :)

p.s. captcha : quality

Re: [CodeSOD] Three's a Crowd

2007-01-02 14:42 • by Derrick Pallas
109279 in reply to 109265

Ya'll caught me.

  • I don't know Spanish. (Pimsleur tried to teach me.)
  • I did learn phonics in grammar school. (An unfortunate experiment in the 80s.)
  • I am really self-centered. (Or not, but I needed to finish the pair.)

In the future, I promise to think about asking a native speaker before I butcher foreign phrases. :)

 

Re: [CodeSOD] Three's a Crowd

2007-01-02 14:46 • by John Hensley
109280 in reply to 109279
It must be a "baker's pair."

Re: [CodeSOD] Three's a Crowd

2007-01-02 14:57 • by seer
109287 in reply to 109270
Anonymous:
Anonymous:

Back on topic, I've seen latex gloves coming in "pairs of three" so you had an extra one in case one broke in the middle of your dish washing. Maybe this was a glove factory stock system?

So the third glove had the thumb in the middle? 

No, it has a recursive pair of thumbs so it can go both ways (also useful for the multitudes with two thumbs on one hand)    ;)

Re: [CodeSOD] Three's a Crowd

2007-01-02 15:27 • by mrprogguy

Perhaps, like me, they just find the word "tuple" to be vaguely pornographic.

Kind of like "s'mores."  *eeeeeeuuuugh*

Re: [CodeSOD] Three's a Crowd

2007-01-02 15:28 • by Phalphalak
109291 in reply to 109257

VGR:

More generic is the opposite of what they should have done.  I'd much
rather have java.awt.Point and java.awt.Dimension than a single
(theoretical) PairOfInts class.  Writing small but meaningful
struct-like classes for aggregate return values is trivial and the only
reason not to do it is, as you said, laziness.

 

I beg to differ. The existence of classes like awt.Point or Dimension are justified because they are entities which can (in a semantical sense) stand for themselves. A pair on the other hand is just a pair. Although you may represent a point by it, they are not the same. Thus, I don't think it has anything to do with laziness when avoiding classes for virtually everything. A helper class like a pair (or triple in that case?!) is quite useful. In fact I think you would be overdoing it if you would declare an own class every time you need to hold certain values which itself do not represent a notional entity. If I were to write a program with some sort of custom Point representation I would not of course keep handling pairs but I might define it with the help of such.

I keep my own java library with useful methods and classes and pair has to proofen to be one of the most usefuls ones. For some geometric algorithms I required to temporarily associate Points with an index. I think it would be inappropriate to especially define a IndexedPoint class for that. Instead I simply used a Pair<Integer,Point>. I think that is a good example of when utilizing such classes makes sense.

package util.misc;

public class Pair<T, E> {
    private T t;
    private E e;
   
    public Pair() {
        t = null;
        e = null;
    }
   
    public Pair(T t, E e) {
        this.t = t;
        this.e = e;
    }

    public final E getSecond() {
        return e;
    }

    public final void setFirst(E e) {
        this.e = e;
    }

    public final T getFirst() {
        return t;
    }

    public final void setSecond(T t) {
        this.t = t;
    }
   
    public String toString() {
        String s = "Pair(";
        s += t + ", " + e + ")";
        return s;
    }
}

 

Re: [CodeSOD] Three's a Crowd

2007-01-02 15:42 • by MGS
109292 in reply to 109291
Phalphalak:

I keep my own java library with useful methods and classes and pair has to proofen to be one of the most usefuls ones. For some geometric algorithms I required to temporarily associate Points with an index. I think it would be inappropriate to especially define a IndexedPoint class for that. Instead I simply used a Pair<Integer,Point>. I think that is a good example of when utilizing such classes makes sense.

Uh... Any reason why you wouldn't use a HashMap for that? 

Re: [CodeSOD] Three's a Crowd

2007-01-02 15:45 • by RangerNS
109293 in reply to 109270
Anonymous:
Anonymous:

Back on topic, I've seen latex gloves coming in "pairs of three" so you had an extra one in case one broke in the middle of your dish washing. Maybe this was a glove factory stock system?

So the third glove had the thumb in the middle? 



 

Nope, it would have been just a "thumb"

« PrevPage 1 | Page 2 | Page 3Next »

Add Comment