From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 44D331F4BD for ; Wed, 9 Oct 2019 06:52:57 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id B610F120A15; Wed, 9 Oct 2019 15:52:46 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id C988612098B for ; Wed, 9 Oct 2019 15:52:43 +0900 (JST) Received: by filter0144p3mdw1.sendgrid.net with SMTP id filter0144p3mdw1-4973-5D9D83BE-1D 2019-10-09 06:52:46.396251495 +0000 UTC m=+136968.969761791 Received: from herokuapp.com (unknown [54.167.22.24]) by ismtpd0096p1iad2.sendgrid.net (SG) with ESMTP id XpxlH3LGTa-oe4ZKJ9tvVg for ; Wed, 09 Oct 2019 06:52:46.335 +0000 (UTC) Date: Wed, 09 Oct 2019 06:52:46 +0000 (UTC) From: keithrbennett@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70874 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16244 X-Redmine-Issue-Author: stevendaniels X-Redmine-Sender: keithrbennett X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?hZggMfLzc347l6M=2Fywi6P9NedGi=2F5cN2kxBQ2ASSWgRilgvhRbbMt1bVTwQmtn?= =?us-ascii?Q?XutkA2z4fpbzKD4g9AsKFepOl6Fg4YrFgaJPjzQ?= =?us-ascii?Q?08HGxWfYGM9RRB0pvVzsPuYBcjFQ5Lc5ytHzzpb?= =?us-ascii?Q?WoliqAx8fHQP5bc6=2FdnyCkL9sOZJN7=2Fdht4G5jS?= =?us-ascii?Q?jbAIg63NQWGOG=2FDhrR0cO2bCQIxWtniR0aw=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95287 Subject: [ruby-core:95287] [Ruby master Feature#16244] Add a Time#before? and Time#after? method X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #16244 has been updated by keithrbennett (Keith Bennett). I think the answer to the question 'which is clearer, more obvious, etc.' cannot be answered objectively. Sawa's example is evidence; he sees his preferred expressions as clearer; I find them quite a bit *less* clear. It all depends on how the person is in the habit of thinking. Some people will think of the comparison in terms of mathematical language and would need to mentally transform a 'before' into '<', requiring more effort. Others are the opposite. I will refer to '<' and '>' as the *symbol approach* and *mathematical language*, and 'before' and 'after' as the *word approach* and *natural language*. Here are some arguments on both sides (all have merit for at least some people): 1) Time is like any other scalar value, so the symbol approach is natural, while the word approach makes this less self evident, as words can define relationships far wider than scalar relationships. 2) The symbol approach uses only 1 character and is easier to miss visually. vs. The symbol approach is visually unique and easier to spot than a word. 3) Adding too many aliases to the language degrades the language, requiring more to learn in order to understand preexisting Ruby code; also, using multiple ways to refer to the same thing hides the fact that it is the same thing underneath. vs. Adding certain aliases improves the language, enabling expressing intent more clearly 4) Adding these aliases are a slippery slope; once we add them, will we want to add many more Rails-y aliases? vs. Adding these aliases is not a slippery slope; these are targeted aliases for mathematical symbols and not just alternate human language. ----- Also, Jeremy, I agree with everything you said except that your suggestion to add the aliases oneself only very slightly addresses Steven's need; unless these aliases are part of the language, he's likely to encounter a lot of resistance to using them in a shared code base. ---------------------------------------- Feature #16244: Add a Time#before? and Time#after? method https://bugs.ruby-lang.org/issues/16244#change-81967 * Author: stevendaniels (Steven Daniels) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Comparing times using `>` and`<` can be pretty confusing. I'd like to propose `Time#before?` and `Time#after?` methods for aliasing `Time#<` and `Time#>` These method aliases would make the code more readable. :) Current syntax: ``` ruby if current_time < expiration_at # do stuff end if birthday > thirteen_years_ago # you need a parent's permission to sign up end ``` What I'd like to see added: ``` ruby if current_time.before? expiration_at # do stuff end if birthday.after? thirteen_years_ago # you need a parent's permission to sign up end ``` Thanks for your consideration! -- https://bugs.ruby-lang.org/