Compare Java vs. python

Source: Internet
Author: User

Compare Java and Python

Compare Java and Python
April 18, 2011
1. In terms of ease. Python is far simpler than Java.
2. Development speed. Python is much better than Java
3. Speed of operation. Java is much better than standard python,pypy and Cython can chase Java, but neither is mature enough to be able to do the project.
4. Available resources. Java is a handful, and Python is very rare, especially Chinese resources.
5. Degree of stability. Python3 and 2 are incompatible, resulting in some degree of confusion and a large number of class library failures. Java because there are enterprises behind the support so much more stable.
6. is open source. Python is completely open source from the start. Java is developed by Sun, but now has the openjdk of gun available, so don't worry.
7. Compile or explain. Both are explanatory.
I understand that C is like manual pavement (compiled language), Java and Python (interpreted language) are like automatic gears. The fastest car to run is manual, but for those who are not good, it is quicker to open the automatic file instead.
There is an article in kno about choosing a programming language, "Determine your needs first", not by the simple or complex language. Only when you can write a program that you really think is useful can you get a sense of satisfaction and learn to continue.
So what kind of environment does Java and Python apply to respectively? It can be seen by sourceforge.net:
The most famous and tried-and-tested common applications are basically written in C + +. such as Emule,7-zip,winscp,filezilla and so on.
Part is developed by Java, such as the most famous OpenOffice.
Python writes very little, such as Pidgin,firebird.
The number of development languages (how many programs are developed by this language) is as follows:
# java46,202
# c++36,895
# php30,048
# c28,075
# c#13,476
# python13,379
# javascript11,285
# perl9,216
# Unix shell3,869
# delphi/kylix3,548
# Visual basic3,186
# Visual Basic. NET
Many frameworks and libraries are also in the same list as application software, so it's fairly fair.
As you can see, Java is the most widely used language in both GNU and commercial areas. C is mainly used to build the system bottom. C + + and Java are used to build an intermediate application layer. If the resources are sufficient, then C + + development will be selected to run speed, otherwise it will be developed in Java, in order to develop speed. Python is superior to Java in every way, and is a second-generation language. Arguably the most controversial is its speed, pure python is much slower than Java, and there is no commercial support behind it, and stability is highly criticized. So far, Python has been used primarily as a glue language to bond other languages (mainly C/s) to class libraries, at the commercial level. In the GNU field, it is mainly confined to small-scale applications and personalization applications. and reverse engineering (hacker) applications.
Why Java is heavily used on the server side, but less in the client. Is the amount of computing used on the server side less? I think it is acceptable to compare the speed of C++,java. Unacceptable is the JRE platform, and the moment the JRE platform is launched. I once thought that Java writes the program performance is low.
Python users often take the point of saying that Python is not slow because Python runs a lot of C libraries, and C is fast. In turn, this reflects the fact that the glue language, any language can call C library, so more valuable? If a library is entirely made up of Python, then it runs efficiently ... Don't say it or not. Programming can't always use someone else's library.

----

The Python programming language needs constant learning in its current use. Let's take a closer look at how we can better learn the relevant knowledge. Lately I've been looking at a GUI application code based on Wxpython, about 45.5KLOC, and that doesn't include the libraries it uses (such as twisted).

The code is written by Java developers who are unfamiliar with python, so it has serious performance problems (such as 30 seconds of startup time). When I checked the code, I found that they wrote a lot of things that make sense in Java but are hard to accept for the Python programming language. Not because "Python is slower than Java", but because there are more convenient ways to accomplish the same goal in Python, even in the unlikely event of Java.

So, the sad thing is that these guys are doing a lot of work, and the code they write is much slower than it should have been in the Python programming language. Below, let's look at some examples:

Static methods in Java cannot be translated into Python's class methods. Well, of course, he can have the same effect in some ways, but the purpose of the class method is actually to do something that is usually not even possible in Java (such as inheriting a nondefault default function). Java static methods idiomatic translations are often translated into a module-level function rather than a class or static method. (and static constants should be translated into module-level constants.)
This is not a performance problem, but if a Python programming language programmer wants to invoke Foo.somemethod, he will be driven mad if he is forced to use Foo.Foo.someMethod like java. It is important to note that calling a class method requires an extra amount of storage space, and calling a static method or function is not required.

By the way, there are also those Foo.Bar.Baz's attribute chains that are not counted by themselves. In Java, the names of these dots are found by the compiler, and are not considered at all when running. In Python, the lookup process occurs at run time, so include each point. (in Python, keep in mind that "tiling is better than nesting", although it may be more about "readability" and "simplicity than complexity" in terms of performance).)

Do you want to use the switch statement? The Python programming language will be a hash table, not a bunch of if-then statements. Do you want to use a bunch of if-then statements that are not switch statements in Java and that have strings involved? It will still be a hash table. The CPython dictionary is implemented using a hash table that is considered one of the best performance in the field we know. Your own code is no better than this, unless you are Guido, Tim Peters, and Raymond Hettinger's illegitimate son, and are genetically enhanced.

XML is not an answer. Nor is it a problem. Now use regular expressions to explain Jamie Zawinski, "some people, when he encounters a problem, will think ' I know, I want to use XML. ' Then they have two problems. ”

This is a different situation in Java, because XML is flexible and resilient compared to Java code. But compared to Python's code, XML is an anchor, a nuisance. In Python, XML is used to work together, not your core function, because you don't need to do that. In Java, XML may be your savior, because it allows you to implement specific areas of language and "without coding" to improve the adaptability of your application. In Java, avoiding coding is a big advantage, because coding means recompiling. But in Python, it's usually easier to write code than to write XML. There is also a lot of Python processing code much faster than processing XML. (not only this, you have to write the XML processing code, and Python has written it for you.)

If you're a Java programmer, you can't use instinctive perception to consider whether you want to use XML as part of your Python core application. If you are not implementing an existing XML standard or creating some kind of input, output format, or creating an XML editor or processing tool for information interaction reasons, do not do so. Don't do this at all. Don't even think about it. Now, get rid of that XML schema and liberate your hands! If your application or platform is to be used by Python programming language developers, they will only thank you for not adding the burden of using XML to their work.

(The only exception to this is if your client (your target audience) really needs to use XML for some reason. It's like they're refusing to learn python, but if you use XML, they pay you, or you're going to give them a great GUI to edit XML, and that's the XML GUI that someone else wrote, and you get the right to use it for free. There are also some very rare architectural reasons that require XML. Trust me, they won't apply to your program. If in doubt, explain your use case to a senior Python developer. Or, if you're thick-skinned and don't mind being laughed at, try explaining to a Lisp program why your program is using xml!.

Getter and setter are demons. I should say it's the devil, it's the devil! The Python programming language object is not a Java Bean. Do not write getter and setter, but also built them into the "properties". It doesn't make sense until you can prove that you need a more complex feature than a simple access, otherwise, don't write getter and setter. They are a waste of CPU time, and more importantly, they are a waste of the programmer's valuable time. Not only for people who write code and tests, but also for those who want to read and understand them.

In Java, you must use getter and setter, because public fields do not allow you to change your mind later to use getter and setter. So, in Java you'd better avoid these "chores" in advance. In Python, this is silly because you can start with a common feature and change your mind at any time without affecting any of the customers in this class. So don't write getter and setter methods.

Code duplication is often an unavoidable scourge in Java, and you must often write the same method over and over again with only a little bit of change (usually this is because of a static type constraint). It is not necessary to do this in Python, and it is not worth it (except for the few specific occasions where you need to inline some functions that require performance). If you find yourself writing the same code over and over again and with little change, you need to learn about closures. They are actually not and are so horrible.

    • A big summary of Python programming skills
    • Python programming language for simple reading flexibility
    • Mastering the Python programming language in a short time
    • Description of the history of the Python programming language
    • Description of the Python programming language

That's what you're going to do. You have written a function that contains a function. The function inside here is the template of the function you want to write over and over, but it adds a function to use the variable for different situations. The external function requires the variable that was just raised as a parameter, and returns the internal function as a result. Then, every time you write another slightly different function, you just call the external function and assign the return value to the name you want the repeating function to appear. Now, if you need to change the way you work, you just need to change one place: the template.

In the application/platform I have seen, only a trivial program has used this technique, removing hundreds of of lines of overloaded code. In fact, because developers use special boilerplate files to develop plug-ins for this platform, it saves a lot of code for third-party developers and makes it easy for programmers to learn.

This is just the tip of the iceberg of the Java->python programming language paradigm shift, and now I can change it right without delving into the details of the program. In essence, if you have used Java for a while and are unfamiliar with python, then you should not trust your instincts too much. Your instincts have been tuned by Java, not python. To take a step back, the most important thing is to stop writing so much code.

To do this, make yourself feel more in need of Python. Pretend like Python can do any magic wand you want, and you don't have to be a bit of a force. Ask, "How does Python solve my problem?" What features of the Python language are most similar to my question? "If you have some sort of fixed form for what you need, you'll be amazed. In fact, this phenomenon is so common that even in very experienced Python programmers, the Python community has a name for this phenomenon. We call it "the Guido Time Machine", because before we have mastered it, we usually seem to get what we need as if it were the only way.

So, if you don't feel more productive than using Java at least 10 times times when using the Python programming language, you'd better make a change, don't you forget to use time machine! (Chances is good that you ' ve been forgetting (And if you still miss your Java IDE, you can think: because you're writing a Python program that's much more complicated than what he needs.)

Compare Java vs. python

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.