Hi, I’m Sean. See you every week for source code parsing
In a recent architecture upgrade, we looked into TypeScript, c#, rust, Java, and go. In this process, I have some personal views, which may be biased or incorrect. Let me just say it briefly.
In the previous post, I briefly covered some of the technical stack features of the game industry and how python, Typescript, and c# are working. For those of you who haven’t seen it, check out the links. This article continues the story of Go and Java rust.
The go
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. The Go language was born in 2009 and is open source by Google. It has been more than 10 years since its development. With the development of cloud native, Go language is booming with vigour and vitality; Many well-known frameworks, Docker, Kubernetes, etCD, etc. are implemented using GO. The recent news in China is that big companies like Byte are fully embracing, and many training institutions are pushing all kinds of GO courses. Everything looks very good.
For a quick taste, write the following main.go:
Package main import "FMT" func main() {FMT.Println("Hello, world ")}Copy the code
Run the hello program directly:
# Go run main. Go Hello, worldCopy the code
Compile Hello into an executable for the corresponding operating system using the following three commands:
GOOS=darwin GOARCH=amd64 go build -o hello_mac
GOOS=linux GOARCH=amd64 go build
GOOS=windows GOARCH=amd64 go build
Copy the code
To view the respective compilation results:
➜ file hello hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=YPrL0x5YX4DVXlh5kkKE/Y2HJXrRQkDsOpEXTVASf/NrLBfe3AB23u7MFL1ITI/GpLRUEatK4FJEmJ8Q5mW, In view ➜ file hello.exe: PE32+ Executable (console) x86-64 (For Windows ➜ file hello_mac hello_MAC: Mach-O 64-bit executable x86_64Copy the code
Hello_mac can be executed directly under MAC:
➜ hello. /hello ZSH: exec format error:./hello ➜ hello. /hello.exe ZSH: exec format error:. Exe ➜ hello. /hello_mac hello, worldCopy the code
This ability to execute directly without requiring a virtual machine/interpreter environment is very powerful.
It was about 14 years ago when I came into contact with Go. At that time, I probably read Asta Xie, the author of Beego. Unfortunately, at the time, GO seemed to be a very syntactically weird language, not as easy as PHP/Java. The second contact was in 19, because I had to temporarily support a project, and because OF the study of Docker and K8S, I understood the community development of GO, and thought it would be a promising language. But then the project changes, and did not continue to go deep. Recently, it is my third contact. At first, I wrote some small tools and services. I plan to write some gateway services. Coincidentally, I found that there are also students who feel similar to me, I directly excerpted below:
from draveness
At present, the author also uses Go language as the main language for daily development. Although Go language does not have the development efficiency and powerful expression ability of Lisp languages, it is a very easy to use and large-scale application of engineering language, which is also the main reason for the author to learn and use Go language.
The author began to learn and use Go language in 2018. When he first came into contact with Go language, he rejected and rejected it. He once thought that the design of GOPATH was very strange, and the simple grammar also led to low expression ability and affected development efficiency. However, with the in-depth study and understanding of the Go language, the author’s concept of this is constantly changing.
Today, the author thinks that we need in industry a grammar simple compiled language, so it can provide simple and abstract concept, although the language also has a lot of problems at present, but the continuous improvement of the language and computer-aided tools also let the author feel the vitality of the community, and firmly believe that the language of the future development of the more the better.
There is an adjustment period when learning to go. For example, the following code:
# gin/context.go func (c *Context) GetString(key string) (s string) { if val, ok := c.Get(key); ok && val ! = nil { s, _ = val.(string) } return }Copy the code
The code is easy to understand, take a key from a context and return it as a string. The differences are:
if val, ok := c.Get(key); ok && val ! = nil {... }
This three-paragraph structure, this syntax is all over almost any function in GO. This is because go does not have a try/catch syntax, and all functions do exception checks.(c *Context)
Such interface implementation, and object-oriented interface implementation is very different.
When you first look at the go code, it feels awkward, but once you get past the adaptation period, it’s ok to implement it this way. Then you fall into the trap of go concurrency where you don’t communicate by sharing memory, you communicate by sharing memory.
The learning process for Go, presumably like the debate over whether Windows PCS are easy to use versus Macs, is a matter of breaking through preconceptions.
Java and rust
Java needs no introduction, the industry’s overlord, the big factory’s favorite. There are many advantages, disadvantages, the main is that the individual is not proficient, has given up.
Rust is a language that empowers everyone to build reliable and efficient software. Rust is extremely fast and memory efficient. With no run-time and garbage collection, it can handle particularly performance-demanding services. Rust’s rich type system and ownership model ensures memory safety and thread-safety, allowing you to eliminate a wide variety of errors at compile time. It looks great.
I have only scratched the surface of Rust because it is said to be extremely difficult to learn. The concept of ownership is the core function and the core obstacle. Here’s a quick example:
let s1 = String::from("hello"); let s2 = s1; println! ("{}, world!" , s1);Copy the code
This code will work in any other language, assigning s1 to s2 and printing s1. Both shallow and deep copies are performance issues, not execution errors. However, it cannot be successfully executed in Rust because rust believes that after s1 is assigned to S2, s1 is no longer in use and should be destroyed, which is probably the concept of ownership.
Language ecological
Language learning, as previously introduced, is all about grammar. Generally speaking, it also involves the ecology or community of language. I can simply conclude that the ecology of language includes the following parts:
After learning the grammar of a language, you need to understand how the language works. For Python, you need to know the CPython interpreter, you need to know the GIL, you need to know GC; Java needs to do JVM tuning, and to become proficient in a programming language, grammar is obviously not enough. Different languages, there are generally different IDE tools, such as c# we use Visual Studio, skilled use of IDE tools, can improve the efficiency of research and development. Although VSCode is still good, it is not very useful without installing plug-ins, and installing plug-ins is not friendly to beginners. The best way is to use jetBrains tools. Pycharm, Rider, Goland are all magic. We also need to learn package management tools for the language so that we can leverage the various libraries in the same language and stand on the shoulder of open source.
Language communities are also very important. The first is the documentation, whether there are sufficient documents to introduce all kinds of grammatical details, and whether there are Chinese documents, language learning entry is very helpful. Personally, I am used to reading both Chinese and English documents. I can read Chinese documents quickly. I can compare and understand some parts that are not well introduced in Chinese. And then there’s whether there are enough open source projects out there to use, killer apps to refer to. When open source projects are sufficient, it is easy to program them. The general work is to carry bricks, not to build from sand.
Learning a language is also for work. In addition to the language itself, consider the recruitment market and talent market. The recruitment market can be reflected by the number of positions and salaries. Here is a statistic of language and salary:
Note: the maps are only illustrations and do not represent actual data
The talent market can be reflected by language popularity, such as Tiobe2019-2020 language popularity rankings:
Java and Python are not bad at all. My personal list of languages is as follows:
language | grammar | The environment | Package management | community | Suitable for field | Personal recommendations |
---|---|---|---|---|---|---|
python | simple | cpython/pypy | pip | rich | Widely used: crawler, data analysis, back-end services, AI, etc | ⭐ ️ ⭐ ️ ⭐ ️ ⭐ ️ |
typescript | simple | node&&v8 | npm | rich | Front-end applications are recommended, or full stack based on front-end | ⭐ ️ ⭐ ️ ⭐ ️ |
c# | medium | dotnet | nuget | rich | Game production | ⭐ ️ ⭐ ️ ⭐ ️ |
go | special | – | go-mod | rich | Cloud native services | ⭐ ️ ⭐ ️ ⭐ ️ ⭐ ️ |
java | medium | jvm | maven | rich | anywhere | ⭐ ️ ⭐ ️ ⭐ ️ |
rust | special | – | crates | general | High performance Web services, WebAssembly, embedded | ⭐ ️ ⭐ ️ ⭐ ️ ⭐ ️ |
Learning and understanding the grammar of various languages will help improve my programming ability and broaden my horizon. People should focus on this area when they are concerned about different languages. It is not recommended to go into the ecology of languages unless you intend to use it for work, because if you don’t use it, you will forget it. Learn different syntax with thought, such as the following Python function:
def readme(a, b):
with open('README.rst', 'w') as f:
c = 1
a = a+c;
b.append("b2")
f.write(a)
f.write(b)
print(a, c)
return b
Copy the code
We can consider the following questions:
- The types of parameters A and b
- Input and output parameters
- Value passing and reference passing of parameters
- B values and references
- Scope of f, C,a
- Does the function return a value? It can return several values
- If a function is an implementation of a class/interface, how should it be expressed syntactically?
The above problems, in different languages, have different implementation or expression, look more will understand the nature of the function.
Finally, I recommend you to learn C, after all, this is the ancestor, this is the history, other languages are derived from this root.
Refer to the link
- Drap. Me/Golang /
- Kaiser.github. IO /trpl-zh-cn/…