try/except/finally

Discussion in 'Python' started by Frank B, Jun 6, 2014.

  1. Point is, choose tasteful idioms in your code.


    Marko
     
    Marko Rauhamaa, Jun 10, 2014
    #21
    1. Advertisements

  2. Frank B

    Rustom Mody Guest

    Here is Dijkstra:
    http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html

    First statement:
    | For a number of years I have been familiar with the observation that
    | the quality of programmers is a decreasing function of the density of
    | go to statements in the programs they produce.

    And here is Hoare, not identical to Dijkstra but with similar areas of
    interest and similar views on correctness etc, very unambiguously
    criticising exceptions:

    | Ada has a plethora of features and notational conventions, many of them
    | unnecessary and some of them, like exception handling, even
    | dangerous. Do not allow this language in its present state to be
    | used in applications where reliability is critical

    http://en.wikipedia.org/wiki/Exception_handling#Criticism
     
    Rustom Mody, Jun 10, 2014
    #22
    1. Advertisements

  3. Here is Dijkstra:
    Would be interesting to get their collective take on C++...

    Are there any good parts? It appears the book was cancelled (note the
    remarks):

    https://www.matthewsbooks.com/produ...hcomingtitles.aspx?sort=0&images=1&print=true

    Skip
     
    Skip Montanaro, Jun 10, 2014
    #23
  4. I entirely agree. I find it incredible that some people find it so
    difficult to differentiate having tens or even hundreds of gotos leaping
    around willy nilly to a similar number of labels, and a similar number
    of gotos targetted at one label called SNAFU or whatever.
     
    Mark Lawrence, Jun 10, 2014
    #24
  5. I've seen some amazingly convoluted C code where people got themselves
    wrapped around the axle six different ways in order to avoid using
    "goto fail" or "goto retry". Invariably I was looking at the code
    because it didn't work right and needed to be fixed. Usually the
    addition of a 'fail' label and a few gotos allowed me to throw out all
    sorts of complexly nested if/else blocks, status flags, and
    unnecessary while loops. Usually you can reduce the number of lines
    of code (sometimes by half or more) while also reducing the number and
    nesting of control structures. And when you're done it works right!
     
    Grant Edwards, Jun 10, 2014
    #25
  6. Yeah. As soon as you take on board a hard-and-fast rule, you open
    yourself up to stupid cases where the rule ought to have been broken.
    I don't know a single piece of programming advice which, if taken as
    an inviolate rule, doesn't at some point cause suboptimal code.

    ChrisA
     
    Chris Angelico, Jun 10, 2014
    #26
  7. Frank B

    Roy Smith Guest

    How about, "Don't use PHP"?
     
    Roy Smith, Jun 10, 2014
    #27
  8. Actually, that one might fit now. In years past, that advice would
    often lead you to write very expensive code, because it couldn't be
    run on a cheap web host - if you write something in Python, you have
    to pay through the nose, but any piece-of-rubbish host will give you
    PHP. That may now be changing, though.

    ChrisA
     
    Chris Angelico, Jun 10, 2014
    #28
  9. Frank B

    Ethan Furman Guest

    Sounds like the exception that proves the rule! ;)
     
    Ethan Furman, Jun 10, 2014
    #29
  10. After that one please consider yourself fortunate that the UK, amongst
    other countries, no longer has the death penalty. I guess that The
    Comfy Chair will have to suffice :)
     
    Mark Lawrence, Jun 10, 2014
    #30
  11. "Don't try to program while your cat is sleeping on the keyboard."
     
    Steven D'Aprano, Jun 11, 2014
    #31
  12. Hmm. I've never actually heard that one. Is it commonly taught in
    programming classes? Because I haven't taken any.

    ChrisA
     
    Chris Angelico, Jun 11, 2014
    #32
  13. Frank B

    Roy Smith Guest

    [/QUOTE]

    A picture of a cat sleeping on your keyboard...

    $ ps l
    F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
    0 1010 4768 4660 20 0 5904 352 n_tty_ S+ pts/1 0:00 cat
     
    Roy Smith, Jun 11, 2014
    #33
  14. Frank B

    Tim Delaney Guest

    On 11 June 2014 10:00, Steven D'Aprano <
    Lying down, the weight is spread across the whole keyboard so you're
    unlikely to suffer extra keypresses due to the cat. So if you're a
    touch-typist that one may not be too bad (depending on how easily their fur
    gets up your nose).

    Now, a cat *standing* on the keyboard, between you and the monitor, and
    rubbing his head against your hands, is a whole other matter.

    Tim Delaney
     
    Tim Delaney, Jun 11, 2014
    #34
  15. Does it make any difference if the cat is European or African?
     
    Mark Lawrence, Jun 11, 2014
    #35
  16. What? I don't know..... AAAAAAAAAAAAAAAAAAAAAAAAAAAAARGH!

    ChrisA
     
    Chris Angelico, Jun 11, 2014
    #36
  17. Awfully sorry, it's 2 a.m. here, next time I'll try to remember to
    mention cats from other continents like America, Asia and Antartica.
    Did I get all of them? :)
     
    Mark Lawrence, Jun 11, 2014
    #37
  18. Frank B

    Rustom Mody Guest

    And — if ‘i’≡‘y’ — the author.
     
    Rustom Mody, Jun 11, 2014
    #38
  19. Frank B

    Roy Smith Guest

    My girlfriend's cat is smarter than me!
     
    Roy Smith, Jun 11, 2014
    #39
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.