https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112012-03-26T10:51:44ZRuby Issue Tracking SystemRuby master - Feature #6201: do_something then return :special_case (include "then" operator)https://redmine.ruby-lang.org/issues/6201?journal_id=251722012-03-26T10:51:44Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/25172/diff?detail_id=18498">diff</a>)</li></ul><p>=begin<br>
(follow response['location']; return :redirected) if response.redirect?<br>
=end</p> Ruby master - Feature #6201: do_something then return :special_case (include "then" operator)https://redmine.ruby-lang.org/issues/6201?journal_id=251732012-03-26T10:52:05Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul> Ruby master - Feature #6201: do_something then return :special_case (include "then" operator)https://redmine.ruby-lang.org/issues/6201?journal_id=251742012-03-26T11:14:09Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>=begin<br>
(follow response['location']; return :redirected) if response.redirect?<br>
=end</p>
</blockquote>
<p>Yes, Nobu, that is the other common idiom (the one I actually use), but I still don't find this readable.</p> Ruby master - Feature #6201: do_something then return :special_case (include "then" operator)https://redmine.ruby-lang.org/issues/6201?journal_id=251792012-03-26T21:21:24Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Target version</strong> changed from <i>2.0.0</i> to <i>3.0</i></li><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Assigned</i></li></ul><p>Hello, Rodrigo</p>
<p>In short, you are proposing a syntactic sugar:</p>
<p>A then B</p>
<p>as</p>
<p>(A; B)</p>
<p>, so that you can rewrite the following idiom:</p>
<p>(render(...); return) if condition?</p>
<p>with:</p>
<p>render(...) then return if condition?</p>
<p>, right?</p>
<p>I think it will cause compatibility issue.</p>
<p>if A then<br>
B<br>
C<br>
end</p>
<p>will be parsed as:</p>
<p>if (A; B)<br>
C<br>
end</p>
<p>So, 2.0 cannot include your idea. I mark this ticket as 3.0.</p>
<p>Personally, I like your idea very much.<br>
I often hesitate to write <em>whopping</em> four lines:</p>
<p>if C<br>
A<br>
B<br>
end</p>
<p>when A, B and C are all short and simple.<br>
I feel like defeat when I use a semicolon ;-)</p>
<p>In addition, it is cool to use "then" which is one of<br>
the least useful keywords ("for", "alias", ...) in Ruby.</p>
<p>So, I'm sorry that I can't accept your idea in 2.0.</p>
<p>BTW, when you write a proposal, I recommend you put a short<br>
example first to demonstrate your idea.<br>
It will not only be attractive to more people, but also make<br>
our ticket management task easier :-)</p>
<p>Thanks,</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Feature #6201: do_something then return :special_case (include "then" operator)https://redmine.ruby-lang.org/issues/6201?journal_id=251802012-03-26T21:36:29Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>Thank you for your feedback Yusuke. And yes, you understood it right. I actually tried to quickly find out first if "if ... then" was a valid syntax in Ruby, but I couldn't find it. It seems I didn't look hard enough...</p>
<p>I think my proposal was very clear in the subject/title (the example), but I think I can still edit it so that the example comes first in the description too. What do you think about this?</p>
<p>And I agree with you, if we're gonna use "then" and it is already an existent keyword, 2.0.0 can't be the target version :(</p> Ruby master - Feature #6201: do_something then return :special_case (include "then" operator)https://redmine.ruby-lang.org/issues/6201?journal_id=254552012-03-30T16:25:52Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul><p>Both "then" and "++" could compatibility problem. Your "a then b" or "a ++ b" can be implemented by "(a; b)" without any addition to the language.</p>
<p>Matz.</p> Ruby master - Feature #6201: do_something then return :special_case (include "then" operator)https://redmine.ruby-lang.org/issues/6201?journal_id=257542012-04-10T01:32:23Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>Sorry if I'm being boring here. Just let me know and I'll never ask about this again.</p>
<p>My understanding is that adding a new keyword to Ruby will break backward-compatibility and so it should be avoided at most.</p>
<p>In the other side, 'then' is not an option because it would conflict with if-then syntax.</p>
<p>My understanding is that "then" is totally optional in "if" statements, and it wouldn't make any difference if we just removed it.</p>
<p>So I thought that maybe we could deprecate "then" in "if" statements for Ruby 2.0, emiting warnings for it, while keeping it a reserved word.</p>
<p>After that we could include the proposed 'then' syntax in Ruby 3.0.</p>
<p>If you really don't want a syntax sugar for (a;b) just let me know and I'll stop asking about this.</p>
<p>Again, sorry if I'm bothering you.</p> Ruby master - Feature #6201: do_something then return :special_case (include "then" operator)https://redmine.ruby-lang.org/issues/6201?journal_id=257562012-04-10T02:12:16ZEregon (Benoit Daloze)
<ul></ul><p>rosenfeld (Rodrigo Rosenfeld Rosas) wrote:</p>
<blockquote>
<p>My understanding is that adding a new keyword to Ruby will break backward-compatibility and so it should be avoided at most.</p>
<p>In the other side, 'then' is not an option because it would conflict with if-then syntax.</p>
<p>My understanding is that "then" is totally optional in "if" statements, and it wouldn't make any difference if we just removed it.</p>
</blockquote>
<p>"then" can also be used in case statements.</p>
<blockquote>
<p>So I thought that maybe we could deprecate "then" in "if" statements for Ruby 2.0, emiting warnings for it, while keeping it a reserved word.</p>
<p>After that we could include the proposed 'then' syntax in Ruby 3.0.</p>
</blockquote>
<p>That sounds like a really good way to confuse users ;)</p>
<p>I think it isn't worth adding a new keyword for such a specific case. I'm more than happy with the multi-line way. Returning inside a method is something that should be clear as it modifies the control flow quite heavily.</p> Ruby master - Feature #6201: do_something then return :special_case (include "then" operator)https://redmine.ruby-lang.org/issues/6201?journal_id=257572012-04-10T02:18:43Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>You're right, Benoit, I completely forgot about the case statements.</p>
<p>Just forget about this then. By the way, did you like the pun? ;)</p> Ruby master - Feature #6201: do_something then return :special_case (include "then" operator)https://redmine.ruby-lang.org/issues/6201?journal_id=257582012-04-10T03:45:01ZEregon (Benoit Daloze)
<ul></ul><p>rosenfeld (Rodrigo Rosenfeld Rosas) wrote:</p>
<blockquote>
<p>Just forget about this then. By the way, did you like the pun? ;)</p>
</blockquote>
<p>Yes, and the "." match well ";" if you see what I mean in my return statement.</p> Ruby master - Feature #6201: do_something then return :special_case (include "then" operator)https://redmine.ruby-lang.org/issues/6201?journal_id=257622012-04-10T07:05:29Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>Eregon (Benoit Daloze) wrote:</p>
<blockquote>
<p>Yes, and the "." match well ";" if you see what I mean in my return statement.</p>
</blockquote>
<p>Sorry, I didn't :D I guess I'm too tired to get Yusuke's joke on <a class="issue tracker-2 status-2 priority-4 priority-default" title="Feature: Remove 'useless' 'concatenation' syntax (Assigned)" href="https://redmine.ruby-lang.org/issues/6265">#6265</a> and your statement :) Or maybe I'm just old enough :D</p>