Project

General

Profile

Actions

Feature #21082

open

Alias it to its

Added by northeastprince (Matt Almeida) 3 days ago. Updated 2 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:120747]

Description

One of Ruby's core tenants is beautiful code - and a key part of that is sweating the names. Adding it as a pointer to the first block parameter was a huge step forward in that regard, but we're not done yet. If [1, 2, 3].each { puts it } works, posts.each { puts its.title } should work too.

Actions #1

Updated by northeastprince (Matt Almeida) 3 days ago

  • Description updated (diff)

Updated by duerst (Martin Dürst) 2 days ago

northeastprince (Matt Almeida) wrote:

One of Ruby's core tenants is beautiful code - and a key part of that is sweating the names. Adding it as a pointer to the first block parameter was a huge step forward in that regard, but we're not done yet. If [1, 2, 3].each { puts it } works, posts.each { puts its.title } should work too.

I propose we reject this. First, we have only just recently introduced it. It (sic!) definitely makes sense to wait and get experience with it before we add a variant.

Second, Ruby has up to now rejected grammatical inflections such as includes instead of include.

Third, if we accept a possessive ending, we would have to do it in general. posts.each { |post| puts post's.title } (or some such, we'd have to figure out a solution for the apostrophe, maybe just leave it out).

Fourth, in something.title, the period already indicates a possessive relation in many cases, in particular if the following method name is read as a noun. Adding the s would lead to something like a double possessive ("the title of of it", so to say).

Fifth, the use of s endings in variable names in programming languages is mostly associated with plural (element: single element; elements: array or hash of elements), much more so than in English, where a final 's' can indicate a third person singular in a verb, a plural in a noun, or a possessive (usually with an apostrophe). So when I first saw its in the example, I was actually thinking about an operation on an array, despite the fact that the plural of 'it' in English is of course 'they', not 'its'.

In conclusion, let's reject this.

Updated by northeastprince (Matt Almeida) 2 days ago

Hey Martin! Thanks for your input.

It seems like there's a very small amount of core method names that would have such a level of linguistic dissonance based on the receiver. However, even something like ledger.include? transaction seems more adaptive than it.title, though that might just be me.

Happy to let it sit for a while before any changes are considered 😆.

Updated by Earlopain (Earlopain _) 2 days ago

Second, Ruby has up to now rejected grammatical inflections such as includes instead of include.

File.exists? was even removed.

Many methods could do with a alias that reads nicer in certain situations. For example, posts.each { put its.title } looks even better to me but where do you stop?

Actions

Also available in: Atom PDF

Like0
Like0Like1Like0Like0