ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "Dan0042 (Daniel DeLorme) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "Dan0042 (Daniel DeLorme)" <noreply@ruby-lang.org>
Subject: [ruby-core:120073] [Ruby master Feature#20925] Allow boolean operators at beginning of line to continue previous line
Date: Sun, 01 Dec 2024 02:51:36 +0000 (UTC)	[thread overview]
Message-ID: <redmine.issue-20925.20241201025135.11019@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-20925.20241201025135.11019@ruby-lang.org>

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/

       reply	other threads:[~2024-12-01  2:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-01  2:51 Dan0042 (Daniel DeLorme) via ruby-core [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.issue-20925.20241201025135.11019@ruby-lang.org \
    --to=ruby-core@ml.ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).