0x06 code English Lesson from code English lesson 00:00 11:52

Hello world, I’m Pshu. I’m here to tell you something about docker.

Let’s start with the word “trivia”. For a more authentic translation, I personally think trivia is a better word.

Trivia:

     The act of answering questions regarding information that is often useless or inapplicable

The act of answering unintentional/useless questions.

Today’s “trivia question” is:

* What is the default container name when starting a Docker container? *


     
  1. CONTAINER ID    IMAGE          COMMAND    NAMES

  2. eee4de167f06    hello-world    "/hello"   peaceful_mcnulty

  3. 783ab628a474    hello-world    "/hello"   suspicious_jones

  4. 5767cd8dc7c0    hello-world    "/hello"   heuristic_bassi

  5. cc4623db38ad    hello-world    "/hello"   elated_montalcini

  6. e8bb358ada71    hello-world    "/hello"   sleepy_kilby

  7. 6e67c5398a72    hello-world    "/hello"   boring_kowalevski

  8. 21ffb481d971    hello-world    "/hello"   angry_euler

  9. 8c9322287dff    hello-world    "/hello"   keen_mayer

Copy the code

Simply put, the default container name is “${adjective}_${name}”.

But to dig a little deeper, who were those names? How many of these combinations are there?

Source code tell/PKG/namesgenerator/names – generator. Go# L105

https://github.com/moby/moby/blob/b5f68d7ed3a2a9db7bdbfd3bdee42d9d1a7e5423/pkg/namesgenerator/names-generator.go

(Click the original address to view the source code)

Source left is an array of 93 adjectives, both positive and negative; Right is the name of 160 well-known scientists and hackers.


     
  1. func GetRandomName(retry int) string {

  2. begin:

  3.    name := fmt.Sprintf("%s_%s", left[rand.Intn(len(left))], right[rand.Intn(len(right))])

  4.    if name == "boring_wozniak" /* Steve Wozniak is not boring */ {

  5.        goto begin

  6.    }

  7.    if retry > 0 {

  8.        name = fmt.Sprintf("%s%d", name, rand.Intn(10))

  9.    }

  10.    return name

  11. }

Copy the code

So there are actually two jokes when you look at the code.

1. About the goto

When Pshu was taught computer programming in college, his teacher mentioned that using Goto was a bad programming habit. Therefore, many students who have accepted the similar statement are sneering at this goto. On the contrary, the goto actually makes the code easier to understand.

So where did the saying about goto come from? Here is the introduction of today’s Dutch god Edsger Wybe Dijkstra. In Chinese, it is commonly transliterated as “Dikstra “.

In fact, I think it’s a little too serious to call him a god. I should call him a sage in the computer industry. Dijkstra’s algorithm for finding the shortest path between two objects in image theory was invented by Dijkstra. In addition to algorithms, Dijkstra is a pioneer in concurrent programming. Critical section and Dining Philosophers problem He came up with all the concepts.

Back to the question of Goto, where does the history of Goto’s “harmfulness” come from?

While Dijkstra had programmed extensively in machine code in the 1950s, he came to the conclusion that in high-level languages frequent use of the GOTO statement was usually symptomatic of poor structure. In 1968 he wrote a private paper “A Case against the GO TO Statement”, which was then published as a letter in CACM.[59] Editor Niklaus Wirth gave this letter the heading “Go To Statement Considered Harmful”, which introduced the phrase “considered harmful” into computing.

Dijkstra’s extensive use of machine code programming in the 1950s; In 1968, he wrote A small paper called “A Case Against the GO TO Statement.” A case in point: Don’t use goto. As a result, at the time of CACM’s publication, the editor had changed the title to “Goto statement “, which was considered harmful.

Unexpectedly, many students learn programming directly to set the flag that GOTO is bad code.

The second point in this code is /* Steve Wozniak is not boring */

2. the Woz

Woz, apple is a great company. For Apple, the most famous company is Steve Jobs. But this Woz is the guy that Jobs called Apple’s dual core. With the Apple I/II, Woz ushered in a new era of personal computing. Apple also had a third founder, Ronald Wayne, who worked at Apple for only 12 days; He said of the two :” Jobs was possessed by a demon at times, and Wozniak was a child controlled by an angel.” When Apple’s stock soared after the Apple II hit the market, Wozniak sold 80,000 shares at a fraction of the price to longtime employees who he felt had been mistreated by Apple.

What else did Woz do that made him feel special?

  1. He made a semiconductor radio at the age of six, and was the youngest person in the United States to earn an amateur radio license.

  2. And Jobs makes a bootlegging telephony device and uses it as a prank to pretend kissinger is calling the Pope of Italy.

  3. He built a telephone hotline for telling jokes. Although he lost money, he met his first wife by relying on this hotline

  4. Second fiancee, flying a plane, crashing a plane, but luckily he’s fine in the end.

In these experiences, Woz is definitely not a boring person.

Also, Woz is Sheldon’s top 15 tech visionary (Steve Jobs is no. 21). For copyright reasons, please do your own search for the video.

So let me conclude

When faced with the question “What is the default name of a Docker container?” Trivial question and the complex question of whether the Goto statement is harmful. If you can resist the urge to give a simple answer, be curious, explore slowly, and think. The knowledge gained in the end is certainly more valuable than the question itself.

Happy Hacking & Happy Docker!