ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:120073] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line
@ 2024-12-01  2:51 Dan0042 (Daniel DeLorme) via ruby-core
  2024-12-09  3:20 ` [ruby-core:120135] " martinemde (Martin Emde) via ruby-core
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Dan0042 (Daniel DeLorme) via ruby-core @ 2024-12-01  2:51 UTC (permalink / raw)
  To: ruby-core; +Cc: Dan0042 (Daniel DeLorme)

Issue #20925 has been reported by Dan0042 (Daniel DeLorme).

----------------------------------------
Feature #20925: Allow boolean operators at beginning of line to continue previous line
https://bugs.ruby-lang.org/issues/20925

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
----------------------------------------
I would like for this to become accepted syntax:

	condition1
	|| condition2
	
	condition1
	&& condition2
	
	condition1
	or condition2
	
	condition1
	and condition2
	
This is similar to how method chaining on the second line was added in Ruby 1.9

	expr
	.method
	
And it has the same advantage: when you have a multi-line expression, instead of hunting for the dot or boolean operator at the end of line1, it's right there at the beginning of line2, making the structure very obvious and readable. Please contrast:

	request.secret_key_base.present? &&
	  request.encrypted_signed_cookie_salt.present? &&
	  request.encrypted_cookie_salt.present? &&
	  request.use_authenticated_cookie_encryption
	
	request.secret_key_base.present?
	  && request.encrypted_signed_cookie_salt.present?
	  && request.encrypted_cookie_salt.present?
	  && request.use_authenticated_cookie_encryption

The first expression must rely on indentation to communicate the multi-line nature of the condition, and even then it's not as immediately obvious as the second expression, where we can see easily and immediately that this is a multi-line `&&` condition.

This syntax is also similar to how a trailing comma is allowed in arrays and hashes (and method calls since Ruby 1.9), with the same advantage. It makes for a cleaner diff when you add an element to the array/hash/conditional. Taking the previous example, imagine we are adding the condition `&& request.use_authenticated_cookie_encryption`. Now contrast the diff between the two styles:

	  request.secret_key_base.present? &&
	    request.encrypted_signed_cookie_salt.present? &&
	-    request.encrypted_cookie_salt.present?
	+    request.encrypted_cookie_salt.present? &&
	+   request.use_authenticated_cookie_encryption
	
	  request.secret_key_base.present?
	  && request.encrypted_signed_cookie_salt.present?
	  && request.encrypted_cookie_salt.present?
	+ && request.use_authenticated_cookie_encryption

Based on the above I would say this syntax is natural and consistent with existing Ruby syntactical elements, and would greatly improve code readability.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:120135] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line
  2024-12-01  2:51 [ruby-core:120073] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line Dan0042 (Daniel DeLorme) via ruby-core
@ 2024-12-09  3:20 ` martinemde (Martin Emde) via ruby-core
  2024-12-09  5:36 ` [ruby-core:120136] " mame (Yusuke Endoh) via ruby-core
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: martinemde (Martin Emde) via ruby-core @ 2024-12-09  3:20 UTC (permalink / raw)
  To: ruby-core; +Cc: martinemde (Martin Emde)

Issue #20925 has been updated by martinemde (Martin Emde).


The difference seems nice when you consider code like:

```
  if request.secret_key_base.present?
    && request.encrypted_signed_cookie_salt.present?
    && request.encrypted_cookie_salt.present?
    request.encrypted_cookie
  end
```

which is much easier to read than

```
  if request.secret_key_base.present? &&
    request.encrypted_signed_cookie_salt.present? &&
    request.encrypted_cookie_salt.present?
    request.encrypted_cookie
  end
```


----------------------------------------
Feature #20925: Allow boolean operators at beginning of line to continue previous line
https://bugs.ruby-lang.org/issues/20925#change-110884

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
----------------------------------------
I would like for this to become accepted syntax:

	condition1
	|| condition2
	
	condition1
	&& condition2
	
	condition1
	or condition2
	
	condition1
	and condition2
	
This is similar to how method chaining on the second line was added in Ruby 1.9

	expr
	.method
	
And it has the same advantage: when you have a multi-line expression, instead of hunting for the dot or boolean operator at the end of line1, it's right there at the beginning of line2, making the structure very obvious and readable. Please contrast:

	request.secret_key_base.present? &&
	  request.encrypted_signed_cookie_salt.present? &&
	  request.encrypted_cookie_salt.present? &&
	  request.use_authenticated_cookie_encryption
	
	request.secret_key_base.present?
	  && request.encrypted_signed_cookie_salt.present?
	  && request.encrypted_cookie_salt.present?
	  && request.use_authenticated_cookie_encryption

The first expression must rely on indentation to communicate the multi-line nature of the condition, and even then it's not as immediately obvious as the second expression, where we can see easily and immediately that this is a multi-line `&&` condition.

This syntax is also similar to how a trailing comma is allowed in arrays and hashes (and method calls since Ruby 1.9), with the same advantage. It makes for a cleaner diff when you add an element to the array/hash/conditional. Taking the previous example, imagine we are adding the condition `&& request.use_authenticated_cookie_encryption`. Now contrast the diff between the two styles:

	  request.secret_key_base.present? &&
	    request.encrypted_signed_cookie_salt.present? &&
	-   request.encrypted_cookie_salt.present?
	+   request.encrypted_cookie_salt.present? &&
	+   request.use_authenticated_cookie_encryption
	
	  request.secret_key_base.present?
	    && request.encrypted_signed_cookie_salt.present?
	    && request.encrypted_cookie_salt.present?
	+   && request.use_authenticated_cookie_encryption

Based on the above I would say this syntax is natural and consistent with existing Ruby syntactical elements, and would greatly improve code readability.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:120136] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line
  2024-12-01  2:51 [ruby-core:120073] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line Dan0042 (Daniel DeLorme) via ruby-core
  2024-12-09  3:20 ` [ruby-core:120135] " martinemde (Martin Emde) via ruby-core
@ 2024-12-09  5:36 ` mame (Yusuke Endoh) via ruby-core
  2024-12-10 13:28 ` [ruby-core:120156] " lpogic via ruby-core
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-12-09  5:36 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20925 has been updated by mame (Yusuke Endoh).


As a developer involved in the implementation of Ruby grammar, I am not a fan in this extension, but as a Ruby programmer, I understand you want to write that.

I might want to write it with the following indentation anyway.

```
if request.secret_key_base.present?
&& request.encrypted_signed_cookie_salt.present?
&& request.encrypted_cookie_salt.present?
  request.encrypted_cookie
end
```


----------------------------------------
Feature #20925: Allow boolean operators at beginning of line to continue previous line
https://bugs.ruby-lang.org/issues/20925#change-110885

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
----------------------------------------
I would like for this to become accepted syntax:

	condition1
	|| condition2
	
	condition1
	&& condition2
	
	condition1
	or condition2
	
	condition1
	and condition2
	
This is similar to how method chaining on the second line was added in Ruby 1.9

	expr
	.method
	
And it has the same advantage: when you have a multi-line expression, instead of hunting for the dot or boolean operator at the end of line1, it's right there at the beginning of line2, making the structure very obvious and readable. Please contrast:

	request.secret_key_base.present? &&
	  request.encrypted_signed_cookie_salt.present? &&
	  request.encrypted_cookie_salt.present? &&
	  request.use_authenticated_cookie_encryption
	
	request.secret_key_base.present?
	  && request.encrypted_signed_cookie_salt.present?
	  && request.encrypted_cookie_salt.present?
	  && request.use_authenticated_cookie_encryption

The first expression must rely on indentation to communicate the multi-line nature of the condition, and even then it's not as immediately obvious as the second expression, where we can see easily and immediately that this is a multi-line `&&` condition.

This syntax is also similar to how a trailing comma is allowed in arrays and hashes (and method calls since Ruby 1.9), with the same advantage. It makes for a cleaner diff when you add an element to the array/hash/conditional. Taking the previous example, imagine we are adding the condition `&& request.use_authenticated_cookie_encryption`. Now contrast the diff between the two styles:

	  request.secret_key_base.present? &&
	    request.encrypted_signed_cookie_salt.present? &&
	-   request.encrypted_cookie_salt.present?
	+   request.encrypted_cookie_salt.present? &&
	+   request.use_authenticated_cookie_encryption
	
	  request.secret_key_base.present?
	    && request.encrypted_signed_cookie_salt.present?
	    && request.encrypted_cookie_salt.present?
	+   && request.use_authenticated_cookie_encryption

Based on the above I would say this syntax is natural and consistent with existing Ruby syntactical elements, and would greatly improve code readability.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:120156] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line
  2024-12-01  2:51 [ruby-core:120073] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line Dan0042 (Daniel DeLorme) via ruby-core
  2024-12-09  3:20 ` [ruby-core:120135] " martinemde (Martin Emde) via ruby-core
  2024-12-09  5:36 ` [ruby-core:120136] " mame (Yusuke Endoh) via ruby-core
@ 2024-12-10 13:28 ` lpogic via ruby-core
  2024-12-18  6:13 ` [ruby-core:120290] " matz (Yukihiro Matsumoto) via ruby-core
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: lpogic via ruby-core @ 2024-12-10 13:28 UTC (permalink / raw)
  To: ruby-core; +Cc: lpogic

Issue #20925 has been updated by lpogic (Łukasz Pomietło).


+1. Regarding indentation, I once read that a multi-line "if" condition looks better with "then":

```
if request.secret_key_base.present?
  && request.encrypted_signed_cookie_salt.present?
  && request.encrypted_cookie_salt.present?
then
  request.encrypted_cookie
end
```

----------------------------------------
Feature #20925: Allow boolean operators at beginning of line to continue previous line
https://bugs.ruby-lang.org/issues/20925#change-110910

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
----------------------------------------
I would like for this to become accepted syntax:

	condition1
	|| condition2
	
	condition1
	&& condition2
	
	condition1
	or condition2
	
	condition1
	and condition2
	
This is similar to how method chaining on the second line was added in Ruby 1.9

	expr
	.method
	
And it has the same advantage: when you have a multi-line expression, instead of hunting for the dot or boolean operator at the end of line1, it's right there at the beginning of line2, making the structure very obvious and readable. Please contrast:

	request.secret_key_base.present? &&
	  request.encrypted_signed_cookie_salt.present? &&
	  request.encrypted_cookie_salt.present? &&
	  request.use_authenticated_cookie_encryption
	
	request.secret_key_base.present?
	  && request.encrypted_signed_cookie_salt.present?
	  && request.encrypted_cookie_salt.present?
	  && request.use_authenticated_cookie_encryption

The first expression must rely on indentation to communicate the multi-line nature of the condition, and even then it's not as immediately obvious as the second expression, where we can see easily and immediately that this is a multi-line `&&` condition.

This syntax is also similar to how a trailing comma is allowed in arrays and hashes (and method calls since Ruby 1.9), with the same advantage. It makes for a cleaner diff when you add an element to the array/hash/conditional. Taking the previous example, imagine we are adding the condition `&& request.use_authenticated_cookie_encryption`. Now contrast the diff between the two styles:

	  request.secret_key_base.present? &&
	    request.encrypted_signed_cookie_salt.present? &&
	-   request.encrypted_cookie_salt.present?
	+   request.encrypted_cookie_salt.present? &&
	+   request.use_authenticated_cookie_encryption
	
	  request.secret_key_base.present?
	    && request.encrypted_signed_cookie_salt.present?
	    && request.encrypted_cookie_salt.present?
	+   && request.use_authenticated_cookie_encryption

Based on the above I would say this syntax is natural and consistent with existing Ruby syntactical elements, and would greatly improve code readability.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:120290] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line
  2024-12-01  2:51 [ruby-core:120073] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line Dan0042 (Daniel DeLorme) via ruby-core
                   ` (2 preceding siblings ...)
  2024-12-10 13:28 ` [ruby-core:120156] " lpogic via ruby-core
@ 2024-12-18  6:13 ` matz (Yukihiro Matsumoto) via ruby-core
  2024-12-21 21:04 ` [ruby-core:120357] " kddnewton (Kevin Newton) via ruby-core
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2024-12-18  6:13 UTC (permalink / raw)
  To: ruby-core; +Cc: matz (Yukihiro Matsumoto)

Issue #20925 has been updated by matz (Yukihiro Matsumoto).


+1. Although it might take time to implement since we have duplicated parser implementations at the moment.

Matz.


----------------------------------------
Feature #20925: Allow boolean operators at beginning of line to continue previous line
https://bugs.ruby-lang.org/issues/20925#change-111055

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
----------------------------------------
I would like for this to become accepted syntax:

	condition1
	|| condition2
	
	condition1
	&& condition2
	
	condition1
	or condition2
	
	condition1
	and condition2
	
This is similar to how method chaining on the second line was added in Ruby 1.9

	expr
	.method
	
And it has the same advantage: when you have a multi-line expression, instead of hunting for the dot or boolean operator at the end of line1, it's right there at the beginning of line2, making the structure very obvious and readable. Please contrast:

	request.secret_key_base.present? &&
	  request.encrypted_signed_cookie_salt.present? &&
	  request.encrypted_cookie_salt.present? &&
	  request.use_authenticated_cookie_encryption
	
	request.secret_key_base.present?
	  && request.encrypted_signed_cookie_salt.present?
	  && request.encrypted_cookie_salt.present?
	  && request.use_authenticated_cookie_encryption

The first expression must rely on indentation to communicate the multi-line nature of the condition, and even then it's not as immediately obvious as the second expression, where we can see easily and immediately that this is a multi-line `&&` condition.

This syntax is also similar to how a trailing comma is allowed in arrays and hashes (and method calls since Ruby 1.9), with the same advantage. It makes for a cleaner diff when you add an element to the array/hash/conditional. Taking the previous example, imagine we are adding the condition `&& request.use_authenticated_cookie_encryption`. Now contrast the diff between the two styles:

	  request.secret_key_base.present? &&
	    request.encrypted_signed_cookie_salt.present? &&
	-   request.encrypted_cookie_salt.present?
	+   request.encrypted_cookie_salt.present? &&
	+   request.use_authenticated_cookie_encryption
	
	  request.secret_key_base.present?
	    && request.encrypted_signed_cookie_salt.present?
	    && request.encrypted_cookie_salt.present?
	+   && request.use_authenticated_cookie_encryption

Based on the above I would say this syntax is natural and consistent with existing Ruby syntactical elements, and would greatly improve code readability.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:120357] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line
  2024-12-01  2:51 [ruby-core:120073] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line Dan0042 (Daniel DeLorme) via ruby-core
                   ` (3 preceding siblings ...)
  2024-12-18  6:13 ` [ruby-core:120290] " matz (Yukihiro Matsumoto) via ruby-core
@ 2024-12-21 21:04 ` kddnewton (Kevin Newton) via ruby-core
  2024-12-23  5:54 ` [ruby-core:120373] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-12-21 21:04 UTC (permalink / raw)
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20925 has been updated by kddnewton (Kevin Newton).


This PR is for Prism support: https://github.com/ruby/prism/pull/3337. I will add some CRuby tests that we can skip on parse.y for now in a follow-up PR.

----------------------------------------
Feature #20925: Allow boolean operators at beginning of line to continue previous line
https://bugs.ruby-lang.org/issues/20925#change-111136

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
----------------------------------------
I would like for this to become accepted syntax:

	condition1
	|| condition2
	
	condition1
	&& condition2
	
	condition1
	or condition2
	
	condition1
	and condition2
	
This is similar to how method chaining on the second line was added in Ruby 1.9

	expr
	.method
	
And it has the same advantage: when you have a multi-line expression, instead of hunting for the dot or boolean operator at the end of line1, it's right there at the beginning of line2, making the structure very obvious and readable. Please contrast:

	request.secret_key_base.present? &&
	  request.encrypted_signed_cookie_salt.present? &&
	  request.encrypted_cookie_salt.present? &&
	  request.use_authenticated_cookie_encryption
	
	request.secret_key_base.present?
	  && request.encrypted_signed_cookie_salt.present?
	  && request.encrypted_cookie_salt.present?
	  && request.use_authenticated_cookie_encryption

The first expression must rely on indentation to communicate the multi-line nature of the condition, and even then it's not as immediately obvious as the second expression, where we can see easily and immediately that this is a multi-line `&&` condition.

This syntax is also similar to how a trailing comma is allowed in arrays and hashes (and method calls since Ruby 1.9), with the same advantage. It makes for a cleaner diff when you add an element to the array/hash/conditional. Taking the previous example, imagine we are adding the condition `&& request.use_authenticated_cookie_encryption`. Now contrast the diff between the two styles:

	  request.secret_key_base.present? &&
	    request.encrypted_signed_cookie_salt.present? &&
	-   request.encrypted_cookie_salt.present?
	+   request.encrypted_cookie_salt.present? &&
	+   request.use_authenticated_cookie_encryption
	
	  request.secret_key_base.present?
	    && request.encrypted_signed_cookie_salt.present?
	    && request.encrypted_cookie_salt.present?
	+   && request.use_authenticated_cookie_encryption

Based on the above I would say this syntax is natural and consistent with existing Ruby syntactical elements, and would greatly improve code readability.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:120373] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line
  2024-12-01  2:51 [ruby-core:120073] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line Dan0042 (Daniel DeLorme) via ruby-core
                   ` (4 preceding siblings ...)
  2024-12-21 21:04 ` [ruby-core:120357] " kddnewton (Kevin Newton) via ruby-core
@ 2024-12-23  5:54 ` nobu (Nobuyoshi Nakada) via ruby-core
  2024-12-23 13:14 ` [ruby-core:120379] " Dan0042 (Daniel DeLorme) via ruby-core
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-12-23  5:54 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #20925 has been updated by nobu (Nobuyoshi Nakada).


`&&` and `||` are questionable for me because they can change RHS of assignment.

https://github.com/nobu/ruby/tree/leading-logical

----------------------------------------
Feature #20925: Allow boolean operators at beginning of line to continue previous line
https://bugs.ruby-lang.org/issues/20925#change-111150

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
----------------------------------------
I would like for this to become accepted syntax:

	condition1
	|| condition2
	
	condition1
	&& condition2
	
	condition1
	or condition2
	
	condition1
	and condition2
	
This is similar to how method chaining on the second line was added in Ruby 1.9

	expr
	.method
	
And it has the same advantage: when you have a multi-line expression, instead of hunting for the dot or boolean operator at the end of line1, it's right there at the beginning of line2, making the structure very obvious and readable. Please contrast:

	request.secret_key_base.present? &&
	  request.encrypted_signed_cookie_salt.present? &&
	  request.encrypted_cookie_salt.present? &&
	  request.use_authenticated_cookie_encryption
	
	request.secret_key_base.present?
	  && request.encrypted_signed_cookie_salt.present?
	  && request.encrypted_cookie_salt.present?
	  && request.use_authenticated_cookie_encryption

The first expression must rely on indentation to communicate the multi-line nature of the condition, and even then it's not as immediately obvious as the second expression, where we can see easily and immediately that this is a multi-line `&&` condition.

This syntax is also similar to how a trailing comma is allowed in arrays and hashes (and method calls since Ruby 1.9), with the same advantage. It makes for a cleaner diff when you add an element to the array/hash/conditional. Taking the previous example, imagine we are adding the condition `&& request.use_authenticated_cookie_encryption`. Now contrast the diff between the two styles:

	  request.secret_key_base.present? &&
	    request.encrypted_signed_cookie_salt.present? &&
	-   request.encrypted_cookie_salt.present?
	+   request.encrypted_cookie_salt.present? &&
	+   request.use_authenticated_cookie_encryption
	
	  request.secret_key_base.present?
	    && request.encrypted_signed_cookie_salt.present?
	    && request.encrypted_cookie_salt.present?
	+   && request.use_authenticated_cookie_encryption

Based on the above I would say this syntax is natural and consistent with existing Ruby syntactical elements, and would greatly improve code readability.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:120379] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line
  2024-12-01  2:51 [ruby-core:120073] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line Dan0042 (Daniel DeLorme) via ruby-core
                   ` (5 preceding siblings ...)
  2024-12-23  5:54 ` [ruby-core:120373] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2024-12-23 13:14 ` Dan0042 (Daniel DeLorme) via ruby-core
  2025-01-09  6:48 ` [ruby-core:120563] " nobu (Nobuyoshi Nakada) via ruby-core
  2025-01-09 14:21 ` [ruby-core:120575] " Dan0042 (Daniel DeLorme) via ruby-core
  8 siblings, 0 replies; 10+ messages in thread
From: Dan0042 (Daniel DeLorme) via ruby-core @ 2024-12-23 13:14 UTC (permalink / raw)
  To: ruby-core; +Cc: Dan0042 (Daniel DeLorme)

Issue #20925 has been updated by Dan0042 (Daniel DeLorme).


	a = b
	&& c
should be parsed as

	a = (b
	&& c)
correct?

----------------------------------------
Feature #20925: Allow boolean operators at beginning of line to continue previous line
https://bugs.ruby-lang.org/issues/20925#change-111156

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
----------------------------------------
I would like for this to become accepted syntax:

	condition1
	|| condition2
	
	condition1
	&& condition2
	
	condition1
	or condition2
	
	condition1
	and condition2
	
This is similar to how method chaining on the second line was added in Ruby 1.9

	expr
	.method
	
And it has the same advantage: when you have a multi-line expression, instead of hunting for the dot or boolean operator at the end of line1, it's right there at the beginning of line2, making the structure very obvious and readable. Please contrast:

	request.secret_key_base.present? &&
	  request.encrypted_signed_cookie_salt.present? &&
	  request.encrypted_cookie_salt.present? &&
	  request.use_authenticated_cookie_encryption
	
	request.secret_key_base.present?
	  && request.encrypted_signed_cookie_salt.present?
	  && request.encrypted_cookie_salt.present?
	  && request.use_authenticated_cookie_encryption

The first expression must rely on indentation to communicate the multi-line nature of the condition, and even then it's not as immediately obvious as the second expression, where we can see easily and immediately that this is a multi-line `&&` condition.

This syntax is also similar to how a trailing comma is allowed in arrays and hashes (and method calls since Ruby 1.9), with the same advantage. It makes for a cleaner diff when you add an element to the array/hash/conditional. Taking the previous example, imagine we are adding the condition `&& request.use_authenticated_cookie_encryption`. Now contrast the diff between the two styles:

	  request.secret_key_base.present? &&
	    request.encrypted_signed_cookie_salt.present? &&
	-   request.encrypted_cookie_salt.present?
	+   request.encrypted_cookie_salt.present? &&
	+   request.use_authenticated_cookie_encryption
	
	  request.secret_key_base.present?
	    && request.encrypted_signed_cookie_salt.present?
	    && request.encrypted_cookie_salt.present?
	+   && request.use_authenticated_cookie_encryption

Based on the above I would say this syntax is natural and consistent with existing Ruby syntactical elements, and would greatly improve code readability.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:120563] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line
  2024-12-01  2:51 [ruby-core:120073] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line Dan0042 (Daniel DeLorme) via ruby-core
                   ` (6 preceding siblings ...)
  2024-12-23 13:14 ` [ruby-core:120379] " Dan0042 (Daniel DeLorme) via ruby-core
@ 2025-01-09  6:48 ` nobu (Nobuyoshi Nakada) via ruby-core
  2025-01-09 14:21 ` [ruby-core:120575] " Dan0042 (Daniel DeLorme) via ruby-core
  8 siblings, 0 replies; 10+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2025-01-09  6:48 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #20925 has been updated by nobu (Nobuyoshi Nakada).


Dan0042 (Daniel DeLorme) wrote in #note-8:
> 	a = b
> 	&& c
> should be parsed as
> 
> 	a = (b
> 	&& c)
> correct? That would not change the RHS of assignment.

Currently the first line in the former is complete code.
I mean that the second line will change the RHS to `b && c`.

----------------------------------------
Feature #20925: Allow boolean operators at beginning of line to continue previous line
https://bugs.ruby-lang.org/issues/20925#change-111384

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
----------------------------------------
I would like for this to become accepted syntax:

	condition1
	|| condition2
	
	condition1
	&& condition2
	
	condition1
	or condition2
	
	condition1
	and condition2
	
This is similar to how method chaining on the second line was added in Ruby 1.9

	expr
	.method
	
And it has the same advantage: when you have a multi-line expression, instead of hunting for the dot or boolean operator at the end of line1, it's right there at the beginning of line2, making the structure very obvious and readable. Please contrast:

	request.secret_key_base.present? &&
	  request.encrypted_signed_cookie_salt.present? &&
	  request.encrypted_cookie_salt.present? &&
	  request.use_authenticated_cookie_encryption
	
	request.secret_key_base.present?
	  && request.encrypted_signed_cookie_salt.present?
	  && request.encrypted_cookie_salt.present?
	  && request.use_authenticated_cookie_encryption

The first expression must rely on indentation to communicate the multi-line nature of the condition, and even then it's not as immediately obvious as the second expression, where we can see easily and immediately that this is a multi-line `&&` condition.

This syntax is also similar to how a trailing comma is allowed in arrays and hashes (and method calls since Ruby 1.9), with the same advantage. It makes for a cleaner diff when you add an element to the array/hash/conditional. Taking the previous example, imagine we are adding the condition `&& request.use_authenticated_cookie_encryption`. Now contrast the diff between the two styles:

	  request.secret_key_base.present? &&
	    request.encrypted_signed_cookie_salt.present? &&
	-   request.encrypted_cookie_salt.present?
	+   request.encrypted_cookie_salt.present? &&
	+   request.use_authenticated_cookie_encryption
	
	  request.secret_key_base.present?
	    && request.encrypted_signed_cookie_salt.present?
	    && request.encrypted_cookie_salt.present?
	+   && request.use_authenticated_cookie_encryption

Based on the above I would say this syntax is natural and consistent with existing Ruby syntactical elements, and would greatly improve code readability.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:120575] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line
  2024-12-01  2:51 [ruby-core:120073] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line Dan0042 (Daniel DeLorme) via ruby-core
                   ` (7 preceding siblings ...)
  2025-01-09  6:48 ` [ruby-core:120563] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2025-01-09 14:21 ` Dan0042 (Daniel DeLorme) via ruby-core
  8 siblings, 0 replies; 10+ messages in thread
From: Dan0042 (Daniel DeLorme) via ruby-core @ 2025-01-09 14:21 UTC (permalink / raw)
  To: ruby-core; +Cc: Dan0042 (Daniel DeLorme)

Issue #20925 has been updated by Dan0042 (Daniel DeLorme).


It's the same thing for method calls right?
```ruby
a = 1
.to_s
```
It changes the RHS of assignment to `1.to_s`
A boolean operators on the second line is consistent with that so I don't see a problem, since there's no backward incompatibility.

----------------------------------------
Feature #20925: Allow boolean operators at beginning of line to continue previous line
https://bugs.ruby-lang.org/issues/20925#change-111402

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
----------------------------------------
I would like for this to become accepted syntax:

	condition1
	|| condition2
	
	condition1
	&& condition2
	
	condition1
	or condition2
	
	condition1
	and condition2
	
This is similar to how method chaining on the second line was added in Ruby 1.9

	expr
	.method
	
And it has the same advantage: when you have a multi-line expression, instead of hunting for the dot or boolean operator at the end of line1, it's right there at the beginning of line2, making the structure very obvious and readable. Please contrast:

	request.secret_key_base.present? &&
	  request.encrypted_signed_cookie_salt.present? &&
	  request.encrypted_cookie_salt.present? &&
	  request.use_authenticated_cookie_encryption
	
	request.secret_key_base.present?
	  && request.encrypted_signed_cookie_salt.present?
	  && request.encrypted_cookie_salt.present?
	  && request.use_authenticated_cookie_encryption

The first expression must rely on indentation to communicate the multi-line nature of the condition, and even then it's not as immediately obvious as the second expression, where we can see easily and immediately that this is a multi-line `&&` condition.

This syntax is also similar to how a trailing comma is allowed in arrays and hashes (and method calls since Ruby 1.9), with the same advantage. It makes for a cleaner diff when you add an element to the array/hash/conditional. Taking the previous example, imagine we are adding the condition `&& request.use_authenticated_cookie_encryption`. Now contrast the diff between the two styles:

	  request.secret_key_base.present? &&
	    request.encrypted_signed_cookie_salt.present? &&
	-   request.encrypted_cookie_salt.present?
	+   request.encrypted_cookie_salt.present? &&
	+   request.use_authenticated_cookie_encryption
	
	  request.secret_key_base.present?
	    && request.encrypted_signed_cookie_salt.present?
	    && request.encrypted_cookie_salt.present?
	+   && request.use_authenticated_cookie_encryption

Based on the above I would say this syntax is natural and consistent with existing Ruby syntactical elements, and would greatly improve code readability.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-01-09 14:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-01  2:51 [ruby-core:120073] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line Dan0042 (Daniel DeLorme) via ruby-core
2024-12-09  3:20 ` [ruby-core:120135] " martinemde (Martin Emde) via ruby-core
2024-12-09  5:36 ` [ruby-core:120136] " mame (Yusuke Endoh) via ruby-core
2024-12-10 13:28 ` [ruby-core:120156] " lpogic via ruby-core
2024-12-18  6:13 ` [ruby-core:120290] " matz (Yukihiro Matsumoto) via ruby-core
2024-12-21 21:04 ` [ruby-core:120357] " kddnewton (Kevin Newton) via ruby-core
2024-12-23  5:54 ` [ruby-core:120373] " nobu (Nobuyoshi Nakada) via ruby-core
2024-12-23 13:14 ` [ruby-core:120379] " Dan0042 (Daniel DeLorme) via ruby-core
2025-01-09  6:48 ` [ruby-core:120563] " nobu (Nobuyoshi Nakada) via ruby-core
2025-01-09 14:21 ` [ruby-core:120575] " Dan0042 (Daniel DeLorme) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).