"Old man" and 00 go Kid's hard drive night conversation

Source: Internet
Author: User
Tags uppercase letter
This is a creation in Article, where the information may have evolved or changed. 1 first meeting

Although the various programming languages in this directory are written in a variety of programs, Java is still nostalgic for the unfortunate victims of the C old man. He often gives the same directory of Python, Ruby said C old man knowledge how profound, close to the hardware run, fast, can learn a lot from him and so on.


(Lao Liu Note: take part in "C Old man and Java boy's hard disk Night conversation")


Today, a new guy in the catalogue, Java a look at the file name "Hello.go" know this is a new language, is this language called go? Use a verb as the language name, very rare Ah!


Java hurriedly search the Internet, I race, this young man was born in 2009, are fast after 10, too young. These are the old guys we really are!


A bunch of old folks in Java, Python, Ruby ..... The Go program after 00 surrounded, carefully looked: "The new, you have what skills?" ”


Go is a little scared: "What are you going to do, Ken Thompson, Rob Pike is my father, be careful!" ”


Python quietly asked Java: "What are these two people?" ”


"Ignorant" Java is actually just online search, is now learning to sell: "Ken Thompson is the founder of Unix and C, Rob Pike is the designer of UTF-8!" This is not the main point, the key is that Google is endorsing this kid's platform. ”


We heard the boy's background so deep that he was timid.


"According to the Convention, new people have to come to a Hello world, to make a cast!" ”



"Another one put the type behind the variable name!" "Java is not going to hit the air at the sight of this syntax!"


"Mr. Java, isn't it true that Scala and Kotlin are on your JVM platform?" "After 00, the go boy knows so much, and he also cures his own way."


"The two boys dare to come here, I must beat them up a meal, your grammar, always let the old man feel really angry retrograde!" "Java is a self-proclaimed old man.


"Well, let it go, old age, True Qi retrograde, the fire is not good ah!" "Python comforted.


"But this kid's variable has to be specified type, and it seems to be a static type of language, my generation." Java felt a hint of comfort.


"Who is the man of your generation?" You take a closer look at this variable declaration, there is no type specified, there is no semicolon behind the statement, and we Python is a family. "Python starts off with Go Set.



Java "Old man" disdain to say: "Craved tricks you do not understand?" This is automatic type inference, our family Kotlin long time to play rotten! Just say that name, has been declared as a string type, can not be changed, you assign it to an integer to try? I bet the compiler will make an error! ”


2 cross-examine

Because of a static type of allies, Java to go to build a little favor, he asked: "Young man, for a language, there must be several basic data structure, such as arrays, lists, HashMap, you should have built-in all?" ”


"That is nature, now is not the C language era, language has to be built-in commonly used data types, no how they mix!" "Go right back.


"Process Control statement estimate almost, I do not want to see, how do you implement user-defined class AH?" "Java as the boss of this directory, on behalf of the people continue to cross-examine."


Go says: "Very simple, we learned a struct from the old man C."



One hears the idol C old man, Java's eyes are bright, this grammar really is similar to C.


Well This is just attribute data ah, there is no relevant method? "Python doesn't allow Java to be big, and it's asking.


"Simple, write a method on the line!" ”



"The method and the property are separated, not together, so weird!" "Everyone shouted.


"We all have public, private permissions qualifiers, what do you do with it?" Ruby asked.


"I'm very simple here, if an identifier (such as a method, variable, etc.) begins with an uppercase letter, it means that it is public and the code of the other package can be accessed, otherwise it is private!" ”


Everyone is amazed, this ... It's a little too fanciful!


"How do you deal with inheritance?" ”


"I do not actually inherit here, I have only a combination here:"



Again a piece of amazing sound, we have to take this method and their own implementation of the comparison, Java old Man remembered an object-oriented design of an important principle: " priority to use the combination rather than inheritance ", the heart felt that go of this idea is quite good.


"Then can you achieve polymorphism?" ”


"That said, I realized the way is also very simple, do not have to force a class to implement an interface, as long as you have and interface the same method can be used as that interface!" ”



"This is not the same as our Duck Typing !" "Python and Ruby say in unison," as long as you look like a duck and walk up the road to stagger a duck, then whether or not you realize the duck interface, we will think you are a duck! ”


3 goroutine

Java does not support duck Typing, the heart slightly uncomfortable, he pie Mouth said: "What is this ah, are some artifice." I ask you, how does your multithreaded programming implement? This is the key to being able to survive on the server side, in a demanding environment with high concurrency! ”


Go says: "I don't have multiple threads!" ”


No threads? We all stare big eyes, then how do you support concurrency ah?


"But I have a goroutine that can be thought of as a lightweight thread. ”


"I say, how can modern languages not support concurrency?" What are the characteristics of your goroutine? "asked Java.


"Goroutine is like a thread, a piece of code that can be run, and you start a goroutine with the keyword go before a function call, simply not?" “



"How exactly did you do that?" ”


"When you create a goroutine, it is added to a global run queue, and the scheduler assigns them to a logical processor that is bound to a unique operating system thread , To really run goroutine on it, if a logical processor has more than one goroutine to run, it will also form a queue, allowing the logical processor to dispatch execution. ”


(Logical processors can have multiple)


"What if a goroutine needs to read and write files and block?" "Java is very concerned about this problem.


"Simple, let this goroutine and logical processor free association, directly and the system thread binding, wait until the read-write file is completed, go back to the queue of a logical processor." ”



"Then you're the equivalent of implementing a thread scheduler ," Python exclaimed.


"Yes, aren't you playing like that?" "Go," asked the back.


Java, Python,ruby naturally not so play, there is no logical processor this thing, like Java, will be the user space thread directly to the core thread of the system to execute.


"Goroutine Although lightweight threads, how do they communicate?" "asked Java.


"My founder invented a thing called the Channel, which you can understand as a passage through which each goroutine can send and receive data!" ”


Goroutine is actually like a thread implemented in the user space of the program, very lightweight, the space required is very small, the switchover takes place in user space, and the overhead is minimal. This makes it ideal for creating a large number of Goroutine to execute requests concurrently.


4 EXE file

"Gee, this kid has created a hello.exe to run." "Ruby observes very carefully.


The original C old man is also compiled into EXE execution, the discovery of Ruby suddenly aroused everyone's jealousy, because here, whether Java, Python, Ruby, PHP actually have a virtual machine to help them execute the program, they all want to experience the next EXE, Directly on the hardware to perform that flying feeling, but there is no chance ah.


Java has a benefit is the hotspot of the virtual machine, can turn some hot code into machine instructions, on the hardware CPU execution, which has made Java boast for many days, did not think of a direct generation EXE to execute.


Java remembered before C old man said the pointer and memory management of hell, immediately thrown a trump card: "Do you have automatic memory management?" ”


Most of the language in this directory is automatically managed by the virtual machine memory, hear Java so ask, the heart came to some superiority.


"Of course it is!" You just create objects, allocate memory, garbage collection go will do it yourself, my father said, must be C language is not easy to improve the place! ”


These shocked everyone, an EXE program, but also automatic management of memory, we still have to live?


"You see, this EXE file is very big ah." "Someone shouted.


If so, a small hello.exe unexpectedly has more than 1M, how to return a matter?


"Our go language is statically linked by default, and that EXE will add everything you need to run it, so you can copy the EXE to anywhere to run, and it's convenient!" Besides, our EXE file also contains garbage collection, isn't it? ”


Java said: "Ah, I understand, in fact, you have each EXE file contains a similar to the virtual machine runtime, right?" Otherwise how do you go to recycle rubbish automatically, carry on Goroutine dispatch AH. ”


The superiority of the big guy is restored a little bit, at least not to look at people nape.


The night has been deep, Java made a final summary: "The new Go Kid code to write a little Python feel, concise and capable, but bones in the flow of static type of blood." His encapsulation, inheritance, polymorphism and goroutine all seem so different, but always find a little shadow in a language, although it can be compiled into EXE, the performance is good, but there are actually runtime. It seems to have absorbed a lot of language features AH. ”


The crowd agreed, and then the birds and beasts dispersed.

Finish

"or" 2017 first half of the article Essence


yards nong Roll over

Using storytelling to tell the technology


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.