Some of the amazing advantages of the Go language you don't know

Source: Internet
Author: User
Tags version control system
This is a creation in Article, where the information may have evolved or changed. [] (https://raw.githubusercontent.com/studygolang/gctt-images/master/go-advantage/1.png) > illustrations from https:// Github.com/ashleymcnamara/gophers in this article, I'll discuss why you should try out the Go language and where to start. Golang is a programming language that you may have heard of in the last few years. Although it was created in 2009, it has only become popular in recent years. [] (Https://raw.githubusercontent.com/studygolang/gctt-images/master/go-advantage/2.png) > is based on Google Trends The popularity of Golang This article is not about the main selling point of Go that you usually see. Instead, I'd like to introduce you to some fairly small but still important features that you can only learn when you decide to try Go. These amazing features don't float on the surface, they can save you a lot of work. They can also make software development more enjoyable. If Go is something new to you, don't worry. This article does not require any Go language experience. If you want to learn more, I have added some additional links at the bottom of the article. We will cover the following topics:-godoc-Static code analysis-built-in test and performance analysis framework-Competitive condition detection-learning curve-reflection-fixed code style-culture note that the list does not follow any particular order. Completely random sort. # # GODOCGO attaches great importance to the documentation in the code. In Go, the document is also easy to add. [Godoc] (https://godoc.org/) is a static code analysis tool that can create beautiful document pages directly from your code. One notable thing about Godoc is that it doesn't use any extra language, just like Javadoc,phpdoc or JSDoc in the code's comment structure. Just use English. It uses the information obtained from the code as much as possible to build the outlines of documents, structured and formatted documents. It has all the garish stuff, such as cross-references, code examples and direct links to the version control system library. All you can do is add a good '//MyFunc transforms Foo into Bar ' note, which will also be reflected in the documentation. You can even add [code sample] (httpS://blog.golang.org/examples), which can be actually run through the Web interface or on-premises * *. Godoc is the only Go document engine used throughout the community. This means that every library or application written with Go has the same document format. In the long run, it saves you a lot of time browsing these documents. For example, this is the Godoc page of the example project I recently implemented: [Pullkee-godoc] (Https://godoc.org/github.com/kirillrogovoy/pullkee). # # Static code analysis go heavy relies on static code analysis. For example, include [Godoc] (https://godoc.org/) for the document, [GOFMT] (https://golang.org/cmd/gofmt/) For code formatting, [Golint] for code style checking (https:/ /github.com/golang/lint), as well as many other examples. There are so many tools and even a project called [Gometalinter] (https://github.com/alecthomas/gometalinter#supported-linters), The ability to package all the tools together into a single tool. These tools are typically implemented as stand-alone command-line applications and can be easily integrated into any coding environment. Static code analysis is not really a new thing in modern programming, but go uses it to the extreme. I can't overestimate how much time it saves me. In addition, it will give you a sense of security, as if someone in your back to shelter you from the wind and rain. It's easy to create your own analysis tools because go has a dedicated built-in package that can be used to parse and process go source code. You can learn more from this speech: [Gothamgo Kickoff meetup:go Static analysis Tools by Alan Donovan.] (https://vimeo.com/114736889) # # Built-in testing and performance analysis framework have you ever tried to choose a test framework for a JAVASCRIPT project that starts from scratch? If so, you may understand the struggle of experiencing such an analysis paralysis. You may have realized that you didn't use 80% of the frame you chose. Once you need to do some reliable analysis, the problem repeats itself. Go provides a built-in test tool designed to be streamlined and efficient. It provides you with the simplest API available and makes the smallest assumptions. You can use it for different types of tests, analysis,Even provide executable code examples. It is out of the box and generates a CI-friendly output that is usually as simple as running ' go test '. Of course, it also supports advanced features such as running tests in parallel, tag skipping, and so on. # # Race condition detection You may already know goroutines, which is used in Go to implement concurrent code execution. If you don't know it yet, [here] (Https://gobyexample.com/goroutines) has a very short explanation. Concurrent programming in complex applications is not easy, regardless of the specific technology, in part because of the likelihood of competitive conditions. In short, the race condition occurs when multiple concurrent operations are completed in an unpredictable order. This can lead to a lot of errors, especially difficult to trace. Did it take a day to debug an integration test that could only perform about 80% of the time? This may be a competitive condition. All this shows that concurrent programming is very much appreciated in Go, and fortunately we have a fairly powerful tool to capture these competitive conditions. It is fully integrated into the tool chain of go. You can read more about it here and learn how to use it: [Introducing the Go Race detector-the go Blog.] (https://blog.golang.org/race-detector) # # Learning curve You can learn all the functions of the Go language in one night. I'm serious. Of course, there are standard libraries, as well as best practices in different, more specific areas. However, two hours is perfectly enough to give you the confidence to write a simple HTTP server or command-line application. This project has [great documentation] (https://golang.org/doc/), and most of the advanced topics have been covered by their blogs: [The Go Programming Language Blog] (https://blog.golang.org/). Go is easier to popularize in your team than Java (and its family members), Javascript,ruby,python or even PHP. The Go development environment is easy to set up and your team needs to make a small investment to complete your first product code. # # Reflection Code reflection is essentially a capability that can lurk at the bottom of the screen and access various meta-information about the language structure, such as variables or functions. Since Go is a statically typed language, it is subject to various limitations when it comes to loosely typed abstract programming. Especially when compared to languages such as Javascript or Python. Also, Go [does not implement a concept known as generics] (Https://golanG.org/doc/faq#generics), which makes it more challenging to handle multiple types in an abstract way. However, due to the complexity of generics, many people think that this is actually useful for languages. I totally agree. Depending on the philosophy of Go design (which is itself a separate topic), you should try not to over-design your solution. This also applies to dynamic type programming. Stick to the static type as much as you can and use the interface when you know exactly what type you are working with. In Go, the interface is very powerful and ubiquitous. However, there are still situations where you can't know what kind of data you're dealing with. JSON is a good example. You can convert all types of data back and forth in your application. strings, buffers, various numbers, nested structures, and so on. To solve this problem, you need a tool to examine all the data at run time, taking different behavior depending on the data type and structure. Reflection can help you! Go has a class-A-class reflex pack that enables your code to be dynamic, like a language in JavaScript. An important caveat is to know what price you pay for using it--only use it when there is no easy way. You can read more about it here: [The laws of Reflection-the Go Blog.] (https://blog.golang.org/laws-of-reflection) You can also read some of the real code in the source code of the JSON package here: [Src/encoding/json/encode.go-source code] (https://golang.org/src/encoding/json/encode.go) # # fixed code style by the way, is there such a word? One of the hardest things I face in the Javascript world is deciding which conventions and tools I need to use. How should I format my code? What test libraries should I use? How should I design the structure? What programming patterns and methods should I rely on? Sometimes these things basically get me stuck. I had to do these things, and I couldn't spend my time writing code to meet the needs of the user. First of all, I should note that I am fully aware of where these conventions should come from. It always comes from you and your team. In any case, even a group of experienced Javascript developers can easily find themselves using completely different tools and conventions to achieve the same results. This makes it difficult to analyze positioning issues across the team, and makes it difficult for everyone to work with each other. However, Go is different. You only have a code style guide that everyone must follow. You only have a test framework built into the basic tool chain. on how ToBuilding and maintaining code, you have a lot of strong opinions. How to select a name. What kind of structured pattern to follow. How to perform concurrency more effectively. While this may seem too restrictive, it can save you and your team a lot of time. When you code, some restrictions are a good thing. When building new code, it gives you a more straightforward approach and makes it easier to understand existing code. As a result, most Go projects look very similar. # # Culture People say that whenever you learn a new spoken language, you will also be influenced by the culture of people who speak it. Therefore, the more languages you learn, the more personal changes you may receive. This is the same as the programming language. Whatever new programming language you use in the future, it will always give you a new perspective on programming, or some specific technology. Whether it's functional programming, pattern matching or prototype inheritance. Once you have mastered this knowledge, you can carry these methods with you, broadening your tools as a software developer to solve problems. In general, it also changes the way you look at high-quality programming. Go is a good investment opportunity. The main pillar of Go culture is to keep the code simple and practical, without generating unnecessary abstraction and attaching great importance to the maintainability of the code. Being able to spend a lot of time on implementing business code, rather than modifying tools and configuration environments, is part of the culture. Or choose between different variants. Go can also be summed up as "there should be only one way to accomplish something". A small aspect of the description. When you need to build a relatively complex abstraction, using Go is usually not so good. For this, this should be a price for the simplicity of the Go language. If you really need to write a lot of abstract code with complex relationships, it's best to use a language like Java or Python. But even if there is a real need, this is a rare situation. Always use the best tools to get the job done! # # Summary You may have heard of Go before. Or maybe it's not in your area of use. Either way, Go can be a very decent choice for you or your team to start a new project or improve an existing project. This is not a complete list of all the amazing benefits of Go. * * is only an undervalued part. * * Please try the go language, [a tour of Go] (https://tour.golang.org/) is a good place to start learning. If you want to learn more about the benefits of Go, you can look at these links:-[Why should learn Go?-keval Patel-medium] (https://medium.com/@kevalpatel2106/why-sho Uld-you-learn-go-f607681fad65)-[Farewell Node.js-tj Holowaychuk-medium] (https://medium.com/@tjholowaychuk/farewell-node-js-4ba9e7f3e52b) Share your learning results in the comments! Even if you are not looking for a new language, it is worthwhile to spend one or two hours learning about Go. Maybe in the future it may become very useful to you. Continue to find the most suitable development tools for you! * * * * If you like this article, please consider paying more attention to my content and click on those interesting green small hands below the text to share.

via:https://medium.freecodecamp.org/here-are-some-amazing-advantages-of-go-that-you-dont-hear-much-about-1af99de3b23a

Author: Kirill Rogovoy Translator: MDGSF proofreading: Rxcai

This article by GCTT original compilation, go language Chinese network honor launches

This article was originally translated by GCTT and the Go Language Chinese network. Also want to join the ranks of translators, for open source to do some of their own contribution? Welcome to join Gctt!
Translation work and translations are published only for the purpose of learning and communication, translation work in accordance with the provisions of the CC-BY-NC-SA agreement, if our work has violated your interests, please contact us promptly.
Welcome to the CC-BY-NC-SA agreement, please mark and keep the original/translation link and author/translator information in the text.
The article only represents the author's knowledge and views, if there are different points of view, please line up downstairs to spit groove

1290 Reads
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.