[ruby-core:63986] [ruby-trunk - Bug #10042] Deprecate postfix rescue syntax for removal in 3.0

From: sowieso@...
Date: 2014-07-23 18:20:43 UTC
List: ruby-core #63986
Issue #10042 has been updated by So Wieso.


Hi, I'm against it :-)
Nobody is forced to use it, and for short scripts it can be quite useful.
For example to fetch some websites, if they exist:
`
require 'open-uri'
urls =3D =E2=80=A6
urls.each do |url|
  open(url) do
    #save the file
  end rescue nil
end
`
But it would be ok for me if we need to specify the Exception.


----------------------------------------
Bug #10042: Deprecate postfix rescue syntax for removal in 3.0
https://bugs.ruby-lang.org/issues/10042#change-48004

* Author: Charles Nutter
* Status: Open
* Priority: Normal
* Assignee:=20
* Category: core
* Target version: next minor
* ruby -v: 2.1 something
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
The postfix rescue notation is convenient...but almost always is a really b=
ad antipattern.

An example of the notation:

    Integer(f) rescue f # returns f if it is not parseable as an Integer

It silently ignores all StandardError raised by a piece of code...which oft=
en covers *many* more exceptions than the user *wants* to be ignoring.

It also hides the cost of constructing and throwing away all those ignored =
exceptions.

I believe Matz has even said in the past that he regrets adding the feature.

In any case, I propose that "rescue nil" should be deprecated with a warnin=
g (either always on or only when verbose) and we should plan to remove it i=
n 3.0.

Who's with me?!



--=20
https://bugs.ruby-lang.org/

In This Thread

Prev Next