📄 00000000.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: cybergene (基因~也许以后~~), 信区: Linux <BR>标 题: Thirty-seven Reasons I Love Ruby <BR>发信站: BBS 水木清华站 (Tue Nov 21 16:48:01 2000) <BR> <BR> <BR>Thirty-seven Reasons I Love Ruby <BR> <BR>------------------------------------------------------------------------ <BR>-------- <BR> <BR> <BR>I won't bother giving the history of Ruby here. For those of you who <BR>haven't heard of it, the definitive web site is www.ruby-lang.org, and <BR>comp.lang.ruby is the newsgroup. For those who have, I present to you <BR>the reasons I love this new language. <BR> <BR> <BR>It's object-oriented. What does that mean? Well, for every ten <BR>programmers, there are twelve opinions as to what OOP is. I will leave <BR>it your judgment. But for the record, Ruby does offer encapsulation of <BR>data and methods within objects and allows inheritance from one class to <BR> another; and it allows polymorphism of objects. Unlike some languages <BR>(C++, Perl 5, etc.) Ruby was designed from the beginning to be <BR>object-oriented. <BR> <BR>It's a pure OOP language. Am I being redundant? I don't think so. By <BR>this we mean that everything, including primitive data types such as <BR>strings and integers, is represented as an object. There is no need <BR>for wrapper classes such as Java has. And in addition, even constants <BR>are treated as objects, so that a method may be invoked with, for <BR>example, a numeric constant as a receiver. <BR> <BR>It's a dynamic language. For people only familiar with more static <BR>languages such as C++ and Java, this is a significant conceptual leap. <BR>It means that methods and variables may be added and redefined at <BR>runtime. It obviates the need for such features as C's conditional <BR>compilation (#ifdef), and makes possible a sophisticated reflection API. <BR> This in turn allows programs to become more "self-aware" -- enabling <BR>runtime type information, detection of missing methods, hooks for <BR>detecting added methods, and so on. Ruby is related to Lisp and <BR>Smalltalk in this respect. <BR> <BR>It's an interpreted language. This is a complex issue, and deserves <BR>several comments. It can be argued that performance issues make this a <BR>negative rather than a positive. To this concern, I reply with these <BR>observations: 1. First and foremost: A rapid development cycle is a <BR>great benefit, and it is encouraged by the interpreted nature of Ruby. <BR>2. How slow is too slow, anyway? Do some benchmarks before you call it <BR>slow. 3. Though some will criticize me, I will say this anyway: <BR>Processors are getting faster every year. 4. If you absolutely need <BR>the speed, you can write part of your code in C. 5. Finally, in a sense, <BR> it is all a moot point, since no language is inherently interpreted. <BR>There is no law of the universe that says a Ruby compiler cannot be <BR>written. <BR> <BR>It understands regular expressions. For years, this was considered the <BR>domain of UNIX weenies wielding clumsy tools such as grep and sed, or <BR>doing fancy search-and-replace operations in vi. Perl helped change <BR>that, and now Ruby is helping, too. More people than ever recognize <BR>the incredible power in the super-advanced string and text <BR>manipulation techniques. Doubters should go and read Jeffrey Friedl's <BR>book Mastering Regular Expressions. So should non-doubters. <BR> <BR>It's multi-platform. It runs on Linux and other UNIX variants, the <BR>various Windows platforms, BeOS, and even MS-DOS. If my memory serves <BR>me, there's an Amiga version. <BR> <BR>It's derivative. This is a good thing? Outside of the literary world, <BR>yes, it is. Isaac Newton said, "If I have seen farther than others, it <BR>is because I stood on the shoulders of giants." Ruby certainly has stood <BR> on the shoulders of giants. It borrows features from Smalltalk, CLU, <BR>Lisp, C, C++, Perl, Kornshell, and others. The principles I see at <BR>work are: 1. Don't reinvent the wheel. 2. Don't fix what isn't broken. <BR>3. Finally, and especially: Leverage people's existing knowledge. You <BR>understand files and pipes in UNIX? Fine, you can use that knowledge. <BR>You spent two years learning all the printf specifiers? Don't worry, you <BR> can still use printf. You know Perl's regex handling? Good, then you've <BR> almost learned Ruby's. <BR> <BR>It's innovative. Is this in contradiction to #7 above? Well, partly; <BR>every coin has two sides. Some of Ruby's features are truly innovative, <BR> like the very useful concept of the mix-in. Maybe some of these <BR>features will be borrowed in turn by future languages. <BR> <BR>It's a Very High-Level Language (VHLL). This is subject to debate, <BR>because this term is not in widespread use, and its meaning is even more <BR> disputable than that of OOP. When I say this, I mean that Ruby can <BR>handle complex data structures and complex operations on them with <BR>relatively few instructions, in accordance with what some call the <BR>Principle of Least Effort. <BR> <BR>It has a smart garbage collector. Routines like malloc and free are only <BR> last night's bad dream. You don't even have to call destructors. Enough <BR> said. <BR> <BR>It's a scripting language. Don't make the mistake of thinking it isn't <BR>powerful because of this. It's not a toy. It's a full-fledged language <BR>that happens to make it easy to do traditional scripting operations like <BR> running external programs, examining system resources, using pipes, <BR>capturing output, and so on. <BR> <BR>It's versatile. It can do the things that Kornshell does well and the <BR>things that C does well. You want to write a quick ten-line hack to do a <BR> one-time task, or a wrapper for some legacy programs? Fine. You want to <BR> write a web server, a CGI, or a chess program? Again, fine. <BR> <BR>It's thread-capable. You can write multi-threaded applications with a <BR>simple API. Yes, even on MS-DOS. <BR> <BR>It's open-source. You want to look at the source code? Go ahead. Want to <BR> suggest a patch? Go ahead. You want to connect with a knowledgeable and <BR> helpful user community, including the language creator himself? You <BR>can. <BR> <BR>It's intuitive. The learning curve is low, and once you get over the <BR>first hump, you start to "guess" how things work?and your guesses are <BR>often correct. Ruby endeavors to follow the Principle of Least <BR>Astonishment (or Surprise). <BR> <BR>It has an exception mechanism. Like Java and C++, Ruby understands <BR>exceptions. This means less messing with return codes, fewer nested if <BR>statements, less spaghetti logic, and better error handling. <BR> <BR>It has an advanced Array class. Arrays are dynamic; you don't have to <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -