[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Interest check in some delicious syntactic sugar for "except:pass"

Oren Elrad

3/3/2010 9:27:00 AM

Howdy all, longtime appreciative user, first time mailer-inner.

I'm wondering if there is any support (tepid better than none) for the
following syntactic sugar:

silence:
......... block

------------------------->

try:
.........block
except:
.........pass

The logic here is that there are a ton of "except: pass" statements[1]
floating around in code that do not need to be there. Meanwhile, the
potential keyword 'silence' does not appear to be in significant use
as a variable[2], or an alternative keyword might be imagined
('quiet', 'hush', 'stfu') but I somewhat like the verbiness of
'silence' since that is precisely what it does to the block (that is,
you have to inflect it as a verb, not a noun -- you are telling the
block to be silent). Finally, since this is the purest form of
syntactic sugar, I cannot fathom any parsing, interpreting or other
complications that would arise.

I appreciate any feedback, including frank statements that you'd
rather not trifle with such nonsense.

~Oren

[1] http://www.google.com/codesearch?q...\spass&hl=en
[2] http://www.google.com/codesearch?hl=en&lr=&q=silence...
4 Answers

Lie Ryan

3/3/2010 1:20:00 PM

0

On 03/03/2010 08:27 PM, Oren Elrad wrote:
> Howdy all, longtime appreciative user, first time mailer-inner.
>
> I'm wondering if there is any support (tepid better than none) for the
> following syntactic sugar:
>
> silence:
> ......... block
>
> ------------------------->
>
> try:
> .........block
> except:
> .........pass
>
> The logic here is that there are a ton of "except: pass" statements[1]
> floating around in code that do not need to be there. Meanwhile, the
> potential keyword 'silence' does not appear to be in significant use
> as a variable[2], or an alternative keyword might be imagined
> ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of
> 'silence' since that is precisely what it does to the block (that is,
> you have to inflect it as a verb, not a noun -- you are telling the
> block to be silent). Finally, since this is the purest form of
> syntactic sugar, I cannot fathom any parsing, interpreting or other
> complications that would arise.

Given that python HATE bare-except (and `pass`-block bare except is even
worse) and given python's idiosyncrasies "There should be one-- and
preferably only one --obvious way to do it", "Errors should never pass
silently"; the chance for `silence` keyword is precisely zero.

> I appreciate any feedback, including frank statements that you'd
> rather not trifle with such nonsense.

There are lots of reason why bare-except is bad, one being is that it
makes it way too easy to ignore errors that you don't actually want to
silence; and given that bare-excepts would prevent Ctrl+C (Interrupt)
from working. Sorry, but IMHO we shouldn't make syntax sugar for bad
practices.

Ben Finney

3/3/2010 10:22:00 PM

0

Lie Ryan <lie.1296@gmail.com> writes:

> There are lots of reason why bare-except is bad, one being is that it
> makes it way too easy to ignore errors that you don't actually want to
> silence; and given that bare-excepts would prevent Ctrl+C (Interrupt)
> from working. Sorry, but IMHO we shouldn't make syntax sugar for bad
> practices.

Right. Another way I've seen this expressed is â??It should be easy to
do the right thing, and awkward to do the wrong thing�.

--
\ â??Everyone is entitled to their own opinions, but they are not |
`\ entitled to their own facts.â? â??US Senator Pat Moynihan |
_o__) |
Ben Finney

Rhodri James

3/4/2010 12:11:00 AM

0

On Wed, 03 Mar 2010 09:27:16 -0000, Oren Elrad <orenelrad@gmail.com> wrote:

> Howdy all, longtime appreciative user, first time mailer-inner.
> I'm wondering if there is any support (tepid better than none) for the
> following syntactic sugar:
> silence:
> ........ block
> ------------------------->
> try:
> ........block
> except:
> ........pass

-100

This catches Control-C interrupts, sys.exit(), subtle typos in the code,
and sundry other errors that actually you *did* want to know about.
Silence isn't so much golden as pyritic.

--
Rhodri James *-* Wildebeeste Herder to the Masses

Bruno Desthuilliers

3/4/2010 11:59:00 AM

0

Oren Elrad a écrit :
> Howdy all, longtime appreciative user, first time mailer-inner.
>
> I'm wondering if there is any support (tepid better than none) for the
> following syntactic sugar:
>
> silence:
> ........ block
>
> ------------------------->
>
> try:
> ........block
> except:
> ........pass
>

Hopefully not.

> The logic here is that there are a ton of "except: pass" statements[1]
> floating around in code that do not need to be there.

s/do not need to be/NEVER should have been at first/