Go, JavaScript

The Translation Bureau is its translation team, focusing on science and technology, business, workplace, life and other fields, focusing on introducing new foreign technologies, new perspectives, and new trends.

Editor’s note: Which programming language is better? This may be a headache that many learning programmers and even laymen will face. Most of the popular programming language introductions on the Internet are patchwork content, and it is impossible for people to truly understand and understand the advantages and disadvantages of various languages. The original title of this article is These Modern Programming Languages ​​Will Make You Suffer. The author Ilya Suzdalnitski launched a detailed evaluation of 15 programming languages ​​in the article, I hope it will be helpful to you.

Image source: deepu

Lazy Directory

Overview: The most important features of programming languages

One star article: C++, JAVA

Two stars: C#, Python, Rust, TypeScript

Samsung article (part one): Go, JavaScript

Samsung articles (part 2): Haskell, OCaml, Scala

Four stars: Elm, F#

Five-star article: ReasonML, Elixir

Go

In multi-core processingIn the era of programmers and large code bases, Go is designed to improve programming productivity. The designers of the Go language hated C++, which was widely used at Google at the time, and this was their main source of motivation for designing Go.

Family of programming language: C

????Concurrency

Concurrency is the killer feature of the Go language. It was designed for concurrency from the beginning. Just like Erlang/Elixir, the Go language also follows the concurrency model of mailboxes.

Unfortunately, Go’s “threads” (goroutines) do not provide the same fault tolerance as Erlang/Elixir processes. In other words, an exception in the goroutine will crash the entire program, and an exception in the Elixir process will only crash that process.

????????Speed

One ​​of the main reasons Google created Go is that it has a very good compilation speed. There was also a joke at the time that Google created Go while waiting for the C++ code to be compiled.

Go is a very fast language, and the Go program starts very fast. Since it will compile native code, it runs very fast.

????The price you need to pay when learning

Go is a very simple language. If a person has other programming experience before, he can learn Go well in one month.

????error handling

Go does not support exceptions. However, Go allows developers to explicitly handle potential errors. Similar to Rust, Go will return two values-the result of the call, and a potential error. If there is no problem in the whole process, the error return value will be nil:

result, err := someFunction( args… );

if err != nil {
// handle error
} else {< br> // handle success
}

????No object-oriented programming

Some people may disagree, but I personally think that the lack of OOP features is a great advantage.

Here, I would like to quote Linus Torvalds, the father of Linus:

C++ is a horrible object-oriented language… If you can only use C to complete the project, then you will not mess up with any stupid object model.

Torvalz is famous for his public criticism of C++ and OOP. He is 100% correct. The thing is that programmers’ choices are indeed limited. In fact, the fewer choices programmers have, the more flexible their code will be.

In my opinion, Go deliberately omit a lot of OOP features to avoid the same mistakes as C++.

????Ecosystem

Some standard libraries are very stupid, and most of them are inconsistent with Go’s idea of ​​returning out-of-bounds errors (for example, those libraries will return -1 for a pointer , But the return value that Go wants is (int, error), and other libraries rely on global state, such as flag and net/http.

Go’s standard library lacks standardization. For example, some libraries will return (int, error) when an error occurs.Some libraries will return a value of -1, while others rely on global status (such as flag) for error handling.

Go’s ecosystem is not as big as JavaScript.

????Type System

When Alan Kay created object-oriented programming, C++ was not the perfect object-oriented language in his mind. Like Larry Tesler, the creator of “Cut, Copy and Paste”, he did not expect to make a language like Go when he introduced copy and paste.

——Twitter user Jasper Van der Jeugt @jaspervdj

There are quite a few modern programming languages ​​that have one or more forms of generics (including C# and Java, and even C++ have templates). Generics allow developers to target Implementation of different types of reuse functions.

Without generics, we must implement add functions for integers, double-precision floating-point numbers, and floating-point numbers, which will lead to a lot of duplicate codes. In other words, because Go lacks generics, there is a lot of repetitive code in Go. As some people say, “Go (which means “to”) is an abbreviation for “to write some templates.”

????Null value

Unfortunately, when safe alternatives have existed for decades, Go has included null values.

????immutability

Go does not provide built-in support for immutable data structures.

Conclusion

Go is a language that is neither good nor bad. We must be careful to use bad programming languages. Otherwise, we may have to keep going for the next 20 years. Use them and make no progress.

——Will Yager

If you are not working at Google and do not have to deal with Google-like use cases, then Go may not be the best language choice.

Go is a simple language most suitable for system programming, but it is not a good choice for API development, because there are many better languages ​​available now (It will be further explained later).

Although Go’s type system is weaker, in general, I think Go is a better programming language than Rust. Go is a simple, fast language, easy to learn, and has good concurrency characteristics. Therefore, Go is a successful C++ advanced language.

Best System Language Award

Go won the “Best System Language Award.” There is no doubt that Go is the perfect choice for system programming. Go is a low-level language. Many successful projects built with Go (such as Kubernetes, Docker and Terraform) are availableTo prove that it is very suitable for this field.

JavaScript

As one of the most popular programming languages ​​in the world, I don’t need to introduce JavaScript anymore.

Of course, this ranking is absolutely correct. JavaScript should rank higher than Rust, TypeScript and Go. Let’s see why.

Family of programming language: C

???? ????Ecosystem

The biggest advantage of JavaScript is its large ecosystem. JS can be used anywhere you can think of-front-end and back-end web development, CLI programming, data science, and even machine learning. JavaScript may have a library that supports everything.

????The price you need to pay when learning

JavaScript, like Python, is one of the easiest programming languages ​​to learn, and novices can master JS in a few weeks.

????Type System

Like Python, JavaScript is dynamically typed, which is nothing to say. JS’s type system can sometimes be very strange:

[] == ![] // -> true

NaN === NaN; // ->false

[] ==” // -> true

[] == 0 // -> true

????immutability

As mentioned in the TypeScript evaluation section, the extension operator is very bad for performance, and deep copying cannot be achieved when copying objects. Although JS has libraries (Ramda/Immutable.js) that can help deal with immutable data structures, it lacks built-in support for immutable data structures.

????React is not suitable for JavaScript

When using React in JavaScript, we must use PropType. However, this also means that we must maintain PropType, which is very scary.

At the same time, if you are not careful enough, you may also introduce performance problems that are not easily detectable:

Such innocuous code may cause a performance nightmare, because in JavaScript, [] != []. Even if the options value is not changed, the above code will cause HugeList to re-render every time it is updated. This problem will worsen until the user interface is finally unusable.

????Keyword this

The biggest disadvantage of JavaScript may be the keyword this. this lineIn order to be inconsistent, you need to pay attention to its details, which means that in different contexts, the content represented by this may be different. The behavior of this depends on the object calling the existing function. Using the keyword this usually results in strange errors that are not easily detectable and difficult to debug.

????Concurrency

JavaScript supports single-threaded concurrency using event loops, so there is no need for thread synchronization mechanisms (such as locking). Although JS did not consider concurrency when it was first created, it is much easier to use concurrent code compared to most other languages.

????New JS features

JavaScript received some new and unpopular features earlier than TypeScript. When you use Babel to compile JS programs, you can even start some of its experimental features.

????Error handling

Catching errors or throwing errors is the priority error handling mechanism.

Conclusion

JavaScript is not a well-designed programming language. Its initial version was created within ten days (although in subsequent versions, many shortcomings have been resolved ).

Although JS has many shortcomings, it is indeed a good choice for web full-stack development. With proper specifications and inspections, JS can be a good programming language.

Further reading:

  • The ultimate evaluation of modern programming languages: an overview

  • The ultimate evaluation of modern programming languages: one-star article

  • The Ultimate Evaluation of Modern Programming Languages: Two Stars

  • The ultimate evaluation of modern programming languages: Samsung (Part 2)

  • The Ultimate Evaluation of Modern Programming Languages: Four Stars

  • The Ultimate Evaluation of Modern Programming Languages: Five Stars

Translator: Junyi