Python and Java hard disk night conversation

Source: Internet
Author: User

This is a programmer's computer hard disk, in a directory called "learning" has lived two small programs, one called Hello.java, Java Boy, the other is called hello.c, that is, C old man.

C Old man's fate is more sad, programmer master think C language pointer is too complex, memory management is too difficult, really is not learn, give up, by the way to delete it!
The Java kid misses it, because C old man is old-fashioned, but knowledgeable and teaches him a lot of things. This evening, the programmer on a whim, decided to mix with Python face familiar, so hello.py also stay in this directory. After a brief greeting, to ascertain the actual situation of each other, they will see the other side is not pleasing to the eye.
They both understand that a mountain can not be two of the tiger's truth, if not to drive away, it is difficult to escape by the master deleted, to the garbage collection station of the tragic fate.

Thinking of this layer, Python became the first to take the lead, it Pille and do not smile Pat Java shoulder: "Java brother ...."
Did not expect Java to immediately counterattack: "Who is your brother?" You have to call me Big Brother Java. ”
Python froze a bit: "Don't you know I was born in 1991, 4 years older than you?" ”
Java grunted: "Although older than me, then you are not very good?" ”
Python said: "More than 10 years ago I may not be well, perhaps not as you, but that Lana, with the advent of artificial intelligence, the use of my people more and more, do not believe you go to see the tiobe leaderboard, my rising momentum is very fierce ah. ”
Java disdain to say: "Cut, grow to now not still a fraction of Lao Tzu." ”
Python was angered, he decided to take Java's cumbersome syntax, pointing to Java, said: "Look at you, a HelloWorld is so troublesome," the long-winded. ”

public class Hello{public static void Main (string[] args) {System.out.println ("Hello world!");}}

Then he pointed to himself and said: "You look at me, how concise!" ”
Print ("Hello world!") Java is silent, in fact, the heart is very envious.

"And how easy it is for me to open a file, can you?" ”

f = open ("C:\\tmp\\hello.java", "R") print (F.read ()) F.close ()

Referring to Io, theJava Heart has inexplicable pain, its own IO module design is so elegant, but why people do not like to use it?

They always say that they can't remember how to write, it seems to change.

See Java is still silent, unable to fight back, Python is very proud, play should be left to chase conqueror Spirit, copy the machine gun, continue to shoot: "Look at my default value of this function, do you have?" ”

As soon as Java saw the code, it came to mind: "Your self is about the same as mine, but why do you have to be a parameter?" How ugly!! And this code indentation, incredibly with a space, an inattentive error, I really do not know how you think. ”

Python did not expect Java this guy to launch a counterattack from this place, for a moment speechless. Just heard Java asked: "Some people say you python variables are not type, right?" ”
Nonsense How does my variable have no type? I am a dynamic language and the type will only be determined at run time. ”

var = 3var = "Hello World"

"You see, this variable var first assignment, the type is an integer, the second time it becomes the string Hello World, you can not do it?" ”

Java laughs without words.

Python continues: "Due to my dynamic nature, I can easily implement duck Typing:"

Class Duck:def Help: Print ("quaaaaaack!") class Person:def Help: Print ("Help me!") def in_the_forest (x): X.help () in_the_forest (Duck ()) In_the_forest (person ())

"See no, this duck and person does not implement a common interface or inherit the same class, but can still be passed as a parameter to the In_the_forest function, is not very flexible?" You're not supposed to be, are you? Ha ha! "Python triumphantly.

Java understands that this is really a good feature and it's very refreshing to write code.
But he is not a vegetarian, and suddenly grabbed the life of the door: "Write it is very cool, read it is not good, I ask you, suppose the human see in_the_forest This function, he knows the type of parameter x is what?" is person? Is bird? Or something like that? "
" Also, "Java continues to criticize," Human want to reconstruct the person function of the help method, such as change to SOS (self), your IDE can be safely reconstructed? I'm afraid it's not easy, huh? Suppose the human flesh refactoring is wrong, and you can only find errors at run time! "
" Dynamic temporary cool, reconstruction crematorium. Java cooled down to the last knife. The
is a static type, the variable type can be determined at compile time, the IDE's powerful IntelliSense feature, the automatic security refactoring function has been proud of the selling point.
"What are you afraid of," python pretend to be indifferent, "Humans have unit tests to make sure, and besides, My code is very compact, the row top you 10 rows, is to change up is also much more convenient. "
Although the surface is indifferent, python has been secretly scared: a careless by this kid with the pit, I have to find a way to shift positions."
Java begins to organize a defensive counterattack: "Have you heard of AOP?" Huh? Heard, then you say, can you achieve AOP? "
Python in the heart of the music: this kid is really ignorant, always think that only spring has AOP, do not know for our dynamic language, the realization of AOP that is simply a breeze."
Python deliberately asked: "AOP is nothing more than the existing code to enhance, dynamically add some security, log, transaction and other ' facets ' function, I know you Java class, once loaded can not be modified, how to implement code enhancements? "
Java proudly said:" We can generate new classes at run time, let the newly generated class inherit the old class, or with the old class implementation of the same interface, such as ASM tools, can manipulate bytecode to create new classes, weaving into those ' slices ' code, this work is so delicate and breathtaking. "
Python said:" Haha, I tell you, you have to do it, we python is different, we are dynamic language, can be at runtime to enhance a class: Add a method, replace the method, do not operate at all so low byte code, I give you a simple example: "

Class Order:def Save (self):p rint ("Save Order") #把老的方法引用保存起来old_save =order.save# defines a new method that calls the old method # and adds the log def before and after the method The save_with_logging (self):p rint ("Logging start") the Old_save (self) print ("Logging End") #把新方法赋值给Order类的save方法Order. save= save_with_logging# Test T=order () t.save () Output: Logging Startsave orderlogging End

Java looked at this piece of code, jaw-dropping, gripped, a class of methods at run time unexpectedly can be replaced! It's really scary! In your own world, this is something that you don't even think about. But isn't it easy to implement an enhancement to a class? There is no need to modify any bytecode.

Python sees the Java kid being intimidated and continues to press: "We python want to implement AOP, but also can use adorners, Meta class and many other ways, I will not give you detailed." ”

The Java mind is still thinking about the replaced function, it seems in Python, the function is an object, otherwise how can be replaced? Since it is an object, it can certainly be passed as a parameter or as a return value. Think of your lambda expression, essentially an implementation of an interface, the equivalent of a dance in chains, with a sigh in my heart.

It seems that I have to find the killer to completely get this arrogant Python kid, Java thought, but his dynamic language is really too flexible, right, virtual machine! My virtual machines have evolved over the years to withstand the toughest tests in the industry, with robust performance, and the ability to discover "hot" bytecode in the process of interpreting bytecode execution, and then compiling cost-effective code execution at very fast speeds. And my garbage collection mechanism is also very perfect.

Java threw this big kill device out, Python's expression immediately is not right, because its own virtual machine performance is not very good, but Python is very cunning, he immediately shifted the topic: "Now the speed bottleneck is not CPU, but IO, you know the network and database how slow the goods?" Relative to their speed, we don't have to be slow ... " Python successfully pulled two people into the same position.

Two guys you came to me, arguing all night, their voices grew louder, the next door to the "Graduation design. docx" angrily ran over scold: "In the end still let me sleep?!" ”

Two people hurriedly down the voice, continue to fight, but no one can completely prevail, finally feel that we really have strengths, but the scope of application is different.

Suddenly, a bright light came in, the eyes of the two people stabbed compelled, the original day has been big bright, the owner opened the folder, selected Hello.java and hello.py, and then did a strange operation.

Java and Python only felt dizzy, and in a twinkling they were carried to a place where rubbish was everywhere.

The shaggy-haired C-man sat on an ebook called "C and the hands" and said to them, "Hello, Welcome to the Recycle Bin." It seems that the host has a lover again, the two of you also abandoned. ”

Python and Java hard disk night conversation

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.