ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:95260] [Ruby master Feature#16244] Add a Time#before? and Time#after? method
       [not found] <redmine.issue-16244.20191007164739@ruby-lang.org>
@ 2019-10-07 16:47 ` stevendaniels88
  2019-10-07 17:07 ` [ruby-core:95261] " merch-redmine
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: stevendaniels88 @ 2019-10-07 16:47 UTC (permalink / raw)
  To: ruby-core

Issue #16244 has been reported by stevendaniels (Steven Daniels).

----------------------------------------
Feature #16244: Add a Time#before? and Time#after? method
https://bugs.ruby-lang.org/issues/16244

* 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/

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

* [ruby-core:95261] [Ruby master Feature#16244] Add a Time#before? and Time#after? method
       [not found] <redmine.issue-16244.20191007164739@ruby-lang.org>
  2019-10-07 16:47 ` [ruby-core:95260] [Ruby master Feature#16244] Add a Time#before? and Time#after? method stevendaniels88
@ 2019-10-07 17:07 ` merch-redmine
  2019-10-07 19:43 ` [ruby-core:95263] " stevendaniels88
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: merch-redmine @ 2019-10-07 17:07 UTC (permalink / raw)
  To: ruby-core

Issue #16244 has been updated by jeremyevans0 (Jeremy Evans).


stevendaniels (Steven Daniels) wrote:
> Comparing times using `>` and`<` can be pretty confusing.

This is subjective.  I don't find such Time comparisons confusing. I would guess the `>` and `<` symbols are probably more understandable to people whose native language is not English, at least.

> I'd like to propose `Time#before?` and `Time#after?`  methods for aliasing `Time#<` and `Time#>`

The argument you are making for adding them could be made for any objects implementing `>` and `<`.  Maybe your need could be solved with?:

```ruby
module Comparable
  alias before? <
  alias after? >
end
```

One of the great things about Ruby is that it is simple to add these aliases yourself.

----------------------------------------
Feature #16244: Add a Time#before? and Time#after? method
https://bugs.ruby-lang.org/issues/16244#change-81938

* 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/

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

* [ruby-core:95263] [Ruby master Feature#16244] Add a Time#before? and Time#after? method
       [not found] <redmine.issue-16244.20191007164739@ruby-lang.org>
  2019-10-07 16:47 ` [ruby-core:95260] [Ruby master Feature#16244] Add a Time#before? and Time#after? method stevendaniels88
  2019-10-07 17:07 ` [ruby-core:95261] " merch-redmine
@ 2019-10-07 19:43 ` stevendaniels88
  2019-10-07 23:34 ` [ruby-core:95273] " sawadatsuyoshi
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: stevendaniels88 @ 2019-10-07 19:43 UTC (permalink / raw)
  To: ruby-core

Issue #16244 has been updated by stevendaniels (Steven Daniels).


jeremyevans0 (Jeremy Evans) wrote:


> I would guess the `>` and `<` symbols are probably more understandable to people whose native language is not English, at least.

It's hard to speak for all non-native English speakers one way or the other, but in the languages non-English languages I speak, using **greater than** and **less than** to compare times isn't a natural way to frame the comparison; by comparison, before and after is a natural way to compare times in most languages.

Over the years I've seen this confusion manifested by developers of all levels of experience leading to real life bugs. Adding aliases that help to alleviate that confusion would be a nice thing to provide to all Ruby developers (which is why I'm making this feature request).

Subjectively speaking, comparisons like`if blog.published_at.before? Time.now` feel more natural than `if blog.published_at < Time.now`. 

(Big fan of your work, BTW!)


----------------------------------------
Feature #16244: Add a Time#before? and Time#after? method
https://bugs.ruby-lang.org/issues/16244#change-81940

* 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/

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

* [ruby-core:95273] [Ruby master Feature#16244] Add a Time#before? and Time#after? method
       [not found] <redmine.issue-16244.20191007164739@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-10-07 19:43 ` [ruby-core:95263] " stevendaniels88
@ 2019-10-07 23:34 ` sawadatsuyoshi
  2019-10-08 23:26 ` [ruby-core:95284] " stevendaniels88
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: sawadatsuyoshi @ 2019-10-07 23:34 UTC (permalink / raw)
  To: ruby-core

Issue #16244 has been updated by sawa (Tsuyoshi Sawada).


Jeremy Evans is right about this.

But I agree that your second example

```
birthday > thirteen_years_ago
```

is a bit hard to comprehend. However,

```
birthday.after? thirteen_years_ago
```

is as hard to comprehend. You should not be writing like that. You should either do somthing like

```
birthday + thirteen_years > now
```

or

```
now - birthday < thirteen_years
```


----------------------------------------
Feature #16244: Add a Time#before? and Time#after? method
https://bugs.ruby-lang.org/issues/16244#change-81949

* 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/

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

* [ruby-core:95284] [Ruby master Feature#16244] Add a Time#before? and Time#after? method
       [not found] <redmine.issue-16244.20191007164739@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-10-07 23:34 ` [ruby-core:95273] " sawadatsuyoshi
@ 2019-10-08 23:26 ` stevendaniels88
  2019-10-09  6:52 ` [ruby-core:95287] " keithrbennett
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: stevendaniels88 @ 2019-10-08 23:26 UTC (permalink / raw)
  To: ruby-core

Issue #16244 has been updated by stevendaniels (Steven Daniels).


sawa (Tsuyoshi Sawada) wrote:

>You should not be writing like that. You should either do somthing like
> 
> ```
> birthday + thirteen_years > now
> ```
> 
> or
> 
> ```
> now - birthday < thirteen_years
> ```

In your example, your coercing the dates to Floats and then comparing integers. Part of the reason I think `before?`/`after?` would be a good addition is because they remove the need to coerce a `Time` in order to do a comparison. I think your solution illustrates part of the problem

I agree that my example in the beginning isn't perfect. A better example might be this:

```ruby
steven.birthday.before? john.birthday
```

instead of

```ruby
steven.birthday < john.birthday
```

I have a more basic question: are there specific criteria for accepting alias methods for core objects? Is Ruby's preference to avoid adding alias methods? 

----------------------------------------
Feature #16244: Add a Time#before? and Time#after? method
https://bugs.ruby-lang.org/issues/16244#change-81964

* 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/

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

* [ruby-core:95287] [Ruby master Feature#16244] Add a Time#before? and Time#after? method
       [not found] <redmine.issue-16244.20191007164739@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2019-10-08 23:26 ` [ruby-core:95284] " stevendaniels88
@ 2019-10-09  6:52 ` keithrbennett
  2019-12-13 18:30 ` [ruby-core:96221] " anastasia.k.stowers
  2019-12-15  0:59 ` [ruby-core:96241] " nobu
  7 siblings, 0 replies; 8+ messages in thread
From: keithrbennett @ 2019-10-09  6:52 UTC (permalink / raw)
  To: 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/

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

* [ruby-core:96221] [Ruby master Feature#16244] Add a Time#before? and Time#after? method
       [not found] <redmine.issue-16244.20191007164739@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2019-10-09  6:52 ` [ruby-core:95287] " keithrbennett
@ 2019-12-13 18:30 ` anastasia.k.stowers
  2019-12-15  0:59 ` [ruby-core:96241] " nobu
  7 siblings, 0 replies; 8+ messages in thread
From: anastasia.k.stowers @ 2019-12-13 18:30 UTC (permalink / raw)
  To: ruby-core

Issue #16244 has been updated by anastasiastowers (Anastasia Stowers).


Using the > and < symbols makes sense to compare Time only with the knowledge of the underlying unix time system being used.

Although this is the way that we choose to store values of it in our systems, Time is special because it has direction in the way that we perceive it. The words “before” and “after” the only words we use to compare it when considering infinitesimally close event values.

I think the promotion of “natural language” is the direction that Ruby has been going.

Some examples of preferring “natural language”:
https://bugs.ruby-lang.org/issues/12746
https://bugs.ruby-lang.org/issues/13784
https://bugs.ruby-lang.org/issues/14043
https://bugs.ruby-lang.org/issues/14697

----------------------------------------
Feature #16244: Add a Time#before? and Time#after? method
https://bugs.ruby-lang.org/issues/16244#change-83113

* 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/

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

* [ruby-core:96241] [Ruby master Feature#16244] Add a Time#before? and Time#after? method
       [not found] <redmine.issue-16244.20191007164739@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2019-12-13 18:30 ` [ruby-core:96221] " anastasia.k.stowers
@ 2019-12-15  0:59 ` nobu
  7 siblings, 0 replies; 8+ messages in thread
From: nobu @ 2019-12-15  0:59 UTC (permalink / raw)
  To: ruby-core

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


anastasiastowers (Anastasia Stowers) wrote:
> Using the > and < symbols makes sense to compare Time only with the knowledge of the underlying unix time system being used.

I don’t think that knowledge necessary.
Rather, the time is comparable physical quantity.

> Some examples of preferring “natural language”:
> https://bugs.ruby-lang.org/issues/12746
> https://bugs.ruby-lang.org/issues/13784

These are selections of more proper names.

> https://bugs.ruby-lang.org/issues/14043

This is a deprecation of too magical special variables.

> https://bugs.ruby-lang.org/issues/14697

This is opposite, preferring a symbol over “natural language”.

----------------------------------------
Feature #16244: Add a Time#before? and Time#after? method
https://bugs.ruby-lang.org/issues/16244#change-83131

* 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/

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

end of thread, other threads:[~2019-12-15  0:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16244.20191007164739@ruby-lang.org>
2019-10-07 16:47 ` [ruby-core:95260] [Ruby master Feature#16244] Add a Time#before? and Time#after? method stevendaniels88
2019-10-07 17:07 ` [ruby-core:95261] " merch-redmine
2019-10-07 19:43 ` [ruby-core:95263] " stevendaniels88
2019-10-07 23:34 ` [ruby-core:95273] " sawadatsuyoshi
2019-10-08 23:26 ` [ruby-core:95284] " stevendaniels88
2019-10-09  6:52 ` [ruby-core:95287] " keithrbennett
2019-12-13 18:30 ` [ruby-core:96221] " anastasia.k.stowers
2019-12-15  0:59 ` [ruby-core:96241] " nobu

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 read-only IMAP folder(s) and NNTP newsgroup(s).