• (cs)

    I can't believe it.

  • Robert (unregistered) in reply to dreifus

    This looks terrible! I am no expert in classes, but from what I remember in Data Structures, can't you throw all of this into an expandable container?  even simple as a list/vector? dunno.....i come here so i know what not to do

  • (cs)

    Hahaha I get it, quite a subtle one today - Quintupe has a Quintuple value rather than QuintupleID.

    Other than that, an excellent and flexible design - by naming the values the generic "fieldX" names, you allow for an unprecedented level of code re-use. With a bit of XML encoding you can even store your choice of data in them since they are strings.

    I bow down before this guy's greatness.

  • Codewulf (unregistered) in reply to dreifus

    He knew what it was but was highly religious and did not want a structure with the word sex in it.

  • (cs)

    Can you say Collection?  Array?  Hash?  How high did he/she go?  Last time I checked, numbers were infinite.

  • (cs)
  • no1 (unregistered) in reply to RayS

    So, when did he stop?

  • Zic (unregistered)

    Microsoft probably created the System.Web.UI.Pair and System.Web.UI.Triplet classes as a result of this guy's genius.  Unfortunately, Microsoft did not go so far as to create a System.Web.UI.Sextuplet class.

  • (cs)

    I'd make a witty reply, but I feel a sudden urge to go spend several minutes in silence thanking God for C++ templates.

  • Fish (unregistered) in reply to no1

    How about just

    public String fields[x]; // where x is your favorite non-negative, non-zero number 

    You can always get the length from a function call.

  • Dave (unregistered) in reply to no1

    You mean with the tuples? Looks like he stopped before he got to sex. So does this qualify as codus interruptus?

     

  • no1 (unregistered) in reply to Mung Kee

    Mung Kee:
    Can you say Collection?  Array?  Hash?  How high did he/she go?  Last time I checked, numbers were infinite.

    Aga! Thus infinite job security.

  • (cs)

    Alex Papadimoulis:
    Talanb's colleague was well trained in best-practices.

    Which best practice is it that states "use a string for everything, except a couple ID values"...? And anyway, he forgot one:

    public <FONT size=+0>class</FONT> Single
    {
      <FONT size=+0>public</FONT> <FONT size=+0>int</FONT> SingleID;
      <FONT size=+0>public</FONT> <FONT size=+0>String</FONT> field1;
    }

  • (cs) in reply to Apoch
    Apoch:
    I'd make a witty reply, but I feel a sudden urge to go spend several minutes in silence thanking God for C++ templates.


    With "God", you mean "Stroustrup", right?

  • (cs) in reply to Fish
    Anonymous:

    How about just

    public String fields[x]; // where x is your favorite non-negative, non-zero number 

    You can always get the length from a function call.


    Oh, now I see the benefit.  So the constructors would be...
    <font>public</font> Pair(int fields)
    {
    <font>public</font> <font>int</font> PairID;
    <font>public</font> <font>String</font>[] = new String[fields];
    }

    <font>public</font> Triple(int fields)
    {
    <font>public</font> <font>int</font> TripleID;<font>
    public</font> <font>String</font>[] = new String[fields];
    }

    <font>public</font> Quadruple(int fields)
    {
    <font>public</font> <font>String</font> QuadrupleID;<font>
    public</font> <font>String</font>[] = new String[fields];
    }
    ...etc.

    Brillant!
  • (cs) in reply to Fish

    I'd be curious to see a database designed by this fellow ....

  • (cs) in reply to no1
    Anonymous:

    Mung Kee:
    Can you say Collection?  Array?  Hash?  How high did he/she go?  Last time I checked, numbers were infinite.

    Aga! Thus infinite job security.



    a masterful plan
  • (cs) in reply to Mung Kee
    Mung Kee:
    Anonymous:

    How about just

    public String fields[x]; // where x is your favorite non-negative, non-zero number 

    You can always get the length from a function call.


    Oh, now I see the benefit.  So the constructors would be...
    <font>public</font> Pair(int fields)
    {
    <font>public</font> <font>int</font> PairID;
    <font>public</font> <font>String</font>[] = new String[fields];
    }

    <font>public</font> Triple(int fields)
    {
    <font>public</font> <font>int</font> TripleID;<font>
    public</font> <font>String</font>[] = new String[fields];
    }

    <font>public</font> Quadruple(int fields)
    {
    <font>public</font> <font>String</font> QuadrupleID;<font>
    public</font> <font>String</font>[] = new String[fields];
    }
    ...etc.

    Brillant!


    Before any bozos comment, I know it won't compile.  I left the array names out.
  • I'm not registered yet.... (unregistered)

    just horrible...............
    <FONT face="Courier New"><FONT color=#808080 size=2>public class Struct6
    {
     public String Struct6ID;
     public String field1;
     public String field2;
     public String field3;
     public String field4;
     public String field5;
     public String field6;
    }</FONT>
    </FONT>you should be ashamed of your solution which is 'wtf' as well

    you could derive Single-->Pair-->Triple--> ...

    where

    <FONT face="Courier New">class Single
    {
     string ID
     string field1;
    }</FONT>

    how about something like:

    <FONT face="Courier New">public class StructN
    {
     public StructN(int n){fields = new int[N];}
     public string ID;
     public int[] fields;
    }</FONT>


     

  • (cs) in reply to Alexis de Torquemada
    Alexis de Torquemada:
    Apoch:
    I'd make a witty reply, but I feel a sudden urge to go spend several minutes in silence thanking God for C++ templates.


    With "God", you mean "Stroustrup", right?



    I did a quick search for "Stroustrup".  Imagine having this line on your resume:

    "I designed and implemented the C++ programming language"

    http://www.research.att.com/~bs/homepage.html
  • (cs) in reply to Alexis de Torquemada

    Alexis de Torquemada:
    Apoch:
    I'd make a witty reply, but I feel a sudden urge to go spend several minutes in silence thanking God for C++ templates.


    With "God", you mean "Stroustrup", right?

    Technically, I mean

    template<class Deity> class God;

     

    It's up to you to instantiate the template with the correct parameter.

  • (cs) in reply to Mung Kee
    Mung Kee:


    I did a quick search for "Stroustrup".  Imagine having this line on your resume:

    "I designed and implemented the C++ programming language"

    http://www.research.att.com/~bs/homepage.html


    My resume already contains the line "I invented the Internet", and I don't want to make people suspicious.

  • (cs) in reply to Apoch
    Apoch:

    Technically, I mean

    template<class deity=""> class God;</class>

     

    It's up to you to instantiate the template with the correct parameter.



    In that case, I choose God<void>. Seems most compatible with my atheism.

  • (cs) in reply to Robert
    Anonymous:
    This looks terrible! I am no expert in classes, but from what I remember in Data Structures, can't you throw all of this into an expandable container?  even simple as a list/vector? dunno.....i come here so i know what not to do


    It's even worse than that. Even if you were doing something like a linked list, you could still do it by declaring an object name, one or two links (depending on the type of LL) and an array to store the data. Same with a tree. Vectors, Stacks, and Queues, are all scale-able by definition.

    And if you needed an array that's statically sized, you could put together an array constuctor with a paltry two input fields. (Name, Size)

    What a moron. I would never do this, just because who the hell wants to type that much crap? If you find yourself typing the same thing more than twice, you should be looking for a better way.

  • (cs) in reply to Mung Kee
    Mung Kee:
    Mung Kee:
    Anonymous:

    How about just

    public String fields[x]; // where x is your favorite non-negative, non-zero number 

    You can always get the length from a function call.


    Oh, now I see the benefit.  So the constructors would be...
    <font>public</font> Pair(int fields)
    {
    <font>public</font> <font>int</font> PairID;
    <font>public</font> <font>String</font>[] = new String[fields];
    }

    <font>public</font> Triple(int fields)
    {
    <font>public</font> <font>int</font> TripleID;<font>
    public</font> <font>String</font>[] = new String[fields];
    }

    <font>public</font> Quadruple(int fields)
    {
    <font>public</font> <font>String</font> QuadrupleID;<font>
    public</font> <font>String</font>[] = new String[fields];
    }
    ...etc.

    Brillant!


    Before any bozos comment, I know it won't compile.  I left the array names out.


    Hey! That won't compile. You left the array names out.
  • (cs) in reply to Zic
    Anonymous:

    Microsoft probably created the System.Web.UI.Pair and System.Web.UI.Triplet classes as a result of this guy's genius.  Unfortunately, Microsoft did not go so far as to create a System.Web.UI.Sextuplet class.



    Just an aside, I was delighted when intel moved from "486" to the "Pentium" line, instead of continuning with the boring x86 number theme. I was convinced they were going to go from Pentium to "Sexium" and damn, that would be a fine name for a computer. Pentium I<i>I</i>?!?!? Oh, unjust, cruel world.

  • (cs)

    That is just silly. He should have used inheritance and have saved himself some typing:

    class Pair
    {
      public int id;
      public String field1;
      public String field2;
    }

    class Name(Pair)
    {
      // field1 is first name
      // field2 is last name
    }

    class Triple(Pair)
    {
      public String field3;
    }

    class Quadruple(Triple)
    {
      public String field4;
    }

    /* ... */

  • LazyGerman (unregistered) in reply to Satanicpuppy

    Oh damn.. i just realized that in all those years i did never asked myself why its called "pentium"...
    thank you man... you enlighted me...

    Have a nice day

  • Mr. Coder (unregistered) in reply to Satanicpuppy

    Horrible! He forgot he could also do this:

    class Triplet extends Pair

       String field3;

     

    class Quadruplet extends Triplet

       String field4;

    Brillant! (please do not take this post seriously)

  • (cs) in reply to Mr. Coder

    What, no Dodecatuple class?

     

  • (cs) in reply to Apoch
    Apoch:

    Alexis de Torquemada:
    Apoch:
    I'd make a witty reply, but I feel a sudden urge to go spend several minutes in silence thanking God for C++ templates.


    With "God", you mean "Stroustrup", right?

    Technically, I mean

    template<class deity=""> class God;</class>

     

    It's up to you to instantiate the template with the correct parameter.



    Aren't God objects an anti-pattern?
  • Chep (unregistered)

    Actually MS has similar approach for managing ASP.NET ViewState data.

    Objects: System.Web.UI.Pair and System.Web.UI.Triplet

    Everything else is the combination of those two (i.e. 4 => 2 pairs; 5 => 1 pair + 1 triplet etc...)

    May be programmer was "under influence"? [;)] 

  • (cs) in reply to Alexis de Torquemada
    Alexis de Torquemada:
    Mung Kee:


    I did a quick search for "Stroustrup".  Imagine having this line on your resume:

    "I designed and implemented the C++ programming language"

    http://www.research.att.com/~bs/homepage.html


    My resume already contains the line "I invented the Internet", and I don't want to make people suspicious.



    Wow, Richard Nixon and Al Gore on the same thread.
  • (cs) in reply to DeusEx
    DeusEx:

    he forgot one:

    public <font size="-0">class</font> Single
    {
      <font size="-0">public</font> <font size="-0">int</font> SingleID;
      <font size="-0">public</font> <font size="-0">String</font> field1;
    }



    Good one!

    He forgot "none", too...

    public class Empty
    {
      public int EmptyID;
    }

    Why do you need an EmptyID?  To tell instances of the class apart, of course.  You don't want to confuse the
    Empty justificationsForThisCode;
    with the
    Empty hopeForThisCoder;

    ;)
  • (cs)

    I take it String arrays or Linked Lists are now bad design!


    Bart.

  • (cs)

    Quoteth the manager : "But what if we need to store 3 values in the pair?"

    Ya know, I'm almost ready to start reporting the article itself as a troll post... I mean, how can you expect anything resembling a reasonable discussion to follow code like that?!?!

  • Sean Connery (unregistered) in reply to Jeff S
    Jeff S:
    I'd be curious to see a database designed by this fellow ....

    haha
  • MarvinRunyon (unregistered)

    You guys are all completely blind!  The only thing wrong with this code is that the classes do not extend a common base class, Tuple.
    Everything else is perfect, and the performance implications are obvious!! 

  • (cs) in reply to Jeff S
    Jeff S:
    I'd be curious to see a database designed by this fellow ....


    I'd rather want to know what was the purpose of creating that ?
    The guy's using fields for the Pete's sake - unless it's a result of Alex's editing of course.
  • (cs)

    The design is sound... there's just too much cutting and pasting of code.
    Ironically, it is not structured and does not embody reuse.

    The following does.

    // nested classes... maximum code and data reuse

    public class Zerople
    {
      public int ID;
    }

    public class Single
    {
      public Zerople data0;
      public String field1;
    }

    public class Pair
    {
      public Single data1;
      public String field2;
    }

    public class Triple
    {
      public Pair data2;
      public String field3;
    }

    // ... etc.

    // First optimization:
    // templatized version of above

    public class 0ple
    {
      public int ID;
    }


    public class <T>ple
    {
      public class<T-1>ple data<T-1>;
      public String field<T>;
    }

    // usage example

    Triple cheeseburger = new Triple();

    cout << cheeseburger.data2.data1.data0.ID;

    ....

    // Second optimization:
    // preprocessor macro (requires patch to preprocessor)
    // Perlish means of token pasting

    #define ID(depth) </span>
        for(int i = 0; i <= depth; i++) { ID = "data$i".ID; } </span>
        ID = "ID(depth)"

    // simplified access...
    cout << cheeseburger.ID(2);  // good
    cout << cheeseburger.ID(3);  // will not compile


    // Third optimization:
    // enhancement to template; depth is generated automatically

    public class 0ple
    {
      public int depth = 0;
      public int ID;
    }

    public class <T>ple
    {
      public int depth;
      <T>ple() { depth = T; }
      public class<T-1>ple data<T-1>;
      public String field<T>;
    }


  • no1 (unregistered) in reply to Xepol

    Xepol:
    I mean, how can you expect anything resembling a reasonable discussion to follow code like that?!?!

    You can't!

    You know when it's really bad when no one has even tried to defend it.

  • Tupler (unregistered)

    Could have been worse.

    [pre] #include <string> #include <iostream>

    template<unsigned int n> class Tuple { Tuple<n-1> prev; std::string current; bool initialized;

    public: Tuple() : prev(), current(), initialized(0) { }

    Tuple<n> &operator()(std::string s)
    {
        if(!prev.initialized)
        {
            prev(s);
        }
        else
        {
            current = s;
            initialized = 1;
        }
        return *this;
    }
    
    std::string &operator[](unsigned int pos)
    {
        if(pos == n)
            return current;
        else
            return prev[pos];
    }
    
    friend class Tuple<n+1>;
    

    };

    template<> class Tuple<1> { std::string current; bool initialized;

    public: Tuple() : current(), initialized(0) { }

    Tuple<1> &operator()(std::string s)
    {
        current = s;
        initialized = 1;
        return *this;
    }
    
    std::string &operator[](unsigned int)
    {
        return current;
    }
    
    friend class Tuple<2>;
    

    };

    int main() { Tuple<3> t;t("hello")("world")("42"); std::cout << "1 -> " << t[1] << std::endl; std::cout << "2 -> " << t[2] << std::endl; std::cout << "3 -> " << t[3] << std::endl; return 0; } [/pre]

    #include <string>
    #include <iostream>
    
    template<unsigned int n> class Tuple
    {
        Tuple<n-1> prev;
        std::string current;
        bool initialized;
    
    public:
        Tuple() :
            prev(),
            current(),
            initialized(0)
        {
        }
    
        Tuple<n> &operator()(std::string s)
        {
            if(!prev.initialized)
            {
                prev(s);
            }
            else
            {
                current = s;
                initialized = 1;
            }
            return *this;
        }
    
        std::string &operator[](unsigned int pos)
        {
            if(pos == n)
                return current;
            else
                return prev[pos];
        }
    
        friend class Tuple<n+1>;
    };
    
    template<> class Tuple<1>
    {
        std::string current;
        bool initialized;
    
    public:
        Tuple() :
            current(),
            initialized(0)
        {
        }
    
        Tuple<1> &operator()(std::string s)
        {
            current = s;
            initialized = 1;
            return *this;
        }
    
        std::string &operator[](unsigned int)
        {
            return current;
        }
    
        friend class Tuple<2>;
    };
    
    int main()
    {
        Tuple<3> t;t("hello")("world")("42");
        std::cout << "1 -> " << t[1] << std::endl;
        std::cout << "2 -> " << t[2] << std::endl;
        std::cout << "3 -> " << t[3] << std::endl;
        return 0;
    }
    
  • Tupler (unregistered) in reply to Tupler

    I give up. How to do code blocks here?

    http://t.div0.ccc-offenbach.org/tuples.cpp

  • Miles Archer (unregistered) in reply to Tupler

    He only really needed prime numbered ones as you can derive the non-primes from the primes

  • (cs) in reply to Miles Archer

    Anonymous:
    He only really needed prime numbered ones as you can derive the non-primes from the primes

    <FONT face="Courier New" size=2>neither false or true.  yet.</FONT>

  • Kiss me, I'm Polish (unregistered) in reply to Alexis de Torquemada
    Alexis de Torquemada:


    With "God", you mean "Stroustrup", right?



    With "Stroustrup", you mean a function that converts strings to objective unsigned uppercase strings?
  • qiguai (unregistered) in reply to Mung Kee
    Mung Kee:


    I did a quick search for "Stroustrup".  Imagine having this line on your resume:

    "I designed and implemented the C++ programming language"

    http://www.research.att.com/~bs/homepage.html


    Fortunately, tenure provides a fair bit of job security. Still rather brave of him to admit it so readily.
  • Opt (unregistered)

    The best way would be inheritance with C++! C'mon, check it out!

    struct Single
    {
    int ID;
    string field1;
    };

    struct Pair:public Single
    {
    string field2;
    };

    struct Triple:public Pair
    {
    string field3;
    };

    struct Quadruple:public Triple
    {
    string field4;
    };

    struct Quintuple:public Quadruple
    {
    string field5;
    };
  • Fast B (unregistered) in reply to emptyset
    emptyset:

    Anonymous:
    He only really needed prime numbered ones as you can derive the non-primes from the primes

    <FONT face="Courier New" size=2>neither false or true.  yet.</FONT>

    Um...I think he was referring to this.

  • Fast B (unregistered) in reply to Fast B

    (obligatory)

    The real WTF is this forum software.

Leave a comment on “Structured Code Reuse”

Log In or post as a guest

Replying to comment #:

« Return to Article