Re:Invert a binary tree on LeetCode
by sltkr on Saturday June 13, 2015 @07:09AM
(#9710659)
Btw, Python has nifty multiple assignment, so you can write the swap simply as:
(Parentheses added to break over two lines.)
[ Parent
| on HN ]
Same in Ruby, but it doesn't need the parens to cross lines:
root.left, root.right = invert_tree(root.right),
invert_tree(root.left)
Re:Invert a binary tree on LeetCode
by TheLoneWolfling on Saturday June 13, 2015 @07:39PM
(#9713178)
I don't like that. I see it as potentially causing more far too many potential problems for such a niece feature.
Especially as Ruby has automatic unpacking of function returns, yes?
So something along the lines of:
a,b = function_returning_two_things(),
function_returning_one_thing()
could cause bugs.That's certainly possible - this would get you 'a' containing an array from the first function and 'b' with the result of the last.
Can't off the top of my head recall actually seeing such a bug. I totally appreciate the desire to reduce the potential for errors from typos, but that ship has kind of already sailed with either language. I guess it just depends how far you're willing to let it go.
Yay choice. Testing will catch it anyway, right?
:/