6 ms·
Go's lexical scoping and first class function/method's owe a lot to JS for leading the way IMHO. That said, it's "object" system is almost the complete reverse.
by donatj 11y ago
Go's lexical scoping and first class function/method's owe a lot to JS for leading the way IMHO. That said, it's "object" system is almost the complete reverse. JS is methods with data, Go is data with methods. It's an interesting contrast.
- xdc55 11y agoJavascript leading the way? What are you talking about? First class functions is a concept from mathematics and many programming languages had this feature way before javascript existed, and I simply don't understand exactly what concept of Go's lexical scoping resembles anything exclusive of javascript. I don't understand the last paragraphs about methods with data and data with methods, but Go's structs resembles C's structs, binding methods to a struct is an thing I've only seen in Go, but maybe some other programming language had this before.
- jerf 11y agoIIRC, the only difference in C++ between a struct and a class is the default visibility, and maybe some other bizarre quirky corner case or two. Despite it technically not being in the Go lingo (the word "object" only appears once in the entire Go spec, and that's referring to composing arrays/slices together to get multi-dimensional arrays/slices), I generally don't kick myself too hard for referring to things in Go as "objects". They are. Sure, officially they're "structs with methods" (method is the official term), but given the diversity of other things the term "object" is applied to that's plenty close enough for me.
- danieldk 11y agoGo's structs resembles C's structs, binding methods to a struct is an thing I've only seen in Go, but maybe some other programming language had this before. Oberon, probably others: http://www.excelsior-usa.com/doc/xds/o2rep.html http://www.excelsior-usa.com/doc/xds/o2rep.html
- hellofunk 11y agoFirst class functions and lexical scoping have been actively used in programming languages since 4 decades prior to the invention of JS.
- woah 11y agoMysteriously they gained popularity at the same time that JS did.
- hellofunk 11y agoThat is certainly not true, and therefore, not mysterious. In fact this website, ycombinator, is the result of a nice pay day that Paul Graham enjoyed for selling web service he built in the 1990s using functional programming techniques... and it was not JS.
- jerf 11y agoRemember that Javascript was literally bashed together in just over a week. That's not a slur, that's a description of reality. Javascript is a minor miracle on its own, but even in that minor miracle, Brendon Eich did not have time to also prototype something brand new. Everything in Javascript was decades old when it was created. The prototype system was probably the craziest thing that went in, but even that was old, if not popular.
- pcwalton 11y ago> Go's lexical scoping and first class function/method's owe a lot to JS for leading the way IMHO. I don't think this comment deserves the downvotes. JS deserves a lot of credit for doing scoping right in 1995, at a time when most popular languages (i.e. not Lisp or ML) were doing it wrong. (A notable exception was Perl 5, which did scoping right in 1994.) Thanks to JS, a lot of working programmers who would never be exposed to Lisp learned lexical scope. Remember that Emacs Lisp famously chose dynamic scope over lexical scope (a serious blunder) due to RMS's belief that lexical scope couldn't possibly be implemented in a performant way!
- muflax 11y agoWhat languages without lexical scope are you thinking of? Aside from literally only (pre-Common and Emacs) Lisp, I can't think of any language without lexical scope (outside some constructs etc). [edit:] Or are you thinking of "only a single global namespace"? Even that exists only in otherwise highly restricted scripting languages, I think? ("Everything global" is technically lexical, but I see why you wouldn't want to call it that.)
- pcwalton 11y agoTcl, PHP, any language without closures.
- muflax 11y agoHow does PHP have dynamic scope? It's been ages since I touched it, but if I remember right... Global is just a flat namespace. Functions have their own, separate flat namespace each. I tried the following in a REPL: function two() { echo $a; } function one() { $a = 1; two(); } one(); as the standard dynamic scope example, and I get an "undefined variable" error. Did that use to be dynamic? (I wouldn't be surprised, though, especially given PHP's implementation history...) There is an explicit "static" modifier that looks dynamic, but I couldn't get it to run that way. It seems to just retain state in recursive calls of the same function, or something? [edit:] (And PHP doesn't predate Javascript, but regardless, "no first-class functions" isn't "no lexical scope".)
- ninjakeyboard 11y ago>> first class function/method's owe a lot to JS for leading the way Javascript's lambdas were inspired by Scheme which has been around since the 70s. "Remember, I was recruited to 'do Scheme', which felt like bait and switch in light of the Java deal brewing by the time I joined Netscape. My interest in languages such as Self informed a subversive agenda re: the dumbed down mission to make 'Java's kid brother', to have objects without classes. Likewise with first-class functions, which were inspired by Scheme but quite different in JS, especially JS 1.0." - Eich (on HN)