Break Out of your Parents
« Return to Article (Viewing 22 comments)
- not a robot (unregistered) 2018-10-04
Reply Adminwhat? so we have come to the point where child with multiple parents is considered wtf?
- I'm not a robot (unregistered) 2018-10-04
Reply AdminSure, there are data structures where children can have multiple parents, but how often do you see them? Especially in web programming, which this appears to be, which mostly uses trees.
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?
- someone (unregistered) 2018-10-04
Reply AdminNo 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. - Simon Clarkstone (unregistered) 2018-10-04
Reply AdminIt'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.
- Steve_The_Cynic (nodebb) in reply to Simon Clarkstone 2018-10-04
Reply AdminIt's like some bizarre sort of multiple inheritance:
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".
See AlsoWe Tasted And Ranked 7 Canned Pasta Brands From Worst To Best - The Daily MealAlternatives to white pasta might seem healthful, but read that label carefully‘A bad roommate is like a toxic partner’: When sharing an apartment becomes a nightmareCan you really cook anything in a microwave? I tested Anyday cookware for a month to find out - Ted (unregistered) 2018-10-04
Reply Adminthis...code...is...horrifying...
- TheCPUWizard (nodebb) 2018-10-04
Reply AdminThere are add-ins for IDEs that support linking a formatted comment to external references. May or may not be the case here.
- doubting_poster (unregistered) in reply to Steve_The_Cynic 2018-10-04
Reply Adminagreed, 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.
- JSdev (unregistered) 2018-10-04
Reply AdminIf 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.
- Alex Vincent (nodebb) 2018-10-04
Reply AdminThis 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.
- Barry Margolin 0 (nodebb) 2018-10-04
Reply AdminYeah, 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.
- RichP (unregistered) 2018-10-04
Reply AdminAh, the "are you my mother" anti-pattern.The catch block should look for the child to throw "you are a snort"
- siciac (unregistered) in reply to Simon Clarkstone 2018-10-04
Reply AdminIt'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.
That's basically how you do multiple inheritance in a dynamic language. Even done "right" it's bizarre.
TRWTF is inheritance.
- siciac (unregistered) in reply to Barry Margolin 0 2018-10-04
Reply AdminYeah, a less WTF way would be something like this
FFS, just define a dummy method on a superclass.
- Simon Clarkstone (unregistered) in reply to siciac 2018-10-04
Reply AdminIt'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.
- Perri Nelson (unregistered) 2018-10-04
Reply AdminEverybody 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.
- Simon Clarkstone (unregistered) in reply to siciac 2018-10-04
Reply AdminIt'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.
- Watson (nodebb) 2018-10-04
Reply AdminWell, 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?
- marczellm (nodebb) in reply to TheCPUWizard 2018-10-04
Reply AdminAnd 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.
- I dunno LOL ¯\(°_o)/¯ (unregistered) in reply to doubting_poster 2018-10-05
Reply AdminUm 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.
- cosmo0 (nodebb) in reply to I dunno LOL ¯\(°_o)/¯ 2018-10-08
Reply AdminThe "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:
- This tries to manage documents tree. Thus the "parent" is not a code concept but a business concept. The whole story falls apart. I should have provided more context. Sorry.
- This is Javascript. No inheritance whatsoever.
- BZ stands for BugZilla. Obviously I can't look for it because we migrated long ago.
- The "parent" variable is never declared. I don't see how iterating on it ever worked.
- The method this code resides in is never called, anyway (phew! disaster averted)
- The biggest WTF of all: this code uses YUI, like most of the app. In 2018.
Next time I'll do better, I promise.
- Flips (nodebb) in reply to not a robot 2018-10-08
Reply AdminAs 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 :(
« Return to Article