what a cheap rule

Discussion in 'Python' started by Yingjie Lan, Nov 25, 2010.

  1. Yingjie Lan

    Yingjie Lan Guest

    Sometimes the golden rule in Python of
    "explicit is better than implicit" is
    so cheap that it can be thrown away
    for the trouble of typing an empty tuple.

    Today when I am explaining that in Python 3,
    there are two ways to raise exceptions:

    raise Exception

    raise Exception()

    and that the first one is the same
    as the second one, as Python will add the
    missing pair of parenthesis.

    I felt their pain as they gasped.
    Before that, I have already explained
    to them this piece of code:

    try: raise SomeException()
    except SomeException:
    print('Got an exception here')

    by saying that the except-clause
    will match anything
    that belong to the SomeException class.

    Without knowing this secrete
    piece of information (that a
    pair of parenthesis is automatically
    provided), the following code
    would be hard to understand:

    try: raise SomeException
    except SomeException:
    print('Got an exception here')

    because the class object SomeException
    is not an instance of itself, so
    a not-so-crooked coder will not
    consider a match here.

    So, the explicit is better than
    implicit rule is thrown out of
    the window so cheaply,
    that it literally worth less
    than an empty tuple!

    Regards,

    Yingjie
    Yingjie Lan, Nov 25, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. NoSpamThanks

    Where to find a cheap image lib

    NoSpamThanks, Oct 27, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    289
    NoSpamThanks
    Oct 27, 2003
  2. zZ

    Re: Cheap ASP servers

    zZ, Nov 6, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    341
  3. Sean Dwyer

    Re: Cheap ASP servers

    Sean Dwyer, Nov 7, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    381
    Sean Dwyer
    Nov 7, 2003
  4. Jow Blow
    Replies:
    6
    Views:
    296
    Jan Tielens
    Feb 23, 2004
  5. Replies:
    0
    Views:
    1,356
Loading...

Share This Page