Programing Language Design: Reference Considered Harmful

By Xah Lee. Date: . Last updated: .

The Problem of the Reference Concept in Programing Languages

the problem with reference is that it creates complexities.

when you assign a list to a variable,

xx = [1,2,3]

normally you think that [1,2,3] is the value of the variable.

actually, the value of the variable is a value called the “reference”, typically an “memory addresss”, which refers to the value [1,2,3].

most of the time, this complexity is hidden, you don't have to worry about it.

the problem appear, when you assign the variable to another variable, then you got a mysterious situation of changing one variable's value changes the other. (technically because they share the same “reference”)

xx = [1, 2, 3]

# copy it to yy
yy = xx

# change the xx
xx[0] = 99

# now yy also changed
print(yy)
# [99, 2, 3]

so, it creates the concept of so-called “clone”, meaning, independent copy.

the problem gets worse, when you have a nested list.

xx = [0, 1]
yy = ["a","b"]

xx.append(yy)

print(xx)
# [0, 1, ['a', 'b']]

yy[0] = 99

print(xx)
# [0, 1, [99, 'b']]

Programing Languages Sans Reference Problem

Why Pointer and Reference Are the Most Harmful

Why pointer and reference are the most harmful idea in the progress of programing languages.

vidthumb ChYNKNrRbbA