Preview
◆ The development trend of languages must be a combination of dynamic and static, hard and soft
◆ Perl is concise and obscure, Python is elegant and clear, Ruby is exquisite and flexible, and PHP is concise and simple
◆ Perhaps elegance comes from paying attention to details and specifications
◆ After (RoR) is combined with Ruby, it is like a civet cat that immediately sets off the elephant-like figures of Java and .NET
Question
◆ What are the characteristics of Perl, Python, Ruby and PHP?
◆ Why are dynamic languages mostly used as lightweight solutions?
◆ Why is LAMP popular?
◆ Why is Ruby on Rails popular?
◆ What is the development trend of programming languages?
Explanation
" There are four remaining dynamic languages, which we classify as background scripting languages." Colon said and drew a chart -
Listen carefully to the quotation marks: "I remember that you initially classified these languages as C-family static. Languages, non-C-family static languages and dynamic languages. "
Colon explained: "That was divided by grammar, focusing on theory; now it is divided by application, focusing on practice. "
Period immediately thought of: "This division looks like a three-tier architecture - the front-end language corresponds to the presentation layer; the platform language and back-end scripting language correspond to the business logic layer; the system language corresponds to the data layer."
"There are indeed some similarities, but they must not be confused. "Colon reminded, "The three-layer architecture is a logical division in module design [1]; and here is a physical division based on the scope of language application - the front-end language interacts with the user, and interacts with the machine The system language is the system language, and the one that provides services for the frontend and requires underlying system services is the backend language. "
Comma asked: "The backend language is divided into platform language and background script language?"
"This is. It is divided based on program (program) and script (script), static and dynamic. "Colon" explains, "In fact, Perl, PHP, Python and Ruby all have their own virtual machines. In this sense, they are They can also be used as platform languages. But in actual applications, they do not have the same integration cohesion and core role as the Java platform and .NET platform, and are usually used as lightweight solutions. "
Question mark wants to find out: "This is because. Are they all dynamic languages?"
Colon replied: "Theoretically dynamic languages can also undertake large-scale applications, but in practice they are mostly used as glue languages or for small and medium-sized applications. To use a fashionable word, for the time being. They are still mainstream supporting roles or non-mainstream protagonists. After all, there is still a certain gap between them and Java and C# in terms of operating efficiency, type safety, available resources, development tools, and technical support. In addition, they are both 'grassroots' languages. With the strong support of the open source community, it is not the same as the latter in terms of influence."
Exclamation mark speculated: "Maybe in the near future, dynamic languages will also become the mainstream protagonist. ”
“Times change, and it’s hard to predict. But one thing is certain, the development trend of language must be a combination of dynamic and static, hard and soft. "Colon asserted, "On the one hand, static languages represented by Java and C# are grafted with branches of dynamic languages; on the other hand, the interface between platforms represented by Java and .NET and dynamic languages is also gradually expanding. For example, JRuby allows Ruby and Java to call each other, similar to Jython, IronRuby, IronPython, etc. It is also worth mentioning that the most active stage for dynamic languages is LAMP, L-A-M-P. "
Quotation marks continue: "L is Linux, A is Apache, M is MySQL, and P is PHP. These four components form a complete open source network development platform. ”
Colon added: “P can also refer to Perl, Python, or even Ruby. "
Comma joke: "It's a pity that Ruby's 'R' has one more tail than 'P'. "
" In order to justify themselves, some people simply let P stand for 'Programming language', and now all languages are included. Foreigners like to play this kind of acronym word game, especially since LAMP also means "light", which means a bright light in the open source world. They must be even more proud. "Colon said with a smile, "We mentioned earlier that network applications are the most fertile soil for the growth of dynamic languages, and LAMP is a platform built on this soil. As a network platform, LAMP is three-thirds of the Java platform and .NET platform because of its openness and flexibility, rapid development, easy deployment, high configurability, security and reliability, and low cost. It is especially popular among small and medium-sized enterprises. In LAMP, Linux is the operating system, Apache is the web server, MySQL is the database system, and what we are most concerned about right now is the ‘P family of languages’: PHP, Perl, Python and Ruby. "
Question mark suggested: "As dynamic languages, their commonalities have been discussed a lot in the last class. Can you talk about their personalities?"
"Their personalities are extremely distinct: Perl is concise and obscure, Python is elegant and clear, and Ruby Compact and flexible, PHP is concise and simple. Let’s look at the big brother Perl first. It draws on the best of others and combines the structure of the C language, the regular expressions of sed, the associative array of AWK, the list of Lisp and the commands of the Unix Shell. In addition, it also I borrowed a language, do you know which one it is?" The colon suddenly sold out.
Comma guess: "It should be some kind of OOP language."
"There are indeed a lot of C++ shadows in Perl, but its object model was only introduced after 5.0. It is a typical halfway house, and it is far less natural than the previous features. Rather than saying it is a natural development, it is an involuntary adaptation under the influence of the OOP trend. The real deep-rooted reference is natural language. "Colon gave the answer, "We mentioned that Perl was invented. The author, Larry Wall, is a linguist. He believes that programming languages should be as simple and natural as natural languages, easy to read and write, diverse in expression, and eclectic. Perl also has many mottos or philosophies that have changed programming languages. The strict and stereotyped face exudes a strong humanistic atmosphere. "
The exclamation point was silent: "I have seen Perl code, and I can't smell the humanistic atmosphere, but I suspect there is an ether atmosphere - I feel dizzy after looking at it for a while. Huhu."
Everyone laughed.
"Someone implemented the RSA algorithm with just one line of Perl code. Didn't you faint on the spot when you saw it?" Colon joked, "Perl's various magic symbols are like sharp scissors for text cutting. This is its biggest advantage. Perl was originally used by Wall for Unix system management, and its widespread use in CGI also benefited from this. This also gives Perl a strong adhesion. Therefore, there is a saying of 'duct tape on the Internet' [2]. It is also known as the Swiss Army Knife, concise and complex, practical and powerful. However, Perl is too flexible and free, and lacks specifications, which affects the readability and consistency of the program. Safety, cleanliness and maintainability. Of course, those who are not familiar with the language are reading a book. In contrast, Python is considered a strong challenger to Perl, not only because of its natural language. OO design and rich class libraries, and more importantly, it is much more programmer-friendly than Perl. Python also has a series of philosophies called Zen, many of which are diametrically opposed to Perl. For example: Perl believes in doing things. One thing can have many ways, and Python believes that one thing should be best in one way; Perl pursues the expressiveness of the language, and Python pursues simplicity and elegance; Perl likes implicit hints, and Python emphasizes explicitness; Perl emphasizes compactness , Python's emphasis is loose; Perl's syntax and semantics are rich, Python's syntax and semantics are simple and its class library is rich. Perhaps the most unaccustomed thing about Python is its sensitivity to whitespace characters. "
Quotation marks are surprising:" Sensitive? This is really weird. "
Colon is not surprising: "Although it is a bit contrary to habits, it is very consistent with Python's consistent standard and concise style - on the one hand, it ensures a good coding style from a grammatical perspective; on the other hand, Each code block no longer needs opening curly braces or begin/end, which reduces the number of lines of code. By the way, another elegant language, Haskell, is also sensitive to whitespace characters. Perhaps its elegance comes from this. Pay attention to details and specifications. In addition, many people complain that there are too many self-references in Python. However, this is also a manifestation of its advocacy of explicit expression. In general, the main problem of Python is its poor performance. "Exclamation point asked curiously: "What about Ruby? It is said that it will replace Java." "Don't say 'replace' lightly," Colon warned, "Java has not replaced C++, and it will not be replaced. Ruby's replacement is at best a redistribution, but Ruby is indeed a lovely language that combines the expressiveness of Perl with the readability of Python. The most distinctive idea behind Ruby is to pay attention to the programmer's experience when using the language. Beyond the functionality of the language itself. In layman's terms, the handling of a weapon is more important than its sharpness; to put it elegantly, programmers should be given more humanistic care. Take code blocks (blocks) and iterators (iterators) as examples. Although they are not the first of Ruby, their syntax is the most pleasing to the eye. Similar examples abound. Ruby's metaprogramming capabilities are particularly strong and are a reflection of its high flexibility, but not everyone likes this style. Ruby has two main weaknesses: one is similar to Python and needs to be improved in performance; the other is that its threads are managed by user space instead of kernel space [3] and cannot be fully utilized. Multi-core or multi-CPU. What really made Ruby popular was the success of the web application framework Ruby on Rails (RoR), which also gave birth to the Groovy language and the Groovy on Grails framework on the Java platform. The CoC (Convention over Configuration) and DRY (Don't repeat yourself) principles and the MVC architecture pursued by RoR seem to have no new ideas, but when combined with Ruby, it is like a civet cat that immediately sets off Java and .NET. An elephant-like figure. "
The comma is a little skeptical: "The framework has actually made the language popular. Is the framework really so important?"
"If there are few dynamic pages in the web application or the business logic is not complex, the value of the framework is not great. In the past, CGI programming was to embed HTML code into Perl and other codes, just like Servlet in Java; PHP simply inserted PHP code into HTML code, just like early JSP. There is no MVC, no three-tier architecture, and no ORM. But -" the colon dragged a transition tone, "once the business logic becomes complex and the number of developers increases, manual workshop-style programming begins to be stretched, and the introduction of the assembly line of the framework to improve productivity is the general trend. ”
Period is puzzled: "I think there must be many frameworks in Perl, Python and PHP, and there are so many frameworks in Java. Why does RoR stand out?"
Colon makes an analysis: "At the time of web2.0 and agile When the concept of agile development becomes popular, RoR combines AJAX and Ruby to become an excellent response. There were many web application frameworks in the past, but before RoR, there were not many lightweight package solutions. Catalyst in Perl, Pylon in Python, and CakePHP in PHP should be imitated. Therefore, the timing of RoR can be said to be neither early nor late. In addition, Perl and PHP have become too popular. There is a lot of historical baggage, and people are used to weaving presentation logic and business logic together. As for Java enterprise solutions, there are too many frameworks and more combinations, making it more difficult to choose, even if the most common lightweight SSH is used. Struts+Spring+Hibernate) combination is much more complicated to maintain than RoR."
The exclamation mark became more and more worried: "Look at this, Java is still dangerous!"
"It's too early to say," Colon disagreed, "First of all. RoR has yet to be further tested. At present, it cannot be compared with Java in terms of application breadth and depth. Secondly, Java still has many advantages in performance, security, etc., and these are particularly important for large and critical applications. In small and medium-sized web applications, RoR is far behind PHP. "
The question mark continued the topic: "Why is PHP so popular?"
"Because it is simple and focused," Colon answered simply, "and Python. Unlike Ruby, which was positioned as a general-purpose language from the beginning, PHP was born specifically for the Internet. Similar to early Perl, PHP initially functioned as a text filter, except that Perl mostly dealt with file streams, while PHP mostly processed file streams. Processing socket streams. PHP has a simple syntax and is tailor-made for network applications. It is understandable that it is popular among network developers, but it is not perfect. Variable names are case-sensitive but function names are not; function naming rules are inconsistent; namespace and unicode are not supported [4]; like Perl, its object model is not innate and was not truly perfected until PHP 5; insufficient support for threads ;Compared with Perl, Python and Ruby, its functions are slightly thinner, etc. "
Quotes suddenly came to mind: "I remember you mentioned in the first class that PHP can also be used for desktop applications."
"Not only PHP. , Perl, Python and Ruby can all be used as front-end languages to develop command line or graphical interface applications. Similarly, VB, Delphi and JavaScript can also be used as back-end languages. Modern programming languages not only have their own expertise, but also develop towards generalization and versatility in order to strive for more living space. Just imagine, are modern programmers not like this?" At this point, Colon stopped the topic, "This is the end of the brief review of languages. There are many interesting and useful languages, so I won't comment on them one by one here. We see that each programming language has its own unique conventions and philosophies, which together with the programming paradigm form the programming style of the language. The deeper the understanding, the stronger the sense of programming language, the more seamless the integration of thinking and language, and gradually moving from the kingdom of necessity to the kingdom of freedom. "
The comma is full of longing: "Is that a state where man and sword merge into one?"
"Maybe the integration of man and machine is more accurate. Programmers can't just use one kind of weapon. "Colon deliberately picked up his words, "Now please everyone write a speech about this lesson. ”
Everyone pondered for a moment and then wrote in unison——
Exclamation mark——There is no best language, only the most suitable language.
Comma——There is no bad language, only bad programmers.
Question mark - No language is omnipotent, knowing only one language is absolutely impossible.
Quote marks - Abolish religious belief in language and establish philosophical thinking about language
Period - Programming is about people. The process of finding the best balance between the brain and the computer.
After reading it, Colon was very happy and slapped five flattery notes with one palm: "It's so wonderful! Every word is exquisite and every sentence is perfect." It is hereby decided that the reward for you is to end get out of class immediately!"
Everyone happily accepted the reward and left.
Interruption
[1] There are two types of three-layer architecture, one is three-layer architecture, and the other is three-tier architecture. They are often used interchangeably, but they are actually different: the former is only divided logically, while the latter is also divided physically - modules at different levels run on different hosts
[2. ] In many places, it is translated as "conveyor belt" or "conveyor belt", because duct means "conveyor pipe" or "conduit", so it is taken for granted that this means that Perl plays a transport role on the Internet. However, 'duct type' specifically refers to 'duct type'. A kind of universal sticky tape, used as a metaphor for Perl's adhesive force.
[3] This type of thread is called a green thread, also known as a pseudo-thread. It is said that Ruby 2.0 will support native threads. Threads (native thread).
[4] PHP will support namespace in 5.3.0 and unicode in 6.0
Summary
◆ Compared with the Java platform and .NET platform, dynamic languages are lightweight and flexible, and have high development efficiency. However, the integration cohesion is not enough, and there are also certain gaps in operational efficiency, type safety, available resources, development tools, technical support, and influence, so it is usually used as a lightweight solution
.◆ LAMP is a network development platform composed of Linux, Apache, MySQL and scripting languages including PHP, Perl, Python or Ruby. It is open and flexible, rapid development, easy deployment, highly configurable, safe and reliable, low cost, etc. advantage.
◆ Perl is concise, complex, powerful, flexible, free, obscure, and expressive, but has poor standardization, readability, consistency, neatness, and maintainability.
◆ Python is elegant and standardized, concise and clear, easy to learn and use, and has rich class libraries, but it is slightly less efficient. Some people don’t like its sensitivity to whitespace characters.
◆ Ruby’s syntax is exquisite and highly flexible, combining the expressiveness of Perl and the readability of Python. It pays special attention to the experience of programmers, but its performance and threading model still need to be improved.
◆ PHP is simple, specific, practical and popular, but compared to the other three languages, it is slightly lacking in syntax and functionality.
◆ RoR is a lightweight package-style web application solution, which is composed of good design (MVC architecture and CoC, DRY principles) plus good language (Ruby) at a good time (web2.0 and agile A good framework created when development was popular).
◆ Static language and dynamic language are gradually integrating from language features to running environment.
◆ Programmers should, like programming languages, not only have their own expertise, but also develop towards generalization and versatility.
◆ Programming language conventions, philosophical concepts, and programming paradigms form the programming style of a language.