python 和 ruby - 用来做什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1149581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
python and ruby - for what to use it?
提问by feiroox
I'm thinking about learning ruby and python a little bit, and it occurred to me, for what ruby/python is good for? When to use ruby and when python, or for what ruby/python is not for? :)
我正在考虑学习 ruby 和 python,我突然想到,ruby/python 有什么好处?什么时候用 ruby 什么时候用 python,或者什么时候用 ruby/python 不?:)
What should I do in these languages?
我应该用这些语言做什么?
thanks
谢谢
回答by fsanches
They are good for mostly for rapid prototyping, quick development, dynamic programs, web applications and scripts. They're general purpose languages, so you can use them for pretty much everything you want. You'll have smaller development times (compared to, say, Java or C++), but worse performance and less static error-checking.
它们主要适用于快速原型设计、快速开发、动态程序、Web 应用程序和脚本。它们是通用语言,因此您几乎可以将它们用于您想要的任何事情。您将拥有更短的开发时间(与 Java 或 C++ 相比),但性能更差,静态错误检查更少。
You can also develop desktop apps on them, but there may be some minor complications on shipping (since you'll usually have to ship the interpreter too).
您也可以在它们上开发桌面应用程序,但在运送时可能会有一些小问题(因为您通常也必须运送解释器)。
You shouldn't do critical code or heavy computations on them - if you need these things, make them on a faster language (like C) and make a binding for the code. I believe Python is better for this than Ruby, but I could be wrong. (OTOH, Ruby has a stronger metaprogramming)
您不应该对它们进行关键代码或大量计算 - 如果您需要这些东西,请使用更快的语言(如 C)制作它们并为代码进行绑定。我相信 Python 在这方面比 Ruby 更好,但我可能是错的。(OTOH,Ruby 有更强的元编程)
回答by Matthew Flaschen
If you want to know what people actually use them for, check out Python Package Index, RubyForge, and search SourceForgeor even StackOverflow.
如果您想知道人们实际使用它们的目的,请查看Python Package Index、RubyForge并搜索SourceForge甚至 StackOverflow。
As shylent says, you can easily get into holy wars about what they shouldbe used for. Both Ruby and Python are popular especially for prototyping, but you can also build production software like Ruby on Rails, Zope, and Mercurial.
正如害羞所说,你很容易陷入关于它们应该用于什么的圣战。Ruby 和 Python 都非常流行,特别是用于原型设计,但您也可以构建生产软件,如Ruby on Rails、Zope和Mercurial。
What one would not use them for is code that is performance-critical (most isn't) or close to the metal.
人们不会将它们用于性能关键(大多数不是)或接近金属的代码。
回答by Lennart Regebro
They are good for everything.
他们对一切都有好处。
Ruby has an edge for munging textfiles awk/perl style. That's slightly easier in Ruby. For the rest, I think Python has a string edge, and that it TOTALLY subjective. See What does Ruby have that Python doesn't, and vice versa?and the follow-up blogpost http://regebro.wordpress.com/2009/07/12/python-vs-ruby/.
Ruby 在处理 awk/perl 风格的文本文件方面具有优势。这在 Ruby 中稍微容易一些。至于其余部分,我认为 Python 具有字符串优势,而且它完全是主观的。请参阅Ruby 有哪些 Python 没有的功能,反之亦然?以及后续博客文章http://regebro.wordpress.com/2009/07/12/python-vs-ruby/。
I use Python for every programming related thing I need to do, and will do that until there is a complete shift in programming paradigm that kicks OO development into the stoneage.
我将 Python 用于我需要做的每个与编程相关的事情,并且会一直这样做,直到编程范式发生彻底转变,将 OO 开发推向石器时代。
回答by Jonke
To avoid the holy war and maybe give another perspective I say (without requesting more information of what fun part of programming the question-ere thinks is cool to do):
为了避免圣战,并可能给出另一个观点,我说(没有要求更多关于编程的有趣部分的信息,该问题认为这样做很酷):
Learn python first!
先学python!
If you haven't done any scripting language yet I would recommend python. The core of python is somewhat cleaner than the core of ruby and if you learn the basic core of scripting with python first you will more or less as a bonus learn ruby.
如果你还没有做过任何脚本语言,我会推荐 python。python 的核心比 ruby 的核心更简洁一些,如果你先用 python 学习脚本的基本核心,你或多或少会作为奖励学习 ruby。
You will (because you use python) write code that looks very clean and has good indentation right from the beginning.
您将(因为您使用 python)编写看起来非常干净并且从一开始就具有良好缩进的代码。
The difficulties about what to learn is what you actually will you try to solve!
学习什么的困难才是你真正要解决的问题!
If you are looking for a new production language to solve X the answer get more complicated. Is X part of the language core? Was the language in fact invented to solve X?
如果您正在寻找一种新的生产语言来解决 X,那么答案会变得更加复杂。X 是语言核心的一部分吗?这种语言实际上是为了解决 X 而发明的吗?
If the question was: What single programming language should I Master and eventually reach Nirva with? My answer is, I don't have a clue! (CLisp, Scheme48, Erlang or Haskell should probably have been on my final list though)
如果问题是:我应该掌握哪种编程语言并最终达到 Nirva?我的回答是,我没有头绪!(CLisp、Scheme48、Erlang 或 Haskell 可能应该在我的最终列表中)
PS. I know that this isn't the spot on answer to the very simplified question in the post. what can ruby do that python can't or what can python do that ruby can't.
附注。我知道这不是帖子中非常简单的问题的答案。ruby 能做什么而 python 不能或 python 能做什么而 ruby 不能。
The point is that when you set out to learn something one usually have a hidden agenda so you try to solve your favorite problem in any language again and again.
关键是当你开始学习某件事时,通常会有一个隐藏的议程,所以你会一次又一次地尝试用任何语言解决你最喜欢的问题。
If your really are out to learn without have an agenda I think that python in it's most basic form is a clean and crisp way and you should be able to use the same style when using ruby.
如果您真的想在没有议程的情况下学习,我认为最基本形式的 python 是一种简洁明了的方式,您应该能够在使用 ruby 时使用相同的样式。
DISCLAIMER: I prefer ruby in a production (commercial setup) over python. I prefer ruby over python on windows. I prefer ruby over python on the things I do at home. I do that because the things I really like to solve is more fun to solve in ruby than in python. My programming style/habit tends to fit better in ruby.
免责声明:与 python 相比,我更喜欢在生产(商业设置)中使用 ruby。在 Windows 上,我更喜欢 ruby 而不是 python。在家里做的事情上,我更喜欢红宝石而不是蟒蛇。我这样做是因为我真正喜欢解决的问题在 ruby 中比在 python 中解决更有趣。我的编程风格/习惯更适合 ruby。
回答by tomaszbak
Ruby and Python are languages aiming at facilitating developers' lives through their simplicity and expressiveness - you can read more in article Ruby vs Python
Ruby 和 Python 是旨在通过其简单性和表现力来促进开发人员生活的语言 - 您可以在文章Ruby vs Python 中阅读更多内容
In the last years Ruby is on the slight decline in popularity, while Python is gaining lots of new users, especially from outside of web dev. That's because of Python's wide usage in data processing and ML/AI.
在过去的几年里,Ruby 的受欢迎程度略有下降,而 Python 正在获得大量新用户,尤其是来自 Web 开发人员之外的用户。这是因为 Python 在数据处理和 ML/AI 中的广泛使用。
You can see it also from the conferences agendas. While Ruby conferences focus around web dev and Ruby performance, Python conferences focus more around data science and machine learning - check out my takeways from a Python conference I attended recently Python in 2019 - Takeaways from PyCon CZ
您也可以从会议议程中看到它。虽然 Ruby 会议侧重于 Web 开发和 Ruby 性能,但 Python 会议更侧重于数据科学和机器学习 - 查看我最近参加的 Python 会议的总结2019 年 Python - PyCon CZ 的总结