Reasons for learning Ruby)

Source: Internet
Author: User
  1. Ruby is an object-oriented language.What does this mean? Indeed, for "What Is oop", every 10ProgramI am afraid there are 12 kinds of opinions among the employees. I will leave this question to your discretion. In terms of features, Ruby provides a mechanism to encapsulate data and methods into objects, implement the Inheritance Mechanism from one class to another, and provide the object polymorphism mechanism. Unlike some languages (C ++, Perl 5, and so on), Ruby was designed with object-oriented goals from the very beginning.
  2. Ruby is a "pure" OOP language.Did I say I already did it? I don't think so. "Pure" means that everything, including basic data types such as strings or integers, is expressed in the form of objects. In Ruby, the Wrapper class provided in Java is not needed ). In addition, even constants are treated as objects, so methods can be raised by -- such as numerical constants.
  3. Ruby is a dynamic language.This is a new concept for people who are familiar with static languages such as C ++ and Java. Dynamic means that methods and variables can be dynamically appended or redefined at runtime. This dynamic mechanism removes the need for Conditional compilation in C Language (# Ifdef) And makes it possible to build a complex reflection (introspection mechanism) API. The complex reflection mechanism further makes the program more self-aware. This opens the door for the following functions: information of types during runtime, detection of loss methods, and hook technology that can detect new append methods. From this point of view, Ruby has some kinship with lisp and smalltalk.
  4. Ruby is an interpreted language.This is a complicated problem and it is worth a few more words. Some people may argue that, in terms of performance, language-based interpretation mechanisms do more harm than advantage. I will respond to this idea with the following considerations: 1. first of all, the rapid development cycle (rapid development cycle) is quite effective, and Ruby's interpreted language nature contributes to this benefit. 2. How slow is it? Please perform some performance tests before speaking slowly. 3. Some may criticize me for this, but I still want to say that the processor continues to speed up every year. 4. If you really need speed, you can use C language to write the part that requires speedCode. 5. Finally, in a sense, there is a debatable point of view: given that no language is interpreted from the bottom, it is impossible to write a ruby compiler.
  5. Ruby can process regular expressions.For many years, regular expressions have been regarded as a minor skill in the Unix field, involvingGrepAndSedOr inVIHere, we will perform some "search-Replace" operations. The PERL language has helped people change this view, and Ruby is now also helpful. More and more people are aware of the power of this ultra-advanced string and text manipulation technique. Those who are skeptical about this should read Jeffrey Friedl's book.Mastering Regular Expressions. Non-skeptical advocates should also read the data.
  6. Ruby is a language that supports multiple platforms.Ruby can run on Linux and other UNIX variants, a variety of Windows platforms, BEOs, and even MS-DOS. If I remember correctly, there will also be the Amiga version.
  7. Ruby draws on previous languages.Is this a good thing? In addition to the field of literature, yes, this is a good thing. Newton said, "If I look farther than others, it is because I stand on the shoulders of giants ". Ruby is indeed on the shoulders of giants. Ruby draws on features from smalltalk, Clu, lisp, C, C ++, Perl, kornshell, and other languages. The principle I see is: 1. Do not re-invent the wheel; 2. Do not fix the problematic part; 3. Make full use of people's existing knowledge. Do you know the files and pipelines (pipes) in UNIX? No problem. You can use that knowledge in ruby. It takes you two years to studyPrintf? Don't worry, you can also use it in ruby.Printf. Do you understand Perl's RegEx handling technology? Okay, so you almost immediately learned Ruby's RegEx handling technology.
  8. Ruby is innovative.Is there a conflict between this article and the 7th articles? Mm ...... Yes. Every coin has two sides. Ruby has some very innovative features, such as the very useful mix-in concept. These innovative features may be used by new languages in the future. (Note: A reader pointed out to me that lisp had mix-in at least as early as 1979. I did not notice this. I should look for a better example to ensure its authenticity .)
  9. Ruby is a very advanced language (very high-level language, vhll ).This issue remains to be discussed because the term vhll is not widely used, and its meaning is more controversial than the meaning of OOP. What I mean by "advanced" is that Ruby can use a relatively small number of commands to control and perform complex operations on complicated data structures, it complies with the principle of least investment (principle of Least Effort ).
  10. Ruby has a smart garbage collector.SuchMallocAndFreeSuch functions are just past last night's nightmare. You do not need to call the destructor. This is enough.
  11. Ruby is a scripting language.Do not think Ruby is a scripting language, so it is not powerful. Ruby is not a toy. Ruby is a fully functional programming language, but Ruby makes traditional script operations easier to write, such as running external programs, checking system resources, using pipe (pipelines), and intercepting output.
  12. Ruby is widely used.Ruby can complete what kornshell can do and what C language can do. Do you want to quickly write a ten-line hack program to complete one-time tasks or write a wrapper for the legacy code? It's okay to use ruby. Do you want to write a Web server, CGI, Or chess game? It's okay to use ruby.
  13. Ruby supports threads.You can use simple APIs to Write multi-threaded applications. Yes, even on a MS-DOS.
  14. Ruby is open-source.RubySource code? Want to provide a patch suggestion? Just go! Users who want to be smart, helpful, including language designersCommunityContact me? Yes!
  15. Ruby is intuitive ).The learning curve is smooth and not steep. Once you get in, will you start to "Guess" how ruby is used? Your guess is usually correct (because Ruby is intuitive and meets the usual expectation ). Ruby is committed to following the principle of least surprise or surprise (principle of least astonishment (or surprise )).
  16. Ruby has an exception mechanism.Like java and C ++, Ruby can handle exceptions. This means less entanglement with the returned code, less nested if statements, and less Italian logic (spaghetti logic, derogatory, refers to complex and chaotic code design, for example, a large number of goto statements are used.
  17. Ruby has an advanced array class.Arrays are dynamic; you do not have to declare the array size during compilation as in Pascal or other languages. You do not need to allocate memory space for arrays as in C/C ++/Java. Ruby's array is an object, so you don't have to worry about its length at all times; in principle, you cannot "Get Out Of The length limit" as in C ". Do you want to use indexes, elements, or reverse processing arrays? Do you want to print the entire array? Ruby provides corresponding methods for all these tasks. Do you want to treat arrays as set, stack, or queue? Ruby also provides corresponding methods for this purpose. Do you want to use arrays as Lookup tables? This is a clever question-you don't need to use it like this, because Ruby provides a hash table dedicated to this problem.
  18. Ruby is extensible.You can use Ruby or C to write external libraries. In addition, you can modify existing classes and objects on the fly.
  19. Ruby encourages literate programming (literal programming ).You can embed comments into the code. Ruby's documentation tools can extract and manipulate these comments. (Literate programming's tie pole supporter may think this is a very basic thing .)
  20. Ruby uses delimiters and case-sensitive characters in an innovative way.Methods that return Boolean (although Ruby does not call it this way) usually end with question marks, and the name of the method for modifying data carries an exclamation point. Everything is simple, clear, and intuitive. All constants, including the class name, start with an uppercase letter. All objects are named@Start with Mark. This scheme not only ensures the old-fashioned "Hungarian notation", but also avoids the ambiguous expression.
  21. Ruby reserved words are not retained.There is no problem with the use of the identifier known as "reserved word", as long as you do not want the syntax analyzer to encounter ambiguity. This is really smooth.
  22. Ruby supports iterator ).Ruby's iterator enables the operation of "passing code blocks to objects" to do so, that is, for arrays, lists, and trees) each element in many structures can call the specified code block. This is a powerful technique worthy of in-depth exploration.
  23. Ruby is secure.Ruby uses Perl's "tainting" concept$ SafeVariable implementation of multiple control levels (worried level ?). This feature is particularly beneficial to CGI programs that are used to break Web servers.
  24. Ruby has no pointer.Similar to Java, and nodded to C ++, Ruby does not have the "Pointer" concept; there is no indirect, no pointer operation, there is no headache caused by syntax and debugging pointers. Of course, this means that the real underlying system programming becomes more difficult, such as accessing the control status register of a device; but these system-level transactions can always be done using the C library. (Just as C programmers use assembly when necessary, Ruby programmers use the C language when necessary !)
  25. Ruby focuses on details.Ruby provides rich synonyms and aliases. Do not remember to use array or stringSizeOrLength? Both can be used. For rangeBeginAndEnd, OrFirstAndLast? You can choose from. Spelling in your heartIndicesWhile your hands are spelled outIndexes? Both can be used.
  26. Ruby has flexible syntax features.You can ignore parentheses in method calls and comma between parameters. Perl-style quotation marks allow us to define arrays or strings without the hassle of hitting those quotation marks and commas (A = ['Ant ', 'bee' in Ruby ', 'cat'] can be abbreviated as a = % W {ant bee cat }).ReturnKeyword can also be ignored.
  27. Ruby has rich libraries available for use.The ruby Library supports many functions such as threads, sockets, limited object persistence mechanisms, CGI, server-side executable mechanisms, and DB files. Ruby also supports TK and will support more in the future.
  28. Ruby has a debugger ).In the perfect world, we do not need a debugger. Unfortunately, this is not a perfect world.
  29. Ruby can be used through interaction.Ruby is designed to be used as a shell similar to kornshell. (This is the most challenging point in this article, and I have to admit that Ruby is not really a very good shell. But I still insist that ruby-based shell is a good thing .)

  30. Ruby is a refined language.There are no unnecessary keywords in ruby, such as Pascal'sBegin,IfAfterThen,WhileAfterDo. You do not need to declare the variable in advance because the variable has no type. You do not need to specify the return type for the method. NoReturnKeyword; the method returns the result of the final evaluated expression. On the other hand ...... Ruby is not as obscure as C or Perl.
  31. Ruby is an expression-oriented language (expression-oriented ).You can easily write data as you speak.X = if a <0 then B else C endSuch a sentence.
  32. Syntax sugar is formed in ruby ).(In Mary Poppins, a spoonful of syntactic sugar can be used to compress the semantic flavor. "A spoonful of syntax sugar helps the semantic medicine go down.") You can useFor a in XTo iterate over the ArrayX, You can useA + = BTo replaceA = a + B. Most operators are actually simplified method representations, more intuitive names, and more convenient syntax forms.
  33. Note: Mary Poppins is a classic movie "Mary Poppins" shot in 1964.

  34. Ruby supports overloading operators ).If I remember correctly, the operator reloads the source from a long time ago, but it is revitalized by a closer C ++. This mechanism may be abused or misused, but it is always better. In addition, Ruby automatically defines the assignment version of the operator. For example, if you have defined the operator +, you will get the operator automatically.+ =.
  35. Ruby has an integer of infinite precisionAlgorithm Who cares?Short,Int,LongWhat about it? UseBignumThat's all. Admit it, you still want to see the factorial of 365. Now you can read it.
  36. Ruby has a power operator.In the past, we used power operators in basic and FORTRAN. But then we learned Pascal and C, and learned the evil side of this operator. (We were told that we didn't even know how the evaluation was done-using logarithm or iteration? How efficient is it ?) But do we really care about this? If yes, you can write your own version. If not, Ruby also provides your favorite**Operator for your use. Enjoy it!
  37. Ruby has powerful string processing capabilities.If you want to search, replace, modify, format, trim, delimit, interpose, or tokenize a string, you can use the ruby built-in method. If the built-in method does not meet the requirements, you can use the built-in method to build your own needs.
  38. Ruby has almost no exceptions that violate its own rules.Ruby's syntax and semantics are more self-completeness (self-consistent) than most languages ). Every language has a logging rule, and every rule has exceptions, but Ruby's logging rules and exceptions may be fewer than you think.
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.