Home > Backend Development > PHP Tutorial > Comparison of similarities and differences between Python and ruby

Comparison of similarities and differences between Python and ruby

小云云
Release: 2023-03-17 18:00:01
Original
1931 people have browsed it

Python is an object-oriented, literal computer programming language. Python syntax is simple and clear, and it has a rich and powerful class library. Ruby, a simple and fast object-oriented (object-oriented programming) scripting language. In this article, we will share with you the similarities and differences between Python and ruby.

1. Similarities and Differences Comparison Selection

1. The similarities between python and ruby:

* Both emphasize simple syntax and have more general expressions. Python is indentation, Ruby is basic-like expression. All symbols have been greatly reduced.

* are all dynamic data types. All have rich data structures.

* Both have c language extension capabilities and are portable, which is better than perl's portability. They can also be used as embedded languages.

* They are all object-oriented languages ​​and can be used as development tools for large projects.

* All have rich library support.

* Also has the most permissive copyright license, except that some tools belong to the GNU world.

* All have lisp-specific eval functions, and they can also take functions as parameters.

* There is also a Ruby-specific editor with a graphical interface.

* All have extensive support from the c library. Such as qt, gtk, tk, SDL, FOX, etc., ruby ​​plans to implement the SWIG interface.

* All have complete documentation.

2. Advantages of ruby ​​compared to python:

* It has the function of regular expressions and embedding HTML. Python also has regular expressions, but they are not as convenient and widely used as ruby. Python's embedded HTML project has just started. Ruby also has the Apache mod module. Ruby itself also implements many unix tools, such as rac and doctools. Closer to linux than python.

* A more complete object-oriented syntax than python.

*Ruby’s entire library is a structure with class inheritance.

* Its basic data types and operators can be overloaded.

*Ruby’s main functions are implemented through object method calls, not functions. Python is also developing in this area, but it is not as thorough as ruby.

*Ruby classes are more standardized single inheritance, and also implement concepts such as interfaces.

* Python can implement conditional statements and loop statements in lists, while Ruby uses "blocks" to implement this function, which is more flexible and versatile than Python.

*Ruby has conditional statements, loop statements, etc. in a complete functional manner similar to lisp. Sentences are more expressive.

* Comes with some unix tools, such as rac, etc.

3. The shortcomings of ruby ​​compared with python:

* The biggest shortcoming is precisely caused by the power of ruby. It doesn't have the simplicity of python. The more complex object-oriented syntax, the introduction of "block" syntax, the introduction of regular expressions, and some abbreviation tags all increase the complexity of the language.

* Python's indentation expression is more pleasing to the eye than ruby's basic expression. The eyes full of ends in ruby ​​programs are uncomfortable. Of course, Ruby considers the end method to be more advanced than Python.

*Ruby does not yet have Python's "introspection" capability and the ability to generate documentation from program files.

*Ruby does not have internationalization support. Internationalization support is in Ruby's plans. This is because ruby ​​has a shorter history than python.

*Ruby has nothing similar to jython.

4. The choice of python and ruby ​​languages:

From the perspective of simple and good, choosing python is right. Python is suitable for people looking for a simple language, which is likely to cause Python to be more popular and therefore have more support. But if you want to pursue more powerful syntax functions, ruby ​​is a good choice. Because the philosophies of ruby ​​and python have many similarities, start with python first, and try to use python. If python is not strong enough, you can look for ruby.

The comparison between ruby ​​and python is like the comparison between Wubi and Pinyin input method. Pinyin is no problem as an entry-level input method or as a long-term input method. Wubi is suitable for more demanding situations. If you are pursuing performance, you might as well learn ruby. Those who are interested in programming languages ​​and want to understand various programming concepts will also be excited to learn Ruby.

2. Both have their own characteristics:

1. Python is simpler in syntax, while Ruby is sexier

Python’s syntax is relatively different from other scripting languages It is said that there are not many fancy places and it seems a bit rigid. In fact, the orientation of Guido's design language can also be seen from Python's forced code indentation. The rigid syntax is that it is not easy to create sexy things, such as frameworks like Rails. In addition, Python cannot do things like DSL. However, the other side of the rigid syntax is that it is more standardized and is relatively more suitable for software development. Engineering requirements make it easier to organize large-scale teams for development.

Ruby’s syntax is very flexible. The starting point of Matz’s design of ruby ​​is also for coding for fun. Therefore, you can use ruby ​​to play many tricks. With enough skills, you can use Ruby to write a DSL that approximates natural language. For programs For programmers, playing ruby ​​is indeed a lot of fun. The birth of Rails in the ruby ​​community, rather than the birth of the Python community, is definitely directly related to the programming language. However, the other side of ruby's flexible syntax is the diversity of programming implementation styles, which is a challenge for collaboration and management of large-scale teams.

2. Python’s parser implementation is more mature and the third-party library is of high quality

Although the Ruby 1.9 parser has achieved great performance improvements and many new features, from the perspective of source code implementation, it is basically by patching the Ruby 1.8 source code to increase the functionality. . In terms of the structure of the source code, the implementation of Ruby is too old. It is difficult to expand Ruby, and we can only continue to patch it. This is why there are so many new Ruby parser implementations emerging in the Ruby community. To a large extent, this has restricted the development speed of Ruby. Relatively speaking, the Python parser is more mature and stable.

In terms of the number of third-party libraries, Ruby is not less than Python, but Python has significantly more high-performance, high-quality and proven third-party libraries than Ruby. In fact, there are many Ruby third-party classes. The libraries are not very mature, so this has greatly restricted the development of Ruby.

3. Python has a wide range of application fields, while Ruby is currently mainly limited to the Web field.

Python has a very wide range of application fields. In addition to web development, it is also widely used in server back-ends. High-performance server implementation, various intensive operations on the server backend, full-text retrieval, various text processing, system management, etc. In addition, wxPython is also a very mature cross-platform GUI framework in the desktop application field. For some special applications, such as calling the operating system kernel API, Python can also complete it very well. For example, the real-time synchronization solution for a large number of small files is achieved by using Python to directly call the inotify feature of the Linux Kernel. So it can be said that Python is the Swiss Army Knife of software development, it can do anything.

Precisely due to the constraints of the Ruby parser and Ruby class library, the application of Ruby is mainly limited to the field of web development. At present, the application of Ruby cannot be extended to many places outside the field of web development. It is said that Douban considered Ruby on Rails in the early days, but because Ruby could not do other things and Python could do everything, it finally gave up Ruby and chose Python.

4. Ruby is the king in the Web field

As Internet applications further penetrate into various fields of software development, in fact, web development accounts for an increasing proportion of the development of the entire software industry. Although Ruby is very limited in other fields, it is the absolute king in the field of web development. The Rails framework is far ahead of any potential competitors. So although Ruby may have problems of one kind or another, when it comes to web development, Rails is almost the undisputed only choice.

Although Python is very comprehensive, it is not outstanding in the field of web development. Although there are many web frameworks, none of them can really take the lead. Although Django is relatively popular in the Python community, it also has flaws in many aspects. Today's Internet applications are often mixed programming in multiple languages. Ruby's shortcomings outside of the Web can also be made up for by other languages.

5. Python’s package management is not as good as Ruby

Although Python’s third-party libraries are of higher quality and more mature, the Python community lacks a good package management software and package publishing website like RubyGem. . Therefore, the construction of applications is not as convenient and user-friendly as Ruby. Especially when upgrading the version of the class library, you will encounter a lot of troubles, which is not as simple as RubyGem.

But in general, Python and Ruby are two very similar programming languages. Even if you learn both programming languages, it won’t waste too much time. If I personally choose, I would first use Rails to build web applications, and then choose Python or Java to handle some server back-end operations depending on the situation. In short, the future is still an era of hybrid programming. We need to know more about some programming tools, and then eat according to our needs.

3. Corrections to "Comparison between ruby ​​and python"

1. Documentation, open source projects, and library support. Ruby should not be compared with Python for these things. It is not a question of several orders of magnitude. Why should it look similar? arranged side by side.

2. Python does not have the regular expression module built into the core, but it does have the support of the re standard library. The purpose at that time was to make the core as small as possible. I don't quite understand, what's the difference between using the standard library and the built-ins, or even as an advantage? And using regular expressions in Python is nothing more than multiple import

re and a few letters when calling. The countless ends saved are enough to offset this problem.

3. As for the embedded HTML function, there is a C/Python dual-implemented Cheetah template available in Python. It is said that thanks to Zope, the US Navy and the French government are using it. I wonder how mature this function is in Ruby?

4. The mod_ruby module has only appeared for a short time. If the author has not heard of mod_python, he is really ignorant. When I translated the mod_python3.2.8 documentation a year ago, mod_python was already so mature that almost all Python

WEB frameworks supported building on it to improve efficiency. However, it seems that mod_ruby is updated only a few times a year. mod_python also has heavyweight applications like gnu.org. I wonder if mod_ruby has one?

5. In addition, unix tools are mentioned. Red hat

Linux installation program has always been written in Python. If you happen to use ubuntu, then the program that prompts you to update the system is also written in Python.

6. rac and doctools. Please forgive my ignorance. I googled and found few Chinese content about rac except your article. After searching, I found out that it is a tool similar to yacc. From Google's perspective, I won't say much about the usability of rac. I don't quite understand how useful a yacc tool is in daily programming, but since the author mentioned it, I looked for spark, which I had only heard of the name and had never used. The result of google is "racc

ruby":"python

spark"=159,000:659,000. As for doctools, I have nothing to say. There are only 15,800 records on Google. I still can’t figure out what this thing is used for. So I found something that was probably similar and compared it. Docutils and Google records were 25,400.

7. "More complete object-oriented syntax than Python library". What is the purpose of object-oriented? Furthermore, can ruby ​​be like Python? Most standard libraries do not need to check the documentation at all. You only need to guess the general name, then dir() and help() to get started directly. It will not be used until the second time. When, because there are too few things in the module and it is too convenient to remember, can it be written directly? In addition, object-oriented is neither a silver bullet nor the most advanced software engineering idea.

8. "The entire ruby ​​library is based on class inheritance structure". I personally think it is the dregs of Java, but I have learned it as a treasure. Perhaps this is also an advantage of ruby ​​to save Java programmers.

9. "Basic data types and operators can be overloaded." This is not very clear. I wonder if overloading __add__ in Python counts.

10. "The main functions of ruby ​​are implemented through object method calls, not functions." Everything in Python is an object, but not all classes. I don't know if this sentence is still there. What's the meaning. In addition, I recommend that you don’t pursue thoroughness too much, and the word practical is more attractive.

11. Python does not strictly require single inheritance to give programmers flexibility. In addition, regarding interfaces, as long as a function with the same name is defined in Python, it is considered to have the same interface. The metaphysics has risen to this level, and I am a little confused. As for the interface, don't be so confident. Ruby's so-called interface is just a mix-in. This thing has been implemented in several large projects in Python, but because it is not obviously meaningful to Python, it is not used more.

12. Regarding Lisp functional programming, Python has a lot of built-in support, such as map, zip, filter, etc., and of course lambda. Don’t talk about support, let’s talk about practicality. Some Pythoners still think that functional programming affects code readability and try to avoid it. Therefore, before you think about supporting something, first think about whether it is a good thing.

13. "The biggest shortcoming is precisely caused by the power of ruby." This is really disgusting, no comment.

14. Haha, ruby ​​doesn’t have international support. What a joke. I wonder what the little Japanese thought at the time? Did he pass CET-4 in English?

15. As for jython, there is also jruby now, maybe because the author’s original text is relatively early. Python also has many implementations, such as jython,

ironpython, pypy,

pyrex, etc. The excellence of Python does not necessarily need to be implemented in other languages ​​to be reflected. Of course, let alone hope that Java will rescue Ruby from dire straits.

In addition, don’t avoid some of Ruby’s shortcomings:

16. Ruby does not have localized threads, but uses pseudo-threads, which cannot take advantage of multi-core CPUs. CPython uses localized threads, but because it uses GIL, it cannot take advantage of multi-core CPUs. However, the emergence of Stackless can completely solve this problem, and stackless has raised Python to the height of parallel computing. The competitor at this level can be Erlang, and Ruby naturally does not need to pry. The ultra-lightweight threading technology can ensure that it is easy to run hundreds of thousands of threads on a poor machine. Asynchronous programming based on Twisted also provides an option.

17. When I first started learning Python, I heard the saying "Python is the slowest among the mainstream dynamic languages". I later learned that the person who said that didn't take Ruby seriously at all. . If ruby ​​is included in the mainstream dynamic languages, then there will be a language that is many orders of magnitude slower than Python.

18. Is ruby ​​popular? Are you going to PHP? PHP is a good thing, but the problem is that it can only be used for WEB programming, which limits the scope of application of PHP. Things that require a little more system must use C. And now Ruby seems to be following this path. Until one day, someone broke the news that "Ruby can be used for client programming", which aroused everyone's curiosity. Moreover, it is still unknown whether the current ROR can replace anything. Not all people rescued from Java

WEB development went to ruby.

4. Comment on "Choose Ruby or Python?" 》

The design philosophies of Python and Ruby are indeed very different. On this issue, I will not comment on which one is better. Everyone has their own preferences. As for efficiency, Ruby should never be compared to Python. Ruby is a pseudo-thread, and there is no possibility of taking advantage of multi-core CPUs, so just pass it. And Python uses native

thread, just because some modules are not threadsafe, GIL is added to limit the application of multi-core CPUs. In my recent tests, after using Twisted’s asynchronous threads, the computing power of multi-core CPUs can be well utilized. . The execution efficiency is not of the same order of magnitude, you will know if you try it yourself.

Comparing Java with Python shows the author’s creativity, haha. Open source projects are very consistent with Darwin's natural selection. Could it be that the lack of Ruby's open source projects is an advantage? In addition, I have not seen any projects in Python that have too much duplication except WEB

framework. For example, pypcap has basically eliminated pcapy.

Speaking of resources, Ruby still has a long way to go, so please don't overdo it when it comes to both sides being strong. As for people in the Java community tending to learn Ruby, I personally think it’s just that the developers who are used to Java are too narrow-minded. Language is a tool, and object-oriented is also a tool. Pure object-oriented is not necessarily clever. Python also has functional programming support. Why didn't the author mention it? In addition, many of Python's practices are based on development efficiency as the first goal and are not limited to various forms. Even multiple inheritance in C++, which is widely criticized by many people with limited intelligence, Python can also support. The issue isn't supporting something you don't like, it's getting as many people as possible to use something they like. In addition, an example of Python that has always been considered by Ruby developers as not being OO enough is to take the length of a sequence. Python uses the len(x) method. For this question, if Ruby developers think that x.length can be regarded as OO, then Python can also directly use x.__len__() to obtain the length. From the perspective of Java, which uses methods to encapsulate properties, who is more OO, haha.

Ruby is a Japanese work, haha, I won’t say much about this. There are many Chinese who don’t like Japan. Here I can disparage Ruby only on the technical level. There is no need to use non-technical terms. Something.

About Rubyon

rails, the Ruby community does focus almost all its energy on this. But this can only show the naivety of Ruby. Facts have proved that many imitators of ROR have launched countless advanced features that far exceed ROR. The failure to replace ROR is just out of preconceived notions. What would it be like if Ruby suddenly lost ROR now? As for the zend mentioned by the author, compared with ROR, it is like hitting a stone with an egg. I have learned two WEB frameworks of Python, and I usually pay more attention to various things in Python and Ruby, but I have never heard of zend. I passed it, I don’t know if it is the author’s work, haha. If you must have a competition on WEB frameworks, you can use django, Quixote, mod_python and the like to compare. Django, a typical imitation of ROR, is still growing, but it already has many functions that are better than ROR, and it goes without saying that the performance is far better than ROR. douban.com, which uses Quixote, has the largest traffic among all websites using Python and Ruby, and is more than twice as fast as ROR with the same hardware configuration. You must know that after removing various equal losses such as WEB servers, etc. , this is something that is an order of magnitude faster. As for mod_python, it is said that this is used. If Ruby still wants to be open source, then it will always live in the shadow of Python.

As for the speed of getting started, everyone has different situations, so I won’t comment. As for what flexibility brings, it's a matter of opinion, so I won't comment. The author talks about how difficult it is to get started with Python, but I really don’t know how easy it is with Ruby. When I first learned Python, I wrote a lexical parser in Python on the 11th day, which is still available on my blog. Therefore, when it comes to entry-level difficulty, it is better for everyone to try it on their own without having to listen to what others say.

It is mentioned that there are many things in the directory generated by ROR, and it takes a long time to understand them all. This is indeed a syndrome of IDE. In Python, a typical example is TurboGears. If you want to understand how the entire application runs, you can start learning from the core cherrypy, and then there will be nothing to know when you start using TurboGears. From this perspective, ROR has no choice. Furthermore, scgi, a way of connecting to WEB servers now available in ROR, was also a work of Python back then, and it was another little thing living in the shadow of Python.

The future development of Ruby is hard to say, but since it is a desperate move, the risk is still quite high. As for Python, I thought it would really develop steadily, but then the addition of Micro$oft made it difficult for us to predict how big the future of Python would be. Let's go back and talk about the diversity of Python that the author has always hated. In my opinion, there are only a handful of things that Ruby can surpass Python, and the things that Python surpasses Ruby are naturally an insurmountable gap for Ruby. Therefore, considering the diversity of programming languages, it is not recommended that everyone learn Ruby. There is one less choice and it is always good to gather some popularity.

5. python or ruby, who should I choose?

In fact, python and ruby ​​are very close, much closer than most other languages, so you can use whatever you like (to be honest, although it is also nonsense). Although there are a few differences in syntax, most of which are syntax sugar. I will venture to list a few (I have almost forgotten python, so feel free to criticize me if you are wrong), but the main difference is still in the design concept: flexibility. vs explicit. I don't think there's any difference in productivity between the two, if you're familiar with it. *Note, comparison is limited to the language itself.

1. Ruby’s case can match many things: range/array, object, regular expression. Python does not have case/switch and using if/else is more rigid.

2. Python’s indentation It's pretty, although it can cause a bit of trouble at times. The end of ruby ​​is quite ugly, so everyone is forced to be one liner (joke)

3. It feels like ruby ​​is more OO than python. Of course, this may also be because python does not advocate the use of those that change the internal structure of the object. The illusion caused by 'tricks'

4. Python has list comprehension, Ruby does not:(

5. Python has real keyword argument, Ruby uses hash to simulate it, of course there is no difference in actual use

6. Python’s self is annoying, Ruby doesn’t have that kind of complicated stuff

7. Reflection, Ruby has many built-in methods, such as object.methods, and Python stores this information in a special dictionary It’s almost the same

8.Ruby’s block function is very strong, and Python’s lambda can only return a single value

9.Ruby’s open class has been declared far-reaching and can be played for 2.days. It seems that Python cannot directly modify built-in classes and is opposed to doing so. 10. Python needs to use @classmethod to modify the declared class method. Ruby has built-in

11. Ruby has a monad method, which is correct. Objects are customized individually. I don’t know if Python has a similar concept.

12.Ruby has a method_missing mechanism. Python can use __getattr__ to intercept undefined methods (from qiezi)

13.Ruby uses single inheritance. +mixin, Python uses multiple inheritance, but Python also has mixin

14. Ruby has attr_* series of syntax helpers, which saves you having to write a bunch of setters/getters yourself. Python’s property method still has to write your own setters/getters

15.Ruby and Python both use duck typing, but Python also has an explicit interface mechanism (has it been incorporated into the kernel from zope3?)

16.Ruby’s function call brackets can be omitted Yes, just press the keyboard a little less. If Python does not have parentheses or parameters by default, it returns a reference to the function itself.

17. I don’t know how far Python’s meta programming can go, so I have to wait for the experts. Let’s talk about it. I just don’t think it is commonly used by pythoners, and it may make the program logic obscure.

18.Ruby inherits some ugly things from perl, such as many predefined $x constants##.

#19.Ruby has built-in regular expressions, which is more convenient.

20.Ruby's yield is used to call blocks. Python's yield is used to input and output values ​​​​to the generator.

21. I feel that the naming convention of python libraries is a bit inconsistent. Some methods use snake_case and some use CamelCase. Maybe it is a historical problem left by too many libraries.

22. python Three quotes are very beautiful, ruby's <<-XX...XX is too ugly, you can also use %q{...} to wrap multi-line text (from qiezi)

23. I like it in ruby's class library design Add aliases to methods to make them easier to remember.

Another: ruby ​​official website also provides some basic comparisons.

6. Comparison of resources and learning curves of the two languages:

Overall impression, use an inappropriate metaphor: If Python is Java, then Ruby is .net. We know that the Java world is very complex and diverse. For any requirement, there will be many open source projects. They use different ideas to implement them and have very different performance characteristics. It is always difficult to choose which one. The same is true for Python now, and because Python is far less difficult to develop than Java, there are many more Python-related projects than Java.

In terms of resources, both communities are very strong. Interestingly, the Java community is now in danger of being assimilated by Ruby. At least the several Java blog aggregations I subscribe to talk about Ruby more than Java. Ruby's community is more concentrated, while Python's is more dispersed. I always suspect that Ruby has more Japanese users, but because I don't understand Japanese, it is difficult to confirm this idea. I am always a little afraid of a founder whose native language is not English, fearing that it will be difficult to understand him, fearing that it will be difficult to get the latest news, etc. Although this worry seems unnecessary at the moment, but who knows what will happen!

The reason why Ruby has suddenly become popular is inseparable from the rails architecture. When considering Ruby, consider Ruby on rails. Rails provides a very good web development framework with very high development efficiency. Although Python has many similar architecture implementations, there is no architecture that can unify the world. Although Python's zend is complete, it is more biased towards web servers and cannot be compared with rails.

Ruby is easier to use than pyton. From the perspective of language features, Ruby has many interesting creations, such as blocks, but large-scale application of these interesting things makes the program confusing. Python syntax emphasizes simplicity, but because it is too flexible and too simple, traditional programmers often see some surprising expressions. I don’t know whether this should be considered an advantage or a disadvantage. At least I think the syntax is too flexible, which can easily lead to excessive differences in the coding styles of different programmers and increase the learning cost.

It is easier to get started with Ruby in the early stages, but once it reaches a certain level of complexity, the difficulty of Ruby suddenly increases. It’s not easy to get started with Python, and it’s not too painful when it gets complicated. Rails has the problem of being easy to get started but difficult to get into. What is the purpose of the directory generated by rails? How is o/r mapping implemented? How to transfer data from the web to the database. These are all problems that Ruby programmers will face sooner or later. This is not the case with Python. If you don't understand these, you probably won't be able to get started. Rapid development tools that are too highly integrated have this characteristic. Whether it is VB, Delphi, or .net, how many developers who have used it for less than half a year can clearly explain the purpose of all the files in the project directory and the syntax of each file? ? I believe that many experienced users may not be able to explain it clearly.

From an architectural point of view, although the two are actually very different, the final results are very similar. Ruby is a pure OO language, while Python is a mixture of functions and OO. Although Ruby can also use functional style coding, it is actually simulated. This gap between them does not have a big impact on ordinary programmers, after all, they look similar.

Generally speaking, if it is a non-professional who is trying development for the first time, Ruby is suitable. For professional programmers, I still recommend choosing Python.

Regarding future development, I think the development of Python is foreseeable and will be relatively stable. Python already belongs to a community rather than a person, but Ruby due to various reasons, the will of Ruby's author maze will still have a greater impact on the development of Ruby. Sun controls Java, but due to Sun's powerful resources and the organization of jcp for coordination, Java is developing very well, but it will take time to prove whether Ruby can achieve this.

7. From Python to Ruby

Python is a very excellent language. When migrating from Python to Ruby, you will find some grammatical differences.

Similarities

Like Python, in Ruby,…

There is an interactive prompt (called irb).

You can Read the document (via the ri command instead of pydoc).

There is no special symbol to end a line (except new line).

Text can use multiple lines, just like three in Python Quotation marks.

Use [] for List and {} for Dict (Dict is called "hashes" in Ruby).

Arrays work the same way (two Arrays added together become a longer Array, but if you want to combine a3 = [ a1, a2 ], it will produce an array containing arrays).

Objects have fixed types and dynamic conversion.

Everything is object, A variable name is just a pointer to an Object.

Although the keywords are different, exceptions work the same way.

You have a tool for embedding documentation (called rdoc in Ruby).

Differences

Different from Python, in Ruby,…

Strings can be changed.

You can use constants (the values ​​of constants change differently).

There are some mandatory writing requirements here (for example: class names start with uppercase letters, variable names start with lowercase letters).

There is only one container (Array), and it can be changed.

String restrictions in quotation marks are different.

There is no new style of Class here, Class has only one style.

You cannot access properties directly. In Ruby, this is done through method calls.

Using () in method calls is an optional strategy.

Here, private and other restricted access keywords are used to replace name hiding in Python.

“mixin’s” are used instead of multiple inheritance.

You can modify the existing Class at any time and add new methods.

Replace True and False with true and false (replace None with nil).

When judging the truth value, only false and nil will be considered false. Everything else is considered true (including 0, 0.0, "", and []).

Use elsif instead of elif.

Use require instead of import. But the usage is the same.

Use usual-style to annotate documents (replacing docstrings) and also to generate documentation.

8. Compare Python and Ruby from three aspects:

1. What applications are they suitable for?

2. Development environment and running environment

3. How is the portability, because the project eventually plans to be transplanted to mobile platforms, such as windows CE Symbina

[1. Applications to which each is applicable]

The results of the review seem to be Both languages ​​have good reviews and perform very well in web development. They are very suitable for rapid application development, and the development efficiency is very high.

Python:

Excerpted some application descriptions related to the project

Cross-platform development:

Python supports a range of different platforms in a neutral manner. If the system used by the user contains different platforms, it is best to use Python to develop applications; its adaptability can also reserve the possibility of using other tools for the system . For users who frequently change platforms, Python is an ideal choice.

When providing software services to end users, Python is also an alternative to avoid the time and expense of programming with different application software at the same time.

Internet Programming:

Python comes with standard modules for basic and protocol level communication with network sockets. For example, if you want to read email from a POP server, Python comes with The library module can do this. In addition, Python also supports XML, HTML and CGI library files, so you can use it to parse user input requirements and produce the best quality results through the web server.

Programmers can also compile modules for Apache, Unix and Windows web servers that have Python's built-in interpreter. Based on the power of CGI programs, Python statements can be easily executed without loading them separately.

For python network programming, there is a good book: "Python Network Programming Basics"

This book comprehensively introduces the basic knowledge of network programming using Python language, the main content Including network basics, advanced network operations, Web Services, parsing HTML and XHTML, XML, E-mail services, FTP, using Python to operate databases, SSL, several server-side frameworks (including Socket server, SimpleXMLRPCServer, CGI and mod_python), As well as multi-tasking (including Forking, threads and asynchronous communication), etc. This book is highly practical, providing a total of about 175 examples and more than 6,600 lines of code. It is the best practice to help readers learn the Python language comprehensively and quickly and write network programs.

Ruby:

A powerful, object-oriented scripting language that allows you to do object-oriented programming quickly and easily, sometimes developed using a formal object-oriented language like Smalltalk, Eiffel, or C++ Some small projects seem a bit "overkill", and Ruby can just meet these object-oriented programming needs. Of course, you can also use Ruby for ordinary process-oriented programming.

Ruby supports many network protocols, both high-level and low-level. Ruby provides some basic classes that allow you to interact using TCP, UDP, SOCKS and many other protocols without having to stick to the network layer. These classes also provide helper classes that allow you to easily read and write to the server. Network programming is also great.

[2. Development environment, operating environment]

Python:

In contrast, there is no strong integrated development environment. Some people say that open source software is easier to use than paid software.

The most commonly used ones:

Python’s own idle:

is not the best among Python IDEs...

PythonWin:

It is very easy to use (as comfortable as using Windows). It has a useful editor that includes code merging, syntax tag highlighting, and code auto-completion features. PythonWin, like some IDEs, does not include a form designer of any kind; but it provides an excellent debugger with monitoring, code inspection, interactive debugging windows, breakpoints, and other features that a debugger should have. Most importantly, PythonWin is stable, although it sometimes "stops responding" strangely when used on Win95r2 systems. In terms of interface, PythonWin is relatively simple, but very attractive, and makes good use of embeddable and dockable elements (I am a bit partial to the Idle style "many windows everywhere", which is also used by many other IDEs). PythonWin also integrates ActiveState's HtmlHelp version of Python documentation and PythonCOM.

eclipse's pydev plug-in, eclipse+pydev

Pydev is based on Eclipse, a great Python environment, and the improvement speed is very fast. Some functions provided

UliPad:

An editor that you can use for your document writing and programming development. It is developed using the Python programming language and the user interface is based on wxPython. In addition to completing the common functions of general editors, it mainly wants to implement a convenient and flexible framework so that developers can easily develop new functions. Moreover, users with programming experience can also prepare plug-ins to deal with special problems in daily work, so that they can be closely integrated with their daily work. Because it uses Python, a powerful programming language, you can easily modify the software to meet your needs.

UliPad supports code coloring, smart completion, code debugging, Python class browsing, code snippets, Ftp function, directory browsing and other powerful functions. The documentation in its Doc directory is very rich, allowing you to write Python A great helper!

System requirements:

python 2.4+

wxPython 2.6+

Our final choice was UliPad, which is pretty good.

Ruby:

Ruby has an excellent high-level debugger.

You can use the ruby ​​plug-in of netbeans or the ruby ​​plug-in of eclipse.

The general process of installing the development environment under Eclipse:

1. Install Ruby1.8.6 One-Click Installer.

2. Unzip the Eclipse Platform Runtime Binary compressed package to a certain directory.

3. Unzip the contents of the RubyDevelopment Tools compressed package to the corresponding directory of Eclipse.

Running environment: Just download the corresponding version from its official website and then install it. The installation under windows is relatively simple, just double-click to run it and you can install it.

[3.Portability]

Python:

Due to its open source nature, Python has been ported on many platforms (with modifications to enable it to work on different on the platform). If you are careful to avoid using system-dependent features, then all of your Python programs will run without modification on any of the platforms listed below. These platforms include Linux, Windows, FreeBSD, Macintosh, Solaris, OS/2, Amiga, AROS, AS/400, BeOS, OS/390, z/OS, Palm OS, QNX, VMS, Psion, Acom RISC OS, VxWorks, PlayStation, Sharp Zaurus, Windows CE and even PocketPC!

When Python is executed, it will first compile the source code in the .py file into Python byte code, and then the Python Virtual Machine will execute these compiled byte codes. The basic idea of ​​this mechanism is consistent with Java and .NET. However, the difference between Python Virtual Machine and Java or .NET Virtual Machine is that Python Virtual Machine is a more advanced Virtual Machine. Advanced here is not advanced in the usual sense. It does not mean that Python's Virtual Machine is more powerful than Java or .NET. It means that compared with Java or .NET, Python's Virtual Machine is further away from the real machine. Or it can be said that Python's Virtual Machine is a Virtual Machine with a higher abstraction level.

You can install an object-oriented interpreted computer programming language. It is also a powerful and complete general-purpose language. It has a development history of more than ten years, is mature and stable. Python has the richest and most powerful class library among scripting languages, which is enough to support most daily applications. Symbina smartphones support two types of programs developed in C++ and JAVA. After installing Python, they can also support many programs developed in Python. Various programs. For ordinary mobile phone users, we don’t need to know too much. We just need to install the Python platform, which allows our mobile phones to support more programs developed in Python. Currently, there are quite a few programs developed in Python on Symbian mobile phones, and they are all relatively practical.

Ruby:

It is mostly developed on Linux, but can be used on many types of Unix, Dos, Windows95/98/Me/NT/2000/XP, MacOS, BeOS, Run on OS/2 and other systems.

There is very little information about ruby ​​and mobile development. There is a version running on Windows CE, but it seems that there is still very little relevant information, and there are many examples of installation failures and compilation failures. There is a small amount of Japanese introduction on the Japanese page. [Summary]

Then I also gave the following reference opinions on Python and Ruby at the suggestion of a friend. I would like to thank him:

1. Python is also called a Clear language. Because when its author designed it, the general guiding idea was that for a specific problem, there is only one best way to solve it. Another meaning that the Python language is a clear language is that its author intentionally designed a very restrictive syntax so that bad programming habits (such as not indenting the next line to the right in an if statement) cannot be compiled. . This intentionally forces programmers to develop good programming habits. Python also adheres to a clear and consistent style in the design of other parts, which makes Python a language that is easy to read and maintain, and is popular with a large number of users and has a wide range of uses.

The codes written by several people using Python for the same problem will be very similar. But Ruby has different design ideas. Programs written using it are too flexible, and the programs written by different people may differ greatly.

The above content is a comparison of the similarities and differences between Python and ruby. I hope that after reading this article, you will have a deeper understanding of the similarities and differences between Python and ruby.

Related recommendations:

Compare python and ruby

If you are new to web development, which one should you learn among php, python or ruby?

The problem of each circular reference variable in Python and Ruby (a hidden BUG?)

The above is the detailed content of Comparison of similarities and differences between Python and ruby. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template