Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNicholas Gaerlan
9,501 PointsWhy bother with pointers?
I remember learning C++ a long time ago and thinking that pointers were a normal thing, but then after learning Python and some JS, I wonder why bother with pointers at all? It seems like it would be better to declare a global variable, or offer a way to access another objects' parameter through dot notation. Also, is garbage collection somehow easier when you use pointers? Just wondering why a modern language like Go would choose to keep this.
2 Answers
Steven Parker
231,268 PointsLanguages have different features, and it's nearly always possible to compensate for missing features using other techniques with a bit of extra code, time and memory. But pointers tie directly into underlying hardware operations and make it possible for code to be very efficient in terms of memory and execution-time, which are among the original objectives of the development of the Go language.
But even though Go has pointers, the implementation is somewhat simplified compared to languages like C++. Go has no pointer arithmetic features, for example.
And I don't believe having pointers is related to having garbage collection.
Andrew Calhoun
19,360 PointsI know this thread is a bit older, but pointers are by and large a relic from a period when we needed to be economical with data and literally point to an address in the memory. They're useful for embedded programming and small devices with limited memory and processing power.
We also use them in graphics and games, to help make things more efficient.
For most high level languages, pointers are handled by a wrapper within the language itself, so that we don't necessarily need to worry about it. It is still a good skill to at least develop a familiarity with, because of the intricacies of memory management.