Comparison between Ruby and other similar languages

Source: Internet
Author: User
Smalltalk

 

Like smalltalk, Ruby is also a dynamic, object-oriented language. You do not need to specify the Data Type statically. Everything is an object. In addition, both have a garbage collection mechanism.

In smalltalk, flow control statements are also completed by sending messages to objects, but sometimes this makes the program hard to read and understand. The Control Process Structure in ruby is conservative and easy to understand.

To be honest, I don't know anything about smalltalk. All the above nonsense is taken from the ruby author.

 

Perl

 

Ruby and the other two P surname languages: Perl and Python are classified as script languages ). There are three reasons:

1. They all support fast development cycles (edit-run-edit) without compilation.

2. They try to reduce the number of your code to improve your efficiency. For example, you do not need to define the type, at least several keys are required.

3. Many strong built-in libraries support text, file, and network operations.

 

Maybe, because it is a scripting language, many people think that the speed is slow and cannot be used in large projects. However, it may be true for CSH, but it is not suitable for Ruby and Perl. Perhaps Ruby is more suitable for dynamic object-oriented language than scripting language ".

Unlike Perl, Ruby is a completely object-oriented language, and OO is not an ornament. Ruby uses fewer symbols, such as $, @, and %. These symbols are very easy to mix for me with small-eye myopia. Ruby does not have much dependency on the context environment, and rarely performs implicit conversion.

For example, you can obtain the length of a string or array as follows:

Ruby:

 

A = "ABC"

A. Length # => 3

A = [1, 2, 3]

A. Length # => 3

 

It is very simple, but in Perl, It is troublesome:

 

$ A = "ABC ";

Length ($ A); # => 3, It's OK

@ A = (1, 2, 3 );

Length (@ A); # => 1, not as expected

Scalar (@ A); #=> 3,

$ A = [1, 2, 3]; #

Length ($ A); # => 16, not as expected

Scalar (@ $ A); #=> 3

 

In Ruby, many Perl functions are packaged into class libraries, so sometimes Ruby programs look like simple Perl programs. Ruby inherits many advantages of Perl. Of course, it does not introduce any annoying things. Therefore, if you are familiar with Perl, you may like Ruby.

Python

Let's talk about Python.

Let's first complain: Why do I have to use indentation to determine the code structure? What do I need tuple TO DO WITH list? Why are all values not instances? You don't have to worry about other issues in Ruby. Ruby aims to make programs shorter and more refined than python.

The question is who is more object-oriented. In Ruby, the length of the string obtained is as follows:

 

IRB (main): 010: 0> A = "1234"

=> "1234"

IRB (main): 011: 0> A. Length

=> 4

IRB (main): 012: 0>

 

 

In python, the process is more oriented:

 

 

Length ()

 

Now I am not familiar with Python and cannot summarize it. I will update it later in a few days.

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.