Project

General

Profile

Actions

Feature #15741

closed

Ordinal parameters

Added by mame (Yusuke Endoh) over 5 years ago. Updated over 5 years ago.

Status:
Rejected
Assignee:
-
Target version:
[ruby-core:92067]

Description

Numbered parameters have been introduced into trunk, and are still being hotly debated in #15723.

One of the problems of the feature is, too short, too symbolic, and then too cryptic. It resembles Perl.

I counterpropose "ordinal parameters":

$ ./miniruby -e '
[ [1, 1, 1], [2, 2, 2], [3, 3, 3] ].each { p 0th * 1st * 2rd }
'
1
8
27

Ordinal parameters are much better than numbered parameters in two points:

  • It is English. No symbol is used. It looks nicer, doesn't it?
  • Some people are complaining that @1 is one-based. Instead, my proposal is zero-based: it starts with 0th.

In other words, it no longer resembles the notorious $1 at all.

You may wonder if it is too friendly for English speakers. Don't worry, it is carefully designed:

  • It is tolerant of small errors. In fact, "2rd" (not "2nd") is allowed. This is because I often typo.
  • Even "1th", "2th", and "3th" are allowed. Non-English-native programmers don't have to learn the difference among "st", "nd", "rd", and "th".

A patch is attached.


Files

ordinal-parameters.patch (1.62 KB) ordinal-parameters.patch mame (Yusuke Endoh), 03/31/2019 11:52 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #12240: circle number argumentsRejectedActions

Updated by sawa (Tsuyoshi Sawada) over 5 years ago

I do not think that 1-based is a problem at all. As some have already noticed in a different thread, regex captures are 1-based, and no one has complained about it. I think it is more natural to have it 1-based.

Actions #2

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

Updated by shevegen (Robert A. Heiler) over 5 years ago

Check the date sawa. :)

The thing is, though ... if we ignore the date (and I guess nobu is having fun
since it may seem less obvious if mame creates the issue ;) ) ... actually I did
want to propose adding .second .third and so forth, since we have .first and .last
already. Not to block-parameters, but in general available for where we already
use .first and last. But I was not completely sure about whether it is that
needed/necessary, and possibly it was already suggested before.

The reason why I did want to suggest it was mostly for code like this:

some_array = [] # it gets filled up with data

person_name   = some_array.first
person_height = some_array[1]
person_age    = some_array.last

Now for the moment let's ignore that a Hash would be better for this,
it is just meant for illustration purpose. My argument would be that
[1] looks strange when I already use .first and .last, so I wanted
to use .second instead.

However had ... my use case is not that good nonetheless. It's just
mostly a visual thing ... when I use [0], [1], [2] then this looks
fine; and when I use .first and .last this looks fine too. It only
looked strange when I would mix both.

Another problem was that, for example, how often would people use
something like .fifth? Or .sixth? Probably not that often. So I
sort of abandoned that ideal for a proposal.

I did, however had, also want to suggest another one on this first
april, aka to suggest a compiled variant of ruby. And while 95% of
this would have been meant as a joke, 5% would have been serious.

I twould not have to be ruby exactly, but just a compiled language,
a bit like the ruby-crystal situation (but matz would design it;
but no worries, even in my joke suggestion, I would not suggest
that matz would IMPLEMENT it - it was only meant for the design
stage). And probably a full alternative to C too. One reason here
was that many casual or less formal users do not know C yet the
really cool things all seem to happen in/through C.

Updated by sawa (Tsuyoshi Sawada) over 5 years ago

shevegen (Robert A. Heiler) wrote:

Check the date sawa. :)

I see. Honestly, I have never felt this kind of stuff to be funny.

Updated by ioquatix (Samuel Williams) over 5 years ago

You make localisation a problem of the language syntax. For example, in the original code: 2rd is actually not correct, it should be 2nd. Other localisations are even more complicated, e.g. Russian.

Updated by Eregon (Benoit Daloze) over 5 years ago

  • Assignee set to 10790

Updated by mame (Yusuke Endoh) over 5 years ago

  • Status changed from Open to Rejected

I forgot to close this ticket. Thanks.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0