Why do I recommend Python [1]: Python as a scripting language

Source: Internet
Author: User
Document directory
  • ◇ High-level abstraction and Encapsulation
  • ◇ Less code
  • ◇ Better readability
  • ◇ More gentle learning curve
  • ◇ Interactive
  • ◇ Versatility (cross-domain)
  • ◇ Popular enough
  • ◇ Strong functions and rich Libraries
  • ◇ Cross-platform
  • ◇ Integration and interaction with other languages

I think that, among all the features of PythonScript Language(For specific definitions, see "Here") is its primary feature. Therefore, in this series of posts, I will first confuse python as a script language. What are the advantages?

★Where is the scripting language?

To talk about the advantages of python as a scripting language, we must first talk about the advantages of the scripting language. In general, when we mention "scripting language", it emphasizes the features of its interpretation execution (although some scripting languages also support Compilation ). Therefore, the advantages described later are mostly compared with compiled languages.

◇ High-level abstraction and Encapsulation

Most scripting languages provide high-level abstraction and encapsulation. For example, many scripting languages have built-in string processing capabilities and regular expressions (typically Perl ). Many other scripting languages have built-in advanced data structures. For example, Python supports linked list (called list in Python), Ding (called dict in Python), and tuples (called tuple in Python) at the language level ).
With these high-level encapsulation, you can write code, which is especially simple and refreshing. For example, to double a list in Python, you only need to write [1, 2, 3] * 2 to get [1, 2, 3, 2].

◇ Less code

Thanks to high-level encapsulation, script language code is much less than compiled languages when the same functions are completed.
For example, if you want to print the content of a text file, if you use Java to implement it, you can write up to seven or eight lines of code in a normal way (leave all the code hard to one line and we will not discuss it ); python supports three or five elements.
For example, capture a Web page with a given URL and implement it in a standard library provided by python. There are about 3-5 lines of code, the amount of code will increase a lot (the specific amount of code to write depends on the HTTP library you use ).
After the amount of code is small, at least when you read the code (whether by yourself or by others), you can press the page flip key many times, greatly extending the keyboard life, by the way, the strain on the fingers is reduced.

◇ Better readability

Of course, extending the lifetime of the keyboard is not critical. The key is that, when the amount of code is small, it will (usually) help improve readability. Readability is exactly one of the strengths of Python.
For exampleSyntaxIt enforces the scope indent (this is one of the places I like python very much ). As a result, even the Python code written by the novice program has a uniform indentation style. In contrast, the code written by C or C ++ is not so neat.

◇ More gentle learning curve

Generally, the syntax of the script language is simple and foolish. Therefore, it is much easier to get started. People with some programming basics can get started in a short time.
For example, the C ++, Java programmers, and some testers can all be within one week (programmers do not need one or two days) understand the python syntax and use it to write some auxiliary gadgets. It greatly reduces the saliva for training.

◇ Interactive

Many scripting languages support interactive code writing. That is to say, each time you write a line of code, the interpreter will execute one. This allows you to quickly detect input errors and view execution results immediately.

★What are the disadvantages of the scripting language?

As mentioned above, what are the disadvantages of the script language? The main drawback is poor performance. This is the heavy price they have paid for the above advantages. Fortunately, today's computer hardware is advancing by leaps and bounds, and the disadvantages of poor performance are getting less and less obvious.

★Comparison between Python and other scripting languages

Some may ask, there are many scripting languages. Why do I prefer Python alone? To answer this question, I use Python and some common scripting languages for some superficial comparisons.
In view of the fact that the subsequent content is easy to cause a language war, I hereby declare that although I will mention the shortcomings of some languages relative to Python, I have no attempt to belittle these languages, I have no intention of proving that python is better than these languages! I just want to explain how I made a trade-off in several scripting languages?
In addition to Python, there are many common scripting languages, such as PHP, JavaScript (JS), Perl, and VBScript (vbs) ruby, Bash, Lua, and Tcl (do not mistakenly think it is a household appliance manufacturer :-)...... how does Python stand out from these scripting languages? When selecting, I mainly consider the following points:

◇ Versatility (cross-domain)

Because I am too lazy to learn too many programming languages. Therefore, I want to be familiar with a scripting language and try to help me deal with different fields as much as possible. From this point of view, I will not choose PHP (too focused on the Web server), JS (too focused on the Web Client), shell scripts such as Bash (too focused on system management ).
Python is a common scripting language with a wide coverage. For example, python can easily handle web development, desktop GUI applications, system management, network applications, and many other fields.

◇ Popular enough

I have introduced the importance of "popularity" in "how to choose an open source project. The higher the popularity and the more popular it means more resources (including documents and related software). When you encounter problems that need to be solved, more people can consult.
For more information about the popularity of programming languages, see the ranking of tietong (although tietong does not fully reflect the popularity, it can be used as a reference at least ).
For example, TCL, powershell, groovy, and javafx all ranked out of 30 (as of January 1, August). I feel that few people are using them, so I will not consider them for the moment. Python's ranking in recent years has risen all the way (see "here"). By August, it had ranked 6th in the rankings. Although Perl is also at a high position, its ranking has declined all the way in recent years (see "here "). I personally think that their popularity is not optimistic.

◇ Strong functions and rich Libraries

Another important thing is whether the function is powerful enough. At this point, both Python and Perl are powerful. As for how powerful python is, I will introduce it in my subsequent post "python as Swiss Army Knife.
On the other hand, JS, Ruby, TCL and other languages are slightly inadequate (of course, they may also be ignorant ).

◇ Cross-platform

Because I usually use different operating systems, and the products I take charge of are also cross-platform. Therefore, I have cross-platform scripting requirements. When it comes to cross-platform platforms, such as vbs and bash streams will not be considered.
In fact, many scripting languages support cross-platform. Python is more outstanding in this regard. It not only supports mainstream operating systems, but also supports some unpopular (such as the old DoS) and handheld devices (the python runtime environment can be installed on your smartphone ).

◇ Integration and interaction with other languages

At last, it is estimated that most people will not be too concerned about this. Because I want to introduce script technology into my company's products, I have to consider the ability to integrate the script language with other languages. A highly integrated scripting language can be used as glue in a complex system to bond different modules (for details about glue language, refer to "Here ").
In this regard, both Python and Ruby are doing well. Their integration with Java includes Jython and jruby; and the integration with the DOTNET platform includes ironpython and ironruby. As for the commonly used C ++, python is better integrated than Ruby. For example, there is a boost. Python sub-library in the C ++ community's well-known boost Library (see "here "). For details about how to use python as glue, I will introduce it in the subsequent post "python as glue language.

★Summary

Based on the above considerations, I finally chose python as the script tool for daily use, and introduced it into the company's products as the glue between modules.
After talking about all aspects of python as a scripting language, let's talk about what it is about as a dynamic language in the next post.

Return to the directory of this series

Copyright Notice
All original articles in this blog are copyrighted by the author. This statement must be reprinted to keep this article complete, and the author's programming preferences and original addresses in the form of hyperlinks should be noted:

Http://program-think.blogspot.com/2009/08/why-choose-python-1-script.html

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.