What language features eliminate a whole class of errors?

340 Views Asked by At

I have often seen claims that a programming language feature eliminates a whole class of errors.

For example, I have seen claims that:

  • A strong type system eliminates the class of errors caused by using features that a type does not support.

  • Automatic memory management eliminates the class of errors relating to allocating the correct amount of memory for an object/structure.

  • Mandatory variable initialisation eliminates null pointer or null reference errors.

  • Immutable data structures eliminate the class of errors caused by not understanding the impacts of changing mutable state.

I am not trying to find out whether the claims above are true or not, but rather compile a list of claims of this type that are specific enough for me to research and evaluate myself.

What other specific features are alleged to eliminate a whole class of errors?

Is there a general principle or theory for identifying features that do this, or identifying the absence of such features?

(Note that I do not include obviously vague or subjective claims like these, whether true or not:

  • Object oriented programming improves reusability.

  • Dynamic languages are faster to program in.

  • Meaningful whitespace makes the program cleaner. )

3

There are 3 best solutions below

1
On BEST ANSWER

Here are a few off the top of my head:

Class                 Feature                             Example
Type Error            Single Data Type                    awk
Type Mismatch         Union Types                         XQuery
Reference Error       No Variables                        sed
Mismatched Braces     No Braces                           python
Dangling semicolon    Significant Whitespace              python
Buffer Overflow       No Pointer Arithmetic               Ada
Division by Zero      Default to infinity                 lua
Circular Reference    All values are immutable strings    tcl
Circular Import       No Cyclical Dependencies            OCaml
Ambiguous Type        Hindley-Milner type inference       OCaml
Not enough args       Partial Application                 Haxe
Import Error          Implicit Standard Library           Coldfusion
Leaky Abstraction     No Conditional Logic                CSS
Object Expected       Everything is an object             SmallTalk
No such method        Reification                         SmallTalk
Infinite Loop         No Side Effects                     DSSSL
Deadlock              Software Transaction Memory         Clojure
Namespace Conflict    Stack Save/Restore                  PostScript
Invalid arguments     Stack Machine                       PostScript
Heisenbug             Message Passing Concurrency         Erlang
0
On

Immutability

Concurrency

Immutability reduces all shared data issues in a concurrent system. Concurrency and Caching are two of the hardest things to get correct, and most people get it wrong the first few dozens of times they try to write code of either type.

Side Effects

Immutability also makes code deterministic, inputs to functions can never change during the scope of the function, for either inside or outside the function, this means there are no side effects.

Non-Null values

Most systems that support immutability as the only type of variable also don't have the concept of Null, either references are assigned or they aren't, if they aren't the compiler complains and you have to fix it.

In Java liberal use of final references and @Nonnull annotations on parameters and return values eliminate almost all non-logic based errors or shows them as they are at compile time or very early in runtime

8
On

Optional types eliminate null pointer exceptions. The type forces you to check for the possibility of an empty value.

Most general programming languages have an optional type of some form. Maybe in Haskell, Option in OCaml, Optional generic type in Java.