Aliasing
PronunciationAY-lee-uh-sing
Definition
Aliasing happens when two or more names refer to the same object, so a change made through one name is visible through the others.
Where you hear it
In Python and JavaScript debugging, when a list or object changes somewhere you did not touch it.
Examples
b = acreates an alias, not a copy, so adding tobalso changesa.The bug was aliasing: both rows pointed at the same list.
Both variables point to the same list, so appending to one changes the other.
Common mistake
Using [[0] * 3] * 3 to build a grid. It repeats the same row three times; build each row separately.
Don't confuse with
A copy, which is a separate object with its own data.
Say it at work
- In a meeting or chat
That's aliasing: make a copy before changing it.
- In an email or ticket
Passing the list in creates an alias inside the function.
Keep exploring
More in Programming Fundamentals