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/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>