5 ms·
I clicked the article thinking that Go pointers are something special... but this seems targeted at the "programmers" who only know javascript...
by nottorp 10y ago
I clicked the article thinking that Go pointers are something special... but this seems targeted at the "programmers" who only know javascript...
- lclarkmichalek 10y agoProgrammers who only know javascript are, controversially, still programmers.
- leshow 10y agoEven if you're a JS programmer, having no knowledge of pointers just shows you've never dug very deep into how your language works. Does JS pass by value? by reference? does it pass references by value? These are all things a JS programmer should know, and requires some knowledge of pointers.
- bsaul 10y agoDon't understand the downvote. Understanding javascript's closure (which is a core js feature even on the client) properly without understanding pointers seems like an impossible task to me.
- inimino 10y agoThe idea of reference is necessary, but pointers are an implementation detail. If you don't come from C, you can understand everything in JavaScript without knowing what pointers are. Many languages have references to mutable state without the peculiar details that make pointers what they are.
- EdiX 10y agoRegardless of whether they can be called programmers, we can not deny that they exist.
- akuji1993 10y agoI'm really tired of people bashing Javascript to death. It's here, it's being used, wether you like it or not. Stop whining about it, please.
- TeMPOraL 10y agoThe constructive question here is: is there any way to make JavaScript stop being used (especially for tasks not related to webpages)?
- self-diversity 10y agoNope. Especially since many of us don't have piles of irrational hatred for it.
- inimino 10y agoThat is not a constructive question.
- bpp 10y agoI'm a programmer who spends all day in Go working on backend systems, but came to it from Javascript, my first language. Pointers were one of the concepts that took me the longest to understand, even having dug into them previously in the context of V8's object implementation. So I for one am grateful for this article, and just passed it on to a recent bootcamp grad at my company. Hopefully it will accelerate his learning curve.
- penpapersw 10y agoThe first language I learned was QBasic, so when I started to learn C++, the concept of pointers was bizarre and took longer to learn than it should have, but after it finally clicked, it gave me a special love for pointers, the simplicity of C, and low-level programming in general.
- int_19h 10y agoWhile QBasic didn't have pointer types, it did have pointers in disguise (or rather, pointers without disguise, which are just memory addresses) - VARPTR, PEEK and POKE. As I recall, PEEK'ing and POKE'ing things was actually necessary to do many important tricks in QB, especially once you started playing with CALL INTERRUPT.
- aaron-lebo 10y agoYes, there are programmers who only know JS. There's nothing "wrong" with that. If you only work in Ruby, Python, JS, or even functional languages it's very possible you've never run across pointers (at least not explicitly). It's actually something people misunderstand about C, it's fundamentally a memory-oriented language in a way functional or OO languages are not and there are some real advantages to working that way. Ironically, this actually shows through in JS with the constructs you use to manipulate arrays (cause it borrowed from C). No need to look down on other programmers; we all gotta start somewhere.
- nottorp 10y agoWe all do... but IMO it's better to start with BASIC than Javascript...
- jerf 10y agoBASIC is an ill-defined term, but if you mean the most modern versions of BASIC (as I seriously hope you don't mean 8-bit era BASIC), they aren't significantly different from Javascript circa 2005 in terms of quirkiness and silliness (and that's assuming you've got one with some sort of closure support, which I don't recall if one ever existed; without that BASIC is a clear loser behind Javascript-2005), and Javascript is certainly moving to exceed any BASIC I know about lately. Javascript does have a lot of flaws, but unlike BASIC which is pretty much dead, the main structure of Javascript is alive and well, as dynamic scripting languages are still very much a going concern.
- pjmlp 10y ago> BASIC which is pretty much dead Tell that to the enterprise employees writing Office macros or doing VB.NET applications.
- jerf 10y agoSince you sort of ask: Go pointers themselves are not that special, because in a GC'ed language with no pointer arithmetic they're really just a map/territory-type distinction, but there are some syntax affordances that can make them briefly more confusing than they appear. For method calls and field accesses, Go fuzzes whether you have an object or a pointer by making the "." operator work on both, rather than C's "." vs "->" distinction. Since it's never ambiguous, it's just pointless overhead to make the programmer worry about that. It can also be slightly confusing that the method itself can control whether it receives a pointer, so you can call object.Method on a concrete object, but Method will receive &object. As a professional programmer I appreciate not being bothered with this unambiguous detail that the language can easily handle for me, but it can confuse people in the early going, which is a legitimate criticism. (I still come down in favor of doing what it is doing, but it is a legitimate drawback.) The other thing I see that fools people with experience from other languages is that the "nil" pointer is not the same thing as a NULL pointer in C. In C, the NULL pointer is simply a zero with no type information connected to it. In Go, pointers are actually (type, address) tuples, so a nil pointer to a custom struct is actually (pointer CustomStruct [1], nil), which means that the runtime is capable of correctly resolving methods on nil pointers and that you can therefore write methods that work on nil pointers. Nil pointers are still bad because they are a value added to all pointer types by the act of taking a pointer that you can't control, you get it whether you like it or not, but they are not bad in the C sense that any attempt to touch one is a segfault.[2] That's about all that matters in normal Go programming. [1]: Asterisk is confusing HN's italicization there. [2]: Which is I think an important aspect of understanding the "billion dollar mistake", by the way; it is easy to deconstruct that mistake as being two mistakes rolled in to one, which may perhaps explain why it was such a big mistake.
- pcwalton 10y ago> Which is I think an important aspect of understanding the "billion dollar mistake", by the way; it is easy to deconstruct that mistake as being two mistakes rolled in to one, which may perhaps explain why it was such a big mistake. If it's two mistakes, it's one big one (having null pointers at all) and one tiny one (the fact that calling methods on null pointers is undefined behavior in C++). The latter is yet another C++ gotcha, but not nearly as pernicious as the former, which causes nearly all the null pointer-related bugs in the wild.
- deleted 10y ago[deleted]
- weberc2 10y agoOr Python or Java or C# or any other language without pointers... These languages command a huge marketshare. This article is clearly targeting folks coming to Go from those languages.
- DrJokepu 10y agoC# actually has (unsafe) pointers, although they're not used (and are not intended to be used) very frequently.