Skip to main content
added 51 characters in body; added 119 characters in body
Source Link
BoppreH
  • 1.4k
  • 5
  • 23

Many languages prioritize runtime safety by forcing users to handle (or annotate) the error cases for operations that can fail.

This works well for I/O and complex algorithms, but how should common fallible operations, like division and array access, be handled? Every a / b can technically fail if b is zero, and every list[index] can fail if index is out of range. 

However, those operations are far too widespread to surround each instance with explicitcumbersome error handling, or annotating with "can throw division by zero".

How can a general-purpose programming language have this sort of operation without creating too much boilerplate for users, and without giving up safety with runtime panics?

Bonus points if the solution is usable for integer overflow, since it includes almost all arithmetic operations.

Many languages prioritize runtime safety by forcing users to handle (or annotate) the error cases for operations that can fail.

This works well for I/O and complex algorithms, but how should common fallible operations, like division and array access, be handled? Every a / b can technically fail if b is zero, and every list[index] can fail if index is out of range. However, those operations are far too widespread to surround each instance with explicit error handling.

How can a general-purpose programming language have this sort of operation without creating too much boilerplate for users, and without giving up safety with runtime panics?

Many languages prioritize runtime safety by forcing users to handle (or annotate) the error cases for operations that can fail.

This works well for I/O and complex algorithms, but how should common fallible operations, like division and array access, be handled? Every a / b can technically fail if b is zero, and every list[index] can fail if index is out of range. 

However, those operations are far too widespread to surround each instance with cumbersome error handling, or annotating with "can throw division by zero".

How can a general-purpose programming language have this sort of operation without creating too much boilerplate for users, and without giving up safety with runtime panics?

Bonus points if the solution is usable for integer overflow, since it includes almost all arithmetic operations.

Source Link
BoppreH
  • 1.4k
  • 5
  • 23

In a language with explicit error handling, how to reduce boilerplate for common fallible operations?

Many languages prioritize runtime safety by forcing users to handle (or annotate) the error cases for operations that can fail.

This works well for I/O and complex algorithms, but how should common fallible operations, like division and array access, be handled? Every a / b can technically fail if b is zero, and every list[index] can fail if index is out of range. However, those operations are far too widespread to surround each instance with explicit error handling.

How can a general-purpose programming language have this sort of operation without creating too much boilerplate for users, and without giving up safety with runtime panics?