Neku's Blog

Why Do Even We Need Pointer?

So why do we even need these strange * and & symbols? Why not just pass the object to the parameter? It's so confusing... =_=

That’s what I thought when I used Golang for the first time.

Modern software engineering embraces immutability.

Immutable types are safer from bugs, easier to understand, and more ready for change. Mutability makes it harder to understand what your program is doing, and much harder to enforce contracts. — MIT's course on Software Construction

And Go gives us the option to choose between value and pointer parameter types because of this. Simply put, by using a pointer, we can say “Hey, this variable is modifiable.”

So... back to the question: why do we need pointers? The answer is: to indicate that something is mutable, make it safer, and make it easier for developers.