Feature #14043
closedIntroduce Process.last_status as an alias for $?
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.
Updated by shevegen (Robert A. Heiler) almost 7 years 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. :)
Updated by normalperson (Eric Wong) almost 7 years 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.
Updated by duerst (Martin Dürst) almost 7 years 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.
Updated by nobu (Nobuyoshi Nakada) almost 7 years ago
I'd prefer something that executes a command and returns Process::Status
, than separate methods.
Updated by ana06 (Ana Maria Martinez Gomez) almost 7 years ago
I completely agree with @mrkn (Kenta Murata). 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!
Updated by shevegen (Robert A. Heiler) over 6 years 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.
Updated by mrkn (Kenta Murata) over 6 years ago
- Target version changed from 2.5 to 2.6
Updated by matz (Yukihiro Matsumoto) over 6 years ago
LGTM.
Matz.
Updated by mrkn (Kenta Murata) over 6 years 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
[ruby-core:83514] [Feature #14043] -
test/ruby/test_process.rb (test_last_status): add a test case for
Process.last_status.