4 ms·
Programmer for 8 years, in a wide variaty of languages but never touched a language that had pointers. How much do I need to know about pointers to use and lea
by sergiotapia 14y ago
Programmer for 8 years, in a wide variaty of languages but never touched a language that had pointers.
How much do I need to know about pointers to use and learn Go? Is Go garbage collected in the C#/Ruby sense?
I recently switched from full ORM usage to hand tuned SQL queries and loved watching the speed of my application increase 10-fold. I'm having a bit of a speed high and Go seems like the perfect language for this.
What book should I buy to learn Go from the ground up?
Edit:This seems like the perfect place to start.
http://www.golang-book.com/ http://www.golang-book.com/
- voidlogic 14y ago>>How much do I need to know about pointers to use and learn Go? Do you understand how they work in C? Maybe try reading a little about that. For Go, I'd recommend starting here: http://tour.golang.org/#1 http://tour.golang.org/#1 (Don't miss the next arrow in the lower right-) After running through that you should have an idea of what you don't know- which makes asking questions people can provide useful answers to much easier. :) >>Is Go garbage collected in the C#/Ruby sense? I'm not sure what your sense of C#/Ruby GC is, but I'd go with yes.
- city41 14y agoPointers are not difficult. Take what you know about references as a starting point and go from there. In many cases, references and pointers behave very similar. When you get into the more interesting things that are possible with pointers, just remember they are merely a value that holds a memory address. If you keep that in mind, the complexity is muted a lot. Just dig into Go and see what you find.
- genwin 14y agoI concur with this approach. My former languages do not have pointers either. It is refreshing to have them as an option, and they are not difficult to get used to.
- coldtea 14y ago>How much do I need to know about pointers to use and learn Go? Very little. Just what pass by value and pass by reference mean in the context of pointers. The very basic you need to know is: if a function argument is defined as (*foo), you are changing the item you pass to the function (like in Javascript or Java), whereas if it's defined as (foo), you're changing a copy of it and the original item remains unaffected. Go has pointers, but no pointer arithmetic (in the base language), and it also has GC, so most of the problems people have with pointers in C are not there.
- sergiotapia 14y ago>The very basic you need to know is: if a function argument is defined as (*foo), you are changing the item you pass to the function (like in Javascript or Java), whereas if it's defined as (foo), you're changing a copy of it and the original item remains unaffected. ============================= So it's like PHP where I need to pass in `function modify(&$foo) {` to modify a variable passed by reference.
- coldtea 14y agoYes, not sure for the whole PHP semantics on this, but it's a little like that.
- dnm 14y agoIt's also a performance boost when you're passing something non-trivial, to pass just the pointer, rather than have Go make a copy of whatever you're passing by value.
- chrisguitarguy 14y ago> So it's like PHP where I need to pass in `function modify(&$foo) {` to modify a variable passed by reference. If you're thinking in terms of PHP's primitive types, then yes: that's probably the best equivalent. PHP has the whole objects always being "passed by reference" [0] thing going on too. 0. http://php.net/manual/en/language.oop5.references.php http://php.net/manual/en/language.oop5.references.php
- 14y ago
- optimusclimb 14y agoIf it's been 8 years, it's about time :) ... Do yourself a favor, and learn the basics of pointers (might as well just read up on C), then move on to Go. Before you go down the route of buying a paper book, try the interactive tutorial on the golang web site. It's pretty good. There's also a lot of good, and free, reading material on that site to help you learn. Also, regarding pointers: They're really not that bad, but I understand a lot of people can have trouble with them. Just realize that in languages like Ruby, and Python, you're never directly working with the computer's memory (as in RAM) - that is abstracted from you. However, in a language like C, you are. (As an aside, you still aren't directly dealing with it, the operating system abstracts it from your program via the virtual memory system, but you can ignore that for now, and look it up some time when you see fit.) So the first thing you need to make sure is that you understand the difference between stack storage, and heap storage. Once you understand the heap, and that it is essentially a large block of memory with sequential addresses, you can begin to understand pointers. They are just variables that contain the address of some other variable stored in memory. Languages that support pointers usually give you some syntactic sugar to make working with the "pointed to" object through the pointer easy. Of course it can all get more complicated, but in summary, give them a shot...you'll gain a much better understanding of many things once you learn them a bit.
- e12e 14y agoAs others have pointed out - you probably know enough about pointers to get started from the (rather excellent) documentation. As for learning pointers -- I've never been able to get entirely comfortable with pointers in C -- the syntax just feels unnatural to me. I much prefer either assembler (intel syntax) -- or Pascal, eg: http://www.tutorialspoint.com/pascal/pascal_pointers.htm http://www.tutorialspoint.com/pascal/pascal_pointers.htm Go syntax is closer to C, though. So knowing C, Go might be easier (than not knowing C) -- but it isn't a prerequisite.
- shurcooL 14y agoI started with this. http://tour.golang.org/ http://tour.golang.org/ Then I went through those. https://news.ycombinator.com/item?id=5365401 https://news.ycombinator.com/item?id=5365401
- jesstaa 14y agoYou already know everything you need to know about pointers. In Ruby almost everything is a pointer. What you need to learn about is 'values'.