try/except/finally


Ad

Advertisements

R

Rustom Mody

Am 08.06.2014 05:58 schrieb Rustom Mody:
And became widely misunderstood. If anybody would read the whole what he
wrote, people would learn that he doesn't criticise the *use* of goto,
but he wants the *replacement* of goto with something else (like
exceptions).
As C doesn't have exceptions, goto is in many cases the simplest and
easiest way of handling errors.
Essentially, you can write both good and bad code both with and without
goto.

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
 
S

Skip Montanaro

Here is Dijkstra:
| 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.

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
 
M

Mark Lawrence

Am 08.06.2014 05:58 schrieb Rustom Mody:


And became widely misunderstood. If anybody would read the whole what he
wrote, people would learn that he doesn't criticise the *use* of goto,
but he wants the *replacement* of goto with something else (like
exceptions).

As C doesn't have exceptions, goto is in many cases the simplest and
easiest way of handling errors.

Essentially, you can write both good and bad code both with and without
goto.

Thomaas

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.
 
G

Grant Edwards

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.

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!
 
C

Chris Angelico

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!

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
 
Ad

Advertisements

R

Roy Smith

Chris Angelico said:
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.

How about, "Don't use PHP"?
 
C

Chris Angelico

How about, "Don't use PHP"?

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
 
M

Mark Lawrence

Sounds like the exception that proves the rule! ;)

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 :)
 
S

Steven D'Aprano

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.

"Don't try to program while your cat is sleeping on the keyboard."
 
Ad

Advertisements

C

Chris Angelico

"Don't try to program while your cat is sleeping on the keyboard."

Hmm. I've never actually heard that one. Is it commonly taught in
programming classes? Because I haven't taken any.

ChrisA
 
R

Roy Smith

"Don't try to program while your cat is sleeping on the keyboard."
[/QUOTE]

Hmm. I've never actually heard that one. Is it commonly taught in
programming classes? Because I haven't taken any.

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
 
T

Tim Delaney

On 11 June 2014 10:00, Steven D'Aprano <[email protected]
"Don't try to program while your cat is sleeping on the keyboard."

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
 
M

Mark Lawrence

On 11 June 2014 10:00, Steven D'Aprano
<[email protected]



"Don't try to program while your cat is sleeping on the keyboard."


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

Does it make any difference if the cat is European or African?
 
Ad

Advertisements

M

Mark Lawrence

What? I don't know..... AAAAAAAAAAAAAAAAAAAAAAAAAAAAARGH!

ChrisA

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? :)
 
Ad

Advertisements

Ad

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. After that, you can post your question and our members will help you out.

Ask a Question

Top