ISF Logo   IS Forum
Forum Index Register Members List Events Mark Forums Read Help

Go Back   International Skeptics Forum » General Topics » Computers and the Internet
 


Welcome to the International Skeptics Forum, where we discuss skepticism, critical thinking, the paranormal and science in a friendly but lively way. You are currently viewing the forum as a guest, which means you are missing out on discussing matters that are of interest to you. Please consider registering so you can gain full use of the forum features and interact with other Members. Registration is simple, fast and free! Click here to register today.
Reply
Old 25th February 2020, 09:43 AM   #41
jeremyp
Graduate Poster
 
Join Date: Aug 2003
Location: ZZ9 Plural Z Alpha
Posts: 1,077
[quote=grmcdorman;13000274]That's only roughly 50% of the off-by-one errors

Yes but in this particular case we are trying to access the third item in a two item container.

Quote:
, and for the other 50% only those where it's an index into an array or other bounded entity. And any reasonable language doesn't abort on an out-of-bounds index.
I don't know of any high level language that doesn't perform some equivalent to aborting except C and its derivates that support C arrays (like C++ and Objective-C).

There's no other reasonable option than to abort. Yes , a Java program (for example) actually throws an exception that can be caught, but that is probably a bad idea because it signifies an error on the part of the programmer. Their assumptions are incorrect, so anything can go wrong.
jeremyp is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 25th February 2020, 11:10 AM   #42
CORed
Philosopher
 
Join Date: Dec 2008
Location: Central City, Colorado, USA
Posts: 9,256
Originally Posted by jeremyp View Post
That's the trouble with C. In any reasonable language, it would go

There are 2 hard problems with computers: caching, naming things and
Code:
INDEX OUT OF RANGE ERROR. ABORT CORE DUMPED.
Coincidentally, I spent the whole of last week trying to diagnose an intermittent problem with our internal time recording system. It turned out that one of its two DNS servers didn't know how to resolve the name of the active directory server.
Some of my earliest ventures into programming were in C on DOS PC's. Programming errors that resulted in reading or writing past the end of an array could be quite interesting, because, in that environment, there was no bounds checking whatsoever. Your program could read or write to any address. A common result of an error that caused a loop to run past the end of an array and display to the screen would be a whole lot of garbage characters with MICROSOFT CORPORATION embedded somewhere in the middle of it. Writing out of bounds often caused a crash or hang that required a three finger salute (Control-alt-delete), which in DOS, triggered an immediate restart, unless you managed to hang it so badly that only the reset button or power switch would fix it.
CORed is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 25th February 2020, 04:36 PM   #43
grmcdorman
Graduate Poster
 
Join Date: Mar 2007
Posts: 1,281
[quote=jeremyp;13000984]
Originally Posted by grmcdorman View Post
That's only roughly 50% of the off-by-one errors

Yes but in this particular case we are trying to access the third item in a two item container.
I was speaking of the general case.
Quote:
I don't know of any high level language that doesn't perform some equivalent to aborting except C and its derivates that support C arrays (like C++ and Objective-C).
C#, Python both throw exceptions. VB, I believe, has a number of ways to intercept the error. JavaScript (and, I believe TypeScript) don't report any sort of error, they return "undefined" (mind you, arrays in JavaScript are weird anyway).

Not sure about modern FORTRAN and COBOL. The original implementations didn't have anything except an abort, but that was in the Dark Ages of computer science.

The majority of modern languages provide mechanism for intercepting errors, including out of bounds.
Quote:
There's no other reasonable option than to abort. Yes , a Java program (for example) actually throws an exception that can be caught, but that is probably a bad idea because it signifies an error on the part of the programmer. Their assumptions are incorrect, so anything can go wrong.
The point to an exception - or other mechanism to intercept the error - is that it may be necessary to clean up before the program terminates. An abrupt, uncontrolled termination can leave resources - files, for example - in an invalid or even corrupted state. Likewise for things like locks.

Yes, the only reasonable thing may be to eventually terminate the program - but an uncontrolled, and unavoidable, abort is rarely a good idea. Logging details about the context of the error and cleaning up really helps diagnosing the issue when it happens.

Mind you, developers can misuse the ability to catch these errors, notably empty 'catch' blocks in languages with exceptions and 'ON ERROR RESUME NEXT' in VB.

In very rare cases, the fault is in code the developer can't change or doesn't have access to, but it is necessary to gracefully catch the failure and continue. Again, an unconditional abort is not a useful solution here.

Having said all of that, again in most languages, if you don't catch the error it will terminate your program. You have the choice.
__________________
"Hello. My name is Inigo Skywalker. You are my father. Prepare to die."
grmcdorman is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 1st March 2020, 11:43 AM   #44
jeremyp
Graduate Poster
 
Join Date: Aug 2003
Location: ZZ9 Plural Z Alpha
Posts: 1,077
Originally Posted by grmcdorman View Post
Originally Posted by jeremyp View Post
I was speaking of the general case.
My post to which you were replying was not talking about the general case.

Quote:
The point to an exception - or other mechanism to intercept the error - is that it may be necessary to clean up before the program terminates. An abrupt, uncontrolled termination can leave resources - files, for example - in an invalid or even corrupted state. Likewise for things like locks.
The trouble with index out of bounds is that it is a programming error. The programmer has made an invalid assumption, which means that the state of the program is pretty much undefined. The damage to your file or data or whatever may already have been done. It's better to use external mechanisms like ACID compliant files which have the advantage of being resilient to classes of issues that cannot be handled with exceptions e.g. power outages or the OS just killing your program.

[quoe]
In very rare cases, the fault is in code the developer can't change or doesn't have access to, but it is necessary to gracefully catch the failure and continue. Again, an unconditional abort is not a useful solution here.
Neither is any other course of action. If third party code has thrown what in Java terms is an unchecked exception i.e. one that doesn't have to be explicitly handled or explicitly passed up the stack, you are screwed.

Quote:
Having said all of that, again in most languages, if you don't catch the error it will terminate your program. You have the choice.
My main point is that people seem to think that exceptions make everything better but the problem is that they get complacent. A null pointer exception stack trace is just as serious as a sig abort (and gives less diagnostic information, if core dumps are enabled). The fact that the program was somehow able to carry on is bad news because it might encourage people to ignore the programming error that caused it.
jeremyp is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Reply

International Skeptics Forum » General Topics » Computers and the Internet

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 06:32 AM.
Powered by vBulletin. Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum began as part of the James Randi Education Foundation (JREF). However, the forum now exists as
an independent entity with no affiliation with or endorsement by the JREF, including the section in reference to "JREF" topics.

Disclaimer: Messages posted in the Forum are solely the opinion of their authors.