- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
I can't believe it.
Admin
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
Admin
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.
Admin
He knew what it was but was highly religious and did not want a structure with the word sex in it.
Admin
Can you say Collection? Array? Hash? How high did he/she go? Last time I checked, numbers were infinite.
Admin
So what?
Admin
So, when did he stop?
Admin
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.
Admin
I'd make a witty reply, but I feel a sudden urge to go spend several minutes in silence thanking God for C++ templates.
Admin
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.
Admin
You mean with the tuples? Looks like he stopped before he got to sex. So does this qualify as codus interruptus?
Admin
Aga! Thus infinite job security.
Admin
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;
}
Admin
With "God", you mean "Stroustrup", right?
Admin
Oh, now I see the benefit. So the constructors would be...
...etc.
Brillant!
Admin
I'd be curious to see a database designed by this fellow ....
Admin
a masterful plan
Admin
Before any bozos comment, I know it won't compile. I left the array names out.
Admin
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>
Admin
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
Admin
Technically, I mean
template<class Deity> class God;
It's up to you to instantiate the template with the correct parameter.
Admin
My resume already contains the line "I invented the Internet", and I don't want to make people suspicious.
Admin
In that case, I choose God<void>. Seems most compatible with my atheism.
Admin
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.
Admin
Hey! That won't compile. You left the array names out.
Admin
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.
Admin
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;
}
/* ... */
Admin
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
Admin
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)
Admin
What, no Dodecatuple class?
Admin
Aren't God objects an anti-pattern?
Admin
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"? [;)]
Admin
Wow, Richard Nixon and Al Gore on the same thread.
Admin
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;
;)
Admin
I take it String arrays or Linked Lists are now bad design!
Bart.
Admin
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?!?!
Admin
haha
Admin
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!!
Admin
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.
Admin
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>;
}
Admin
You can't!
You know when it's really bad when no one has even tried to defend it.
Admin
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) { }
};
template<> class Tuple<1> { std::string current; bool initialized;
public: Tuple() : current(), initialized(0) { }
};
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]
Admin
I give up. How to do code blocks here?
http://t.div0.ccc-offenbach.org/tuples.cpp
Admin
He only really needed prime numbered ones as you can derive the non-primes from the primes
Admin
<FONT face="Courier New" size=2>neither false or true. yet.</FONT>
Admin
With "Stroustrup", you mean a function that converts strings to objective unsigned uppercase strings?
Admin
Fortunately, tenure provides a fair bit of job security. Still rather brave of him to admit it so readily.
Admin
The best way would be inheritance with C++! C'mon, check it out!
Admin
Um...I think he was referring to this.
Admin
(obligatory)
The real WTF is this forum software.