现在的位置: 首页 > 程序设计> 正文
为什么每个程序设计者都应该学习 Python 或者 Ruby
2011年07月25日 程序设计 评论数 1 ⁄ 被围观 5,177+

这是一篇选自外文的评论文章,该文告诉我们为什么要选择python或者ruby,他们相比较其他的编程语言有哪些优势,对我们以后的开发会有怎样的帮助。

=========== 英文原文============

If you are a student, you probably know C, C++ and Java. A few know VB, or C# / .NET. At some point you’ve probably built some web pages, so you know HTML, CSS and maybe JavaScript. By and large, it is difficult to find students who have any exposure to languages beyond this. And this is a shame because there are a number of programming languages out there which will make you a better programmer.

In this article, we give some reasons why you must learn Python or Ruby2.

  • Compared to C/C++/Java – Python/Ruby allow you to write the same program with much, much fewer lines of code. It is estimated that a typical Python or Ruby program will require 5 times fewer lines of code than a corresponding Java code. Why spend that much more time on writing programs unless it is absolutely necessary? Also, someone said that a good programmer can reasonably maintain 20000 lines of code. It does not matter whether those are in assembly, C, or Python/Ruby/PHP/Lisp. So, if you write in Python/Ruby, whatever you do alone would probably need a 5-person team in Java/C/C++.
  • Compared to VB/PHP – Python/Ruby are much, much better designed languages than PHP/VB. PHP and VB are very popular for writing websites, and desktop applications respectively. The reason they’re popular is that they are very easy to learn and even non-programmers can pick them up quickly. But write any large program in these languages and you’ll start seeing the huge problems with these languages because they’re so badly designed. Friends don’t let friends program in PHP/VB.
  • Compared to Lisp/Scala/Haskell/Closure/Erlang – Python/Ruby are still quite “mainstream”. Sure these languages have some really cool features, and for advanced programmers, exposure to these languages can really improve the way they think about programming. But there will be time later in your career to decide whether you want to pick up one or more of these. But for now, Python/Ruby do a much better job of balancing the power of the language against commercial applicability.
  • Compared to Perl1 – Both Python & Ruby owe a lot to Perl, and Perl was the biggest and best dynamic language before they started gaining prominence. But now, Perl’s popularity is reducing and more and more people are adopting Ruby/Python. I find Perl’s object-orientedness a bit contrived and ugly. In general, I think Perl is a harder language to learn since it has so many different ways of doing things, and the syntax tends to be cryptic and non-intuitive until you get the hang of it. Overall, I feel that Perl is not the best language for a student to pick up, unless there is a very good reason to do so (i.e. if you have lots of regular expression processing, then Perl shines)
  • Compared to sh/sed/awk/bash – If you have exposure to Linux/Unix, you have probably done some shell programming, and might even have written non-trivial programs. But anything more than a few lines in these languages starts to become a bit painful and it’s much better to do this in Python. Of course, Perl is the best language for this, but Python is a close second. (Ruby is not so great for system shell scripting).

Just do a Google search on ‘Why is X better than Y’ – where you put Python or Ruby for X and put one of the other languages for Y – and you will find a whole bunch of material on why these languages are so good.

If you have the flexibility to choose the programming language for you final year project, then pick Python or Ruby and get done in half the time that it would have required you to do the project (except if it is a mobile app development project, in which case you’ll be forced to use Java or Objective-C).

Here is a cartoon from xkcd which gives an idea of how powerful you feel after having mastered Python:

How to get started? There are many, many website that give tutorials and classes on Python and Ruby. Here are just a couple of them that we’ve chosen:

Questions? Ask in the comments below, and we’ll try to answer them.

Footnote:

1: My post seems to have pissed of a lot of Perl fans, and in retrospect I realized that I was harsher on the language than I should have been. Hence I’ve changed the Perl section. Earlier it read:

Both Python & Ruby owe a lot to Perl, and Perl was the biggest and best dynamic language before they showed up. But Perl is now old. It’s object-orientedness is broken. It hasn’t really been updated in a while, and it is losing market share. For new, hot things (like web programming frameworks, web APIs) it is not as up-to-date as Python & Ruby. Basically, Python/Ruby are rising, Perl is setting.

Please keep this in mind when reading the comments of Lars, Torsten and Olaf.

2 All the language comparisons made in this article are for the context of students in Indian CS degree programs picking up a new programming language. A statement like “X is better than Y” will never make sense as an absolute statement because all languages that have survived the test of time are obviously better than other languages in some areas, and that is the reason they exist. In other words, there are always scenarios where PHP/Java/C/C++/Perl and others are better languages than Ruby/Python.

 

=========== 中文翻译============

如果你是个学生,你应该会C,C++和Java。还会一些VB,或C#/.NET。多少你还可能开发过一些Web网页,你知道一些HTML,CSS和JavaScript知识。总体上说,我们很难发现会有学生显露出掌握超出这几种语言范围外的语言的才能。这真让人遗憾,因为还有很多种编程语言,它们能让你成为一个更好的程序员。

在这篇文章里,我将会告诉你,为什么你一定要学习Python或Ruby语言。

  • C/C++/Java相比 — Python/Ruby能让你用少的多的多的代码写出相同的程序。有人计算过,Python或Ruby写出的程序的代码行数只相当于相对应的Java代码的行数的五分之一。如果没有绝对的必要,为什么要花这么多时间写出这么多的代码呢?而且,有人说,一个优秀的程序员能维护的代码量最多是2万行。这不区分用的语言究竟是汇编,C还是Python/Ruby/PHP/Lisp。所以,如果你用Python/Ruby写,你一个人干的,不管是干什么,如果换用Java/C/C++,那都需要一个5人的小团队来干。
  • VB/PHP比较 — 跟PHP/VB相比,Python/Ruby的是一种从设计上讲比它们好的不知多少倍的语言。PHP和VB分别是在开发网站和桌面应用程序上非常流行的语言。它们流行的原因是非常的易学。不懂计算机的人也很容易的上手。如果你用这些语言开发过大型的项目,你就会发现这些语言的设计是如此的糟糕。是朋友,他就不会劝你使用PHP/VB。
  • Lisp/Scala/Haskell/Closure/Erlang相比 — Python/Ruby跟它们比起来显得相当的“主流”。确实,这些语言每种都有其很酷的特征,对于高级编程人员,了解这些语言能给他们对编程的思考带来实际的提升。但这些应该在你以后的职业生涯中才去决定学哪一两种。对于现在,Python/Ruby是在语言功能和实际运用之间平衡后的更好的选择。
  • Perl相比 — Python和Ruby都受恩于Perl,在这两种语言异军突起前,Perl是最好、最大的一种动态语言。但现在,Perl已是昨日黄花,越来越多的人转向Ruby/Python。我感觉Perl的面向对象机制有点做作,很不好用。通常认为,Perl一种比较难学的语言,因为它提供你了太多不同的方法去完成同一个任务,它的语法有点像密码,非常不直观 — 除非你对它掌握的非常好。总之,我感觉Perl是一种对于学生来说不是很合适的语言—除非你有特殊的理由去学它(例如,你有很多正则表达式要处理,这是Perl的闪光点)。
  • sh/sed/awk/bash相比 — 如果你使用Linux/Unix,你可能需要做一些shell编程,甚至会编写一些不小的程序。但是,对于这些语言,一旦程序达到一定的行数,事情就会开始变得让你痛苦不堪,你最好是用Python去做这些事情。当然,做这种事情,Perl是最好的选择,Python排第二。(Ruby对于系统shell脚本不是很合适)。

你可以在Google上搜一下“为什么X比Y好” — 其中把X换成Python或Ruby,把Y换成另外一种语言 — 你就会发现,有无数的文章来说明它们为什么这么好。

如果你有选择你的毕业设计使用的编程语言的自由,你应该选择Python或Ruby,它们能让你在开发项目的过程中节省一半的时间(除非你要开发的是移动应用,这样你必须要使用Java或Objective-C)。

下面是xkcd上的一幅漫画,告诉你掌握Python后你会变得多么的强大:

如何去学它们呢?很多很多的网站上都提供了学习Python和Ruby的教材和课程。下面的是我从中选出的一些:

有疑问吗?请在评论了写出来,我会尽量回答你们。

尾注:

1:我的这篇文章可能会让很多Perl爱好者很郁闷,现在回味一下,我认识到对这种语言的要求过于苛刻了。因此,我把关于Perl的一节改写了一下。

Python和Ruby都受恩于Perl,在这两种语言出现之前,Perl是最大、最好的动态语言。但Perl现在太老了。它的面向对象性不完整。它很久没有升级更新了,它的市场份额正在丢失。对于一些新的、很火的事物(例如Web编程框架,Web API),它不如Python & Ruby 那样能跟上时代的步伐。基本上,Python/Ruby在兴起,Perl在衰退。

2:本文中的所有语言的比较都是用来给印度计算机科学专业的学生选编程语言时做参考的。像“X比Y好”这样的句子准确的讲是毫无意义的,因为所有的语言都是经过时间的考验而存活下来的,有些语言会在某些领域比另外一种要强,这也是它们存活下来的原因。换句话说,总有一些情况下,PHP/Java/C/C++/Perl 看起来会比 Ruby/Python 等其它语言显的更适合。


英文链接:http://reliscore.com/why-every-programmer-should-learn-python-or-ruby

中文链接:http://www.aqee.net/2011/07/25/why-every-programmer-should-learn-python-or-ruby/

目前有 1 条留言 其中:访客:1 条, 博主:0 条

  1. 匿名 : 2012年01月13日23:15:58  -49楼 @回复 回复

    一直在学习!

给我留言

留言无头像?


×
腾讯微博