go101 / go101, Hacker News

go101 / go101, Hacker News



Many articles think, and some surveys suggest, simplicity is the main reason why Go becomes popular. I have different opinions.

Go is not the simplest language among popular ones, it is neither from syntax view nor concept set view.

In my opinion, the reason why Go becomes popular depends on many factors:

  1. Go is supported by Google and embraced by the industry.
  2. Go programs have not an obvious weak point, though they are also not the strongest (comparing to other languages) in each of these points, which includes
    • memory saving
    • fast warming-up
    • fast execution speed
    • good reflection support
    • good static analysis support (tools)
    • good code readability
    • good cross-platform support
    • great guarantee for keeping compatibility
    • not complex
  3. Go filled the blank of lacking of a static language which is still much flexible in the world.

Honestly, the second factor is the most important one to Go’s success. However, personally, I think the last factor is the main sell point of Go.

Specifically, Go’s flexibility is mainly reflect in the following aspects:

  • great type deduction support in Go.
  • supporting a unique and interesting (and flexible) built-in concurrency programming model.
  • supporting function values ​​perfectly.

Let’s view some examples of the last aspect.

In Go, we can use methods as general function values:

( (c) *************(C) )M() {println(c.Name) }funcg(ffunc
()) {f() }funcmain() {     varc=C {foo}     g(c.M) )//foo}

Of all the other static languages ​​I have used, I feel they are all too rigid, in an unexpected way. For example, C doesn't support using methods (member functions) as function values.

class(C{   public:    voidM() {} };void
(f() {}void((g  (void
fptr) ()) {     fptr(); }intmain () {   C c;      g(f);ok  //  g (c.M); // not ok     return(0; }

(Yes, we can use the following shown JavaScript way withthe help ofstd :: bindandstd :: functionto use member functions as callbacks, but this is so weird, verbose, and unnatural.)

Java even does not support function values. A single-method interface is needed to simulate function callbacks.

Many languages ​​introduce lambda expressions to add some flexibility. But this does not solve the rigid problem, member functions still can't be used as function values. (Supporting lambda expressions is a compensation, not a solution, to become flexible.)

JavaScript is a dynamic language which supports function values. It really supports using member functions as function values, but the receiver context (or

thisin JavaScript) is lost in the process. Programmers must bind a member function and an object together explicitly. This is some weird and counter-intuitive. (In fact, this is not the only place exposes the weirdness of

) thiscontext in JavaScript.)

class(C{   constructor
(name) {;   }      M() {     console

;   } }functiong( f{   f(); }var



bar);r(M();r(M=************ (r) ************.  M) .bind
(r);//if this line is missing. ,                   //the next line will run error:                   //TypeError: Cannot read property 'name' of undefined



Although JavaScript support function values ​​well (despite the just mentioned drawback), now it also supports arrow functions (kind of lambda expressions), which in fact is not a necessary feature for JavaScript. I often have a feeling that JavaScript is becoming another C by supporting many new features (with duplicated functionalities) in recent years in a surprising pace, which results that there are many ways to do the same thing in modern JavaScript.

                     ************************Read MoreBrave Browser

What do you think?

Leave a Reply

Your email address will not be published.

GIPHY App Key not set. Please check settings

Every bookmark manager ever made, Hacker News

Every bookmark manager ever made, Hacker News

Surprise! Oculus Quest becomes first VR set with native hand tracking — this week, Ars Technica

Surprise! Oculus Quest becomes first VR set with native hand tracking — this week, Ars Technica