Project

General

Profile

Feature #14043

Introduce Process.last_status as an alias for $?

Added by mrkn (Kenta Murata) about 1 year ago. Updated 11 months ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:83514]

Description

I found that we don't have any methods for an alias to $?, like MatchData.last_match for $~.

I propose to introduce Process.last_status method for that purpose.

Associated revisions

Revision 8624cec9
Added by mrkn (Kenta Murata) 11 months ago

process.c: add Process.last_status

  • process.c (proc_s_last_status): add Process.last_status
    [Feature #14043]

  • test/ruby/test_process.rb (test_last_status): add a test case for
    Process.last_status.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 61143
Added by mrkn (Kenta Murata) 11 months ago

process.c: add Process.last_status

  • process.c (proc_s_last_status): add Process.last_status
    [Feature #14043]

  • test/ruby/test_process.rb (test_last_status): add a test case for
    Process.last_status.

Revision 61143
Added by mrkn (Kenta Murata) 11 months ago

process.c: add Process.last_status

  • process.c (proc_s_last_status): add Process.last_status
    [Feature #14043]

  • test/ruby/test_process.rb (test_last_status): add a test case for
    Process.last_status.

History

#1 [ruby-core:83521] Updated by shevegen (Robert A. Heiler) about 1 year ago

Would be nice I think. Does not matter so much the name, IMO; the name Process.last_status
is fine but I think any other would do fine too.

My (personal) biggest problem with the short names, such as $? is that they are, for me,
very hard to remember. So I am all up for ways to make it easier to use them so +1 from
me.

It looks as if matz already may have added your proposal to queue for addition. :)

#2 [ruby-core:83530] Updated by normalperson (Eric Wong) about 1 year ago

shevegen@gmail.com wrote:

My (personal) biggest problem with the short names, such as $? is that they are, for me,
very hard to remember. So I am all up for ways to make it easier to use them so +1 from
me.

It's actually easier for me coming from Bourne shell and Perl to use
short names.

We already have English.rb for the $CHILD_STATUS alias, and I'd
rather not force redundant bloat onto all users.

#3 [ruby-core:83533] Updated by duerst (Martin Dürst) about 1 year ago

normalperson (Eric Wong) wrote:

It's actually easier for me coming from Bourne shell and Perl to use
short names.

For some people, yes. But my guess is that these days, most people coming to Ruby have no Perl and little if any shell experience.

We already have English.rb for the $CHILD_STATUS alias, and I'd
rather not force redundant bloat onto all users.

It's true that $? may be easier to write for some people, but last_status should be easy for everybody to read, even for people who see it for the first time.

The general direction in Ruby is to get rid, or at least provide replacements, for cryptic notations. I don't have a reference ready, but I seem to remember that getting rid of some Perl leftovers was one of the things being discussed for Ruby 3.0. Of course input on that direction is welcome.

#4 [ruby-core:83534] Updated by nobu (Nobuyoshi Nakada) about 1 year ago

I'd prefer something that executes a command and returns Process::Status, than separate methods.

#5 [ruby-core:83753] Updated by ana06 (Ana Maria Martinez Gomez) about 1 year ago

I completely agree with @mrkn. How is it possible that a programming language which is described as focussed on simplicity with an elegant syntax that is natural to read and easy to write have this unreadable Perl operators? I am sorry, but there are not readable, neither elegant. And I am pretty sure event Perl developers/people used to the sintax has to check the documentation sometimes to know what that means.

Let's remove them and use the alias in English.rb instead!

#6 [ruby-core:83815] Updated by shevegen (Robert A. Heiler) 12 months ago

I don't want to write too much, but I would suggest more patience from
you, Ana. In particular towards any path forward to the x-mas release,
I assume that bug fixes may have a higher priority than feature
changes/additions. Also note that it is even less likely that anything
can be too easily "removed" in the ruby 2.x branch due to backwards
compatibility.

To the $ variables, while I also said that I have a difficulty
memorizing them, it is not true that they have no use case. For
example, they are short, which is not a bad thing per se necessarily
in ALL situations. To give another example ...

For example:

var =~ /(ab.+)de.+/
$1.to_s.dup

is easy to use for me compared to the variant with MatchData[1]. I always
start like typing =~ and sometimes I write the regex to use in a constant,
and then refer to it such as:

var =~ REGEX_FOR_DISCOVERING_REMOTE_PROGRAMS

Like via open-uri and then finding some matches to remote URLs from a
webpage.

The proposal here and the suggestion is to use a method called
Process.last_status which I think is a perfectly fine proposal. Nowhere
does the issue request speak about removing $ variables so I am
confused about comments such as "Let's remove them".

The scope here is simply to add a method as alternative means to
access $?, which I think is a perfectly fine proposal in itself.

The rest is up to the ruby core team and matz.

#7 Updated by mrkn (Kenta Murata) 12 months ago

  • Target version changed from 2.5 to 2.6

#9 Updated by mrkn (Kenta Murata) 11 months ago

  • Status changed from Open to Closed

Applied in changeset trunk|r61143.


process.c: add Process.last_status

  • process.c (proc_s_last_status): add Process.last_status
    [Feature #14043]

  • test/ruby/test_process.rb (test_last_status): add a test case for
    Process.last_status.

Also available in: Atom PDF