- 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
what? so we have come to the point where child with multiple parents is considered wtf?
Admin
Why would there be any correlation between the kind of data structures it uses and the fact that it has an HTTP/HTML-based user interface?
Admin
No note of children either. Note that
parent
apparently isn't a property of anything at all.And obviously the empty
catch
es are a (common) WTF too.Admin
It's like some bizarre sort of multiple inheritance: you keep searching through your parent classes/objects until you find one that "implements" the compositionExportResultMessage method.
Admin
Almost certainly that's it, although perhaps just single inheritance. The
parent
array is not an array of the immediate parents(1), but of the successive generations of parent, grandparent, greatgrandparent, etc.(1) It might be, but a system of A-from-B-from-C seems more likely.
But by all that's holy, don't use gdmf exceptions to report "I don't support that".
Admin
this...code...is...horrifying...
Admin
There are add-ins for IDEs that support linking a formatted comment to external references. May or may not be the case here.
Admin
agreed, the array is likely a list of parents and grandparents walking up the tree, in order of distance from current object. Also, the difference is also the value of success, so it'll give 'true' or 'false' up, not just the message
The only WTF here is using exceptions as control flow. Remy fail.
Admin
If a parent does not have the function compositionExportResultMessage, it will throw an exception. TRWTF is trying to find the parent which has the function using exception handling.
Admin
This looks a lot like JavaScript code in a web browser. If so, parent would really be window.parent, and can be treated like an array: https://developer.mozilla.org/en-US/docs/Web/API/Window/frames
So that part of the API call does make a little sense.
Admin
Yeah, a less WTF way would be something like this (I'm assuming JavaScript)
if ('compositionExportResultMessage' in parent[i]) { parent[i].compositionExportResultMessage(obj.success, obj.response, 'info'); break; }
And of course, instead of having almost-duplicate code in both branches, just set a variable to either 'info' or 'error' and write the loop once.
But compared to many of the WTFs we've seen, this is really pretty mild.
Admin
Ah, the "are you my mother" anti-pattern. The catch block should look for the child to throw "you are a snort"
Admin
That's basically how you do multiple inheritance in a dynamic language. Even done "right" it's bizarre.
TRWTF is inheritance.
Admin
FFS, just define a dummy method on a superclass.
Admin
It's even how you do single-inheritance in dynamic languages. :-)
More seriously, I too was thinking that you'd fill in the "parent" array with the parent objects in your desired MRO (as Python calls it). This isn't general-purpose inheritance though as it doesn't seem to passing "this" through.
Admin
Everybody is assuming that the people that created this piece of code named their variables to indicate a hierarchy structure. There's nothing in this code that indicates any form of inheritance, subclassing, superclassing, or tree structures, other than a name that might be misleading. It's simply iteration over a an array of maps of strings to functions.
The real WTF here is swallowing exceptions and using exceptions for flow control. The code 'duplication' might be another.
Admin
It's even how you do single-inheritance in dynamic languages. :-)
More seriously, I too was thinking that you'd fill in the "parent" array with the parent objects in your desired MRO (as Python calls it). This isn't general-purpose inheritance though as it doesn't seem to passing "this" through.
Admin
Well, come on Thomas, don't leave us hanging.
What was #BZ7350?
Meanwhile, if this is some sort of inheritance thing going on, why aren't the language's own inheritance semantics being used? Did they really need to hand-roll their own?
Admin
And there are IDE / VCS combinations that don't play well together, usually when one of them is a WTF choice. I'm privileged to work with Perforce whose Xcode integration was dropped years ago. To view when and who wrote a particular line, you have to use the Time-lapse view in the Perforce GUI which is a buggy Qt app with bad usability. Thus, //#BZ7350.
Admin
Um no, the second WTF is that this crazy code is probably copypasta'd all over the code base, instead of being a common "send to parent" function.
Admin
The "parent" thing is a very small detail over all the WTF-ery there is in this small snippet.
The two branches of the if/else that do exactly the same thing except for a very small detail (use "info" or "error"). So much copy/paste that even the comment is copied. The concept of accessing an array inside a try/catch instead of testing if the value exists. The empty catch without even a comment.
For more context, now that the blow has softened:
Next time I'll do better, I promise.
Admin
As far as I'm concerned, I'm the only child with 2 parents. But to be fair... In a normal (computerscience) hierarchy, a child with multiple parents is just an upside-down tree.. So I must be the parent and my parents are my children.
Addendum 2018-10-08 18:56: /addendum: I never understand the strange method of placing a comment, where I 'reply to someone' without being able to quote :(