- 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
Programming for Non-Shitheads
Chapter 3: Understanding loops
Admin
Are you saying this is a bad example?? Upon what do you base this conclusion. I think you're way off base.
Admin
Guess he had a problem with his parents when he was young [:D]
Admin
What loops ??? No need for loops. Just use the keywork base.
Admin
Also, does this really have anything to do with inheritance? Isn't .Parent a reference to the physical container?
Admin
Damn all this time I though inheritence meant getting a large bag with a dollar sign on it as a result of a rich, anonymous relative dying. Now I know, it's just referring directly to objects by going through the Parent tree. Jeez if only some clever group could come up with a way for me to just use the functions without going through all that "Parent.Parent..." crap.
Admin
Depends on what's actually going on in the code. If that was an asp.net page/control/etc, then Parent is indeed referring to the container that owns the current control. From what it looks like though, it is some kind of ridiculous attempt at inheritance.
Admin
But without lengthy brute force code like this, my mad fast typing skills become less of a commodity.
Admin
Exactly .... No inheritance here !
I'd love to see the rest of this system ... it does make you think, though. What if you just started working at this company and were present for this informative demonstration? What would you do or say?
Admin
That has nothing to do with inheritance !
Admin
Right, but we have no guarantee that this is code from within a asp.net page, or from a windows form.
Admin
Isn't that more like "Advanced Loop unrolling"?
Admin
So what is your point? What does that have to do with inheritance or the way this code was written?
Admin
Oh fuck me...!
What a stupid ass monkey.
Admin
You guys missed the joke; it's "inheritance" as in it has parents and children.
But not OO inheritance.
Admin
In fact, I'll go a bit further and just state that the code is not from a Web or Windows Form. Since the call to .Parent is not being cast at all, and a method called Initialize()(which is not a method of the Control class) is being invoked, Parent cannot be either the Web or Windows control property named Parent.
Admin
Why didn't he write a GrandParent method that returns Parent.Parent?
(this.Parent.Parent.Parent.Parent.Parent.Parent != null) --> (this.GrandParent.GrandParent.GrandParent != null)
And while we're at it, let's add a Sister method, a BrotherInLaw method and a CrazyAuntYouOnlyMeetOnHolidays method.
Admin
The subject of the thread is inheritance and how this code was being used as an example of inheritance. From the looks of the code, actual inheritance wasn't used.
I was just pointing out to the poster that was saying the Parent property was a physical container, and I was merely pointing out that is the case in forms, but not in this code.
Admin
uhmmm do I see a need for recursive function here?
Admin
i'd be severely pissed if my "senior architect" broke this crap out.
i mean seriously....where did this senior guy come from? C# .NET via "Learn Access in 21 days and seven mins" ??
wow - rather, WTF!
-spacey
Admin
my brother's mom's dad's wife's mom's grandmother's uncle's cousin's husband's wife's cousin's niece's grandaughter's daughter's husband's daughter's son's brother, a.k.a. me, sees nothing wrong.............
Admin
If the app has that many levels of nesting of objects, then its very clear the "senior" deveoper had no clue. This is further supported by the claim that this parent.parent.parent.... chain is some form of inheritance.
If this were a job I just started, I would run screaming toward the nearest exit. Actually, I would have loved to have seen this presentation, just to see how far out in left field this "programmer" was.
Admin
mike - i'd be runnin right behind ya =)
-space
Admin
with all this parent on parent action, what do the kids look like??
Admin
Many, many years ago when I was 23
I was married to a Wider who was purty as can be
This Wider had a grown-up daughter who had hair of red
My father fell in love with her and soon they two were wed
This made my dad my son-in-law and changed my very life
For my daughter was my mother cause she was my father's wife
To complicate the matter even though it brought me joy
I soon became the father of a bouncing baby boy
I'm my own grampa,
I'm my own grampa
It sounds funny I know
But it really is so
I'm my own grampa
My little baby then became a brother-in-law to dad
And so became my uncle though it made me very sad
For if he was my uncle then that also made him brother
Of the Wider's grown up daughter who of course was my step-mother
My father's wife then had a son who kept them on the run
And he became my granchild for he was my daughters son
My wife is now my mother's mother and it makes me blue
Because although she is my wife she's my grandmother too
I'm my own grampa,
I'm my own grampa
It sounds funny I know
But it really is so
I'm my own grampa
Oh if my wife is my grandmother then I'm her grandchild
And every time I think of it, it nearly drives me wild
For now I have become strangest case you ever saw
As husband of my own grandmother I'm my own grampa
I'm my own grampa,
I'm my own grampa
It sounds funny I know
But it really is so
I'm my own grampa
Admin
Hmm. The preview function on this forum doesn't do a very good job of it.
Admin
Welcome to "The Daily WTF" [:P]
Admin
It might be smarter if each of the parent's just called their parent. then there would be only parent fall. obviously this person is too much of an idiot to think of that, tho.
Admin
AAAAAAAAAARRRRRRRRGGGGGGGGGHHHHHHHHH!!!!! runs screaming off interstate bridge
Admin
I'll apply as senior from now on.
Admin
Maybe he should have demo'd recursion before he did inheritance.
Admin
Yeah, then we could have seen GOTO statements as well. [:D]
Admin
They do that in West Virginia, Alabama and some parts of Kentucky.
Why use loops when you can make a family tree that cycles?
Admin
You could always go back and edit your post.
Oh wait...
<font size="1">(Just kidding Alex)</font>
Admin
Today's lesson: the if-statement:
public void anIfStatement()
{
}
this.anIfStatement();
Admin
Following your foot steps to the nearest, tallest bridge!
Admin
Aside from the obvious mess, isn't it more usual for the parent to create/initialize its children?
I'm finding it very difficult to imagine a scenario where child objects are responsible for initializing the parent...
Admin
I guess when someone tried to explain "composition" in objects, he got it a bit confused with "inheritance" and just went a bit overboard...
I miss out on so much by working on a small team of people we've all personally interviewed and asked for code samples from. Well, that and avoiding crappy languages in the first place (ducks VB.NET manuals being thrown at him).
Admin
<font size="2">inheritance, composition, aggregation...let's not fight in front of the children!</font>
Admin
ROFL @ Jon
-space
Admin
You'll want to take note of the language used in the example.......
;)
Admin
DanielR almost made me spray my tea.
Admin
I think a more appropriate job title for this guy would be "Senior O2 to CO2 Converter" instead of Senior Developer.
Admin
Alex seems to have stripped out the comments from the code, which were quite informative. As a public service announcement, here they are:
Admin
Assuming 'Parent' has a similar InitializeDisplay method:
public void InitializeDisplay () {
if (IsActive) {
Initialize();
if (Parent != null)
Parent.InitializeDisplay();
}
}
Admin
John, release the book and it'll sell. Actually I can help you write it:
Programming for Non-Shitheads
Chapter 4: How to ignore shitheads.
Admin
Imagine the endless hours of fun you'd get by using slightly more colorful names.
Gramps.Guvnor.Pops.Initialize();
or
Mammy.Grandma.Moogie.Initialize();
Seriously, what kind of a MORON 1) writes that crap and 2) shows it off as an example of inheritance?
There should be a "shoots random people then self" smiley on this board.
Admin
This program oughta be called "Inherited Bastard."
Admin
Might be real OOP inheritance, who knows with seeing the rest of the code? (Of course this would mean the code was written by a programmer who couldn't find the base keyword)
namespace WhatTheFrag {
public class a1 {
public void Initialize() { /* ... / }
}
public class a2 : a1 {
private a1 Parent;
public a2() {
Parent = this;
}
public void Initialize() { / ... */ }
}
public class a3 : a2 {
private a2 Parent;
public a3() {
Parent = this;
}
public void Initialize() { /* ... / }
}
/ ... */
public class a99 : a98 {
private a98 Parent;
public a99() {
Parent = this;
}
public void Initialize() { /* see original WTF */ }
}
}
Admin
Somebody needs to refactor, bad!