Greetings from North Korea Golang into the pit series

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Hung-Chien on the land

Ben wanted to write 18-style, but according to the current progress, it is difficult to get enough 18-style. So that's the same sentence, do what you have to. Can write as much as how much, I can not guarantee to read this Golang talk show, will be able to become Golang Danale. But into the door, can self-reliance began to write Golang jokes should be similar.

Technology, you said Day is a skilled worker. A knowledge point, once do not understand, just look two times. Two times no, just come three times. Practice makes perfect, skillfully can seize the day. How many Daniel also came from a line of code. After all, like Li Yinan so little technology, the vast majority of coder career still rely on the amount of code piled up.

When I was in college, the computer course was divided into major majors: Theoretical research and application practice. Theoretical research is to study the principle of various algorithms, in favor of mathematics. Application practice is inclined to the idea of landing, that is, coding implementation. That will always feel that writing code is a very challenging and promising things, and research algorithms, boring boring, there is no way out.

10 years later, I was wrong.

Write code is always migrant workers, but is a little more senior one lost the migrant workers. The research algorithm, after all, is higher than the migrant workers of the golden Collar class. In this line of it programmers, the algorithm is not easy to find, write code programmers a lot. So the algorithm is ultimately more important than the code.

How many times, I want to switch from writing code to research algorithms, but always fail. It turns out that some debts are owed and will never have a chance to pay back. Life can be a few 10, a decade has gone, the next ten years quietly arrived. It took 10 years to understand that mathematics is not a decoration. Is it still a decade to make up for this fault?

Perhaps the four words of the corner overtaking are limited to paper, but the reality has lost the chance of overtaking forever. Some opportunities are lost or lost, and opportunities are prepared for those who are prepared, but it takes a long time to prepare for it. It's probably what this means, because it's a thick, thin hair.

For programmers, a lot of people are this is a young rice. In the past, I would scoff, smile. But now I agree from the heart, China is no programmer feelings. China's programmer prime Time is in the 25~32岁, this period, can enjoy overtime, enjoy the night, enjoy the inspiration, indulge in unbridled. And once you have a prime-day program, you need to think about the family, the need to think about life, the need to think about the wealth gap with your peers and the future of the next generation. Limited energy, the family slowly occupy the head of energy. The code, even though there is a great enthusiasm, but can not devote five points of energy.

If there is a group of superior peers on the side to stimulate you, that taste really uncomfortable.

It's not deliberately demeaning the programmer's job, which is a real social dilemma. And this problem has always been deliberately avoided, but now can not escape. Everyone has their own answers to this question. After all, the road is their own choice, and then tired to go down.

Greetings from the DPRK

Today in reading this book data statistics, found that unexpectedly have a UV from North Korea, a moment of excitement deliberately photographed souvenir

To commemorate this special occasion, this section is specially named < Greetings from North Korea >. Also do not know is North Korea which elder brother to visit this book, from PV above view only click 10 times, estimate probably is to see not to understand Chinese, casually point of point on go. But for me, this UV is precious. I do not know that the user is "the Supreme leader of the Revolutionary Armed forces" who relatives and friends, if you can see this article, can you introduce? (이사람이 ' 혁명무장역량의최고지도자 ' 라고할수있는어느친척인데,이글을볼수있다면,추천을받을수있을지도모른다.)

In other words, technology has no borders. Our narrow strip neighbors want to learn some technology. What if you want to watch the introductory tutorial? Do you recruit Golang engineers there? I can work from home, remote help you solve the problem, directed at this great international friendship, I am embarrassed to mention the money things, you watch to give! (당신들은golang엔지니어를채용합니까?나는집에서일할수있고,장거리도너희들에게문제를해결하고,이위대한국제적인우정을가지고있는데,나는돈을말할수없는일을,당신이바라보고있다!)

Thank you Youdao dictionary, the translation of my meaning sorta, in addition to Youdao, temporarily no use of translation software, can only endure. If you also want to participate in this great technological revolution, leave a contact for me. When Comrade Kim Jong-un summons me, I will summon you again. For the Revolution! We are always ready (혁명을위하여!우리는항상준비하고있다). North Korean friends see here can be, below I want to write Golang.

My style is always where I want to be, where I write. A few days ago when writing the program, there was a cycle of death. Looking carefully, the exit condition of the recursive algorithm is problematic. This is the first verse to say recursion.

Recursive

Simply put, recursion is the repetition of calling the same Function procedure to resolve the same problem. To convert adult words, is to self-tune themselves. The pseudo code is as follows:

func recursion() {   recursion() }func main() {   recursion()}

Most programming languages support this method of invocation, when using recursion, be sure to pay attention to the exit condition, otherwise it will be the same as me, there is a dead loop! Because recursion belongs to the algorithm of one, according to the truth should be placed in the algorithm book to explain the best. So just use an example to remind everyone who uses recursion, be sure to pay attention to the exit criteria!

package mainimport "fmt"func fibonaci(i int) (ret int) {   if i == 0 {      return 0   }   if i == 1 {      return 1   }   return fibonaci(i-1) + fibonaci(i-2)}func main() {   var i int   for i = 0; i < 10; i++ {      fmt.Printf("%d ", fibonaci(i))   }}

The above two if is used to determine the exit condition. If you exit the condition and write well, recursion does not occur. In my death cycle case, there was a problem in the if link, which was used to determine whether the two variable types were consistent, resulting in a permanent false and therefore a cyclic%>_<%. So, when the strike is over, let's talk about how Golang can be typed.

Type conversions and type assertions

There are two types of operations involved in Golang, one is type conversion and one is type assertion.

First of all, type conversion, the type of Golang is divided into two types, one is static type, and the other is the underlying type. Like what:

type myString string

Your type mystring is declared with the type keyword. MyString is a static type, while string is the underlying type. If the underlying type is the same, both types can be converted successfully and vice versa. If you do not know the underlying type, you can call reflect's kind method to get it, as follows:

fmt.Printf("%v",reflect.Kind(count))--int32

There are also interface type interface{} in Golang. Many times, the normal type is converted to interface{}, the process is implicit derivation, the user is not aware. However, if you reverse the conversion of interface{} to a normal type, a display deduction is required. A type assertion is required at this time.

There are two ways of asserting:

The first kind, Comma-ok:

value, ok := element.(T)比如:var a interface{}value, ok := a.(string)if !ok {    fmt.Println("It's not ok for type string")    return}

If ok = = True, indicates that a is of type string. Anyway, it means that it is not a string type.

The second type, switch judgment:

var t interface{}t = functionOfSomeType()switch t := t.(type) {    case bool:        fmt.Printf("boolean %t\n", t)             // t has type bool    case int:        fmt.Printf("integer %d\n", t)             // t has type int    case *bool:        fmt.Printf("pointer to boolean %t\n", *t) // t has type *bool    case *int:        fmt.Printf("pointer to integer %d\n", *t) // t has type *int    default:        fmt.Printf("unexpected type %T", t)       // %T prints whatever type t has}

The advantage is that you can save code, essentially the same as COMMA-OK.

Together, the Golang type conversion is three rules:

    1. Normal type to interface{} conversion is implicit.
    2. interface{} to a normal type conversion must be displayed
    3. When casting, it is best to use type assertions to prevent panic.

Still the most supplementary sentence, reprint please keep my mailbox. Ztao8607@gmail.com

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.