如果公司使用 C++、C# 或 Java 作为应用程序语言,为什么要学习 Perl、Python、Ruby?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/84340/
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
Why learn Perl, Python, Ruby if the company is using C++, C# or Java as the application language?
提问by szabgab
I wonder why would a C++, C#, Java developer want to learn a dynamic language?
我想知道为什么 C++、C#、Java 开发人员想要学习动态语言?
Assuming the company won't switch its main development language from C++/C#/Java to a dynamic one what use is there for a dynamic language?
假设公司不会将其主要开发语言从 C++/C#/Java 切换到动态语言,那么动态语言有什么用呢?
What helper tasks can be done by the dynamic languages faster or better after only a few days of learning than with the static language that you have been using for several years?
与您使用了几年的静态语言相比,仅几天的学习时间,动态语言可以更快或更好地完成哪些辅助任务?
Update
更新
After seeing the first few responses it is clear that there are two issues. My main interest would be something that is justifiable to the employer as an expense. That is, I am looking for justifications for the employer to finance the learning of a dynamic language. Aside from the obvious that the employee will have broader view, the employers are usually looking for some "real" benefit.
在看到前几个回复后,很明显有两个问题。我的主要兴趣是对雇主来说是合理的费用。也就是说,我正在寻找雇主资助学习动态语言的理由。除了员工将拥有更广阔的视野这一显而易见的事实外,雇主通常还在寻找一些“真正的”利益。
采纳答案by Cervo
A lot of times some quick task comes up that isn't part of the main software you are developing. Sometimes the task is one off ie compare this file to the database and let me know the differences. It is a lot easier to do text parsing in Perl/Ruby/Python than it is in Java or C# (partially because it is a lot easier to use regular expressions). It will probably take a lot less time to parse the text file using Perl/Ruby/Python (or maybe even vbscript cringeand then load it into the database than it would to create a Java/C# program to do it or to do it by hand.
很多时候会出现一些不属于您正在开发的主要软件的快速任务。有时任务是一次性的,即将此文件与数据库进行比较并让我知道差异。在 Perl/Ruby/Python 中进行文本解析要比在 Java 或 C# 中容易得多(部分原因是使用正则表达式要容易得多)。使用 Perl/Ruby/Python(或者甚至 vbscript cringe,然后将其加载到数据库中)解析文本文件可能比创建 Java/C# 程序来执行它或通过手。
Also, due to the ease at which most of the dynamic languages parse text, they are great for code generation. Sure your final project must be in C#/Java/Transact SQL but instead of cutting and pasting 100 times, finding errors, and cutting and pasting another 100 times it is often (but not always) easier just to use a code generator.
此外,由于大多数动态语言可以轻松解析文本,因此它们非常适合代码生成。确保您的最终项目必须使用 C#/Java/Transact SQL,但与其进行 100 次剪切和粘贴、查找错误、再剪切和粘贴 100 次,不如使用代码生成器通常(但并非总是)更容易。
A recent example at work is we needed to get data from one accounting system into our accounting system. The system has an import format, but the old system had a completely different format (fixed width although some things had to be matched). The task is not to create a program to migrate the data over and over again. It is to shove the data into our system and then maintain it there going forward. So even though we are a C# and SQL Server shop, I used Python to convert the data into the format that could be imported by our application. Ultimately it doesn't matter that I used python, it matters that the data is in the system. My boss was pretty impressed.
最近工作中的一个例子是我们需要将数据从一个会计系统获取到我们的会计系统中。系统有导入格式,但旧系统有完全不同的格式(固定宽度,但有些东西必须匹配)。任务不是创建一个程序来一遍又一遍地迁移数据。它是将数据推送到我们的系统中,然后在那里维护它。因此,即使我们是 C# 和 SQL Server 商店,我也使用 Python 将数据转换为我们的应用程序可以导入的格式。最终,我使用 python 并不重要,重要的是数据在系统中。我的老板印象非常深刻。
Where I often see the dynamic languages used for is testing. It is much easier to create a Python/Perl/Ruby program to link to a web service and throw some data against it than it is to create the equivalent Java program. You can also use python to hit against command line programs, generate a ton of garbage (but still valid) test data, etc.. quite easily.
我经常看到用于测试的动态语言。与创建等效的 Java 程序相比,创建 Python/Perl/Ruby 程序来链接到 Web 服务并针对它抛出一些数据要容易得多。您还可以使用 python 来攻击命令行程序,生成大量垃圾(但仍然有效)的测试数据等,非常容易。
The other thing that dynamic languages are big on is code generation. Creating the C#/C++/Java code. Some examples follow:
动态语言的另一大亮点是代码生成。创建 C#/C++/Java 代码。一些例子如下:
The first code generation task I often see is people using dynamic languages to maintain constants in the system. Instead of hand coding a bunch of enums, a dynamic language can be used to fairly easily parse a text file and create the Java/C# code with the enums.
我经常看到的第一个代码生成任务是人们使用动态语言来维护系统中的常量。无需手动编码一堆枚举,动态语言可用于相当轻松地解析文本文件并使用枚举创建 Java/C# 代码。
SQL is a whole other ball game but often you get better performance by cut and pasting 100 times instead of trying to do a function (due to caching of execution plans or putting complicated logic in a function causing you to go row by row instead of in a set). In fact it is quite useful to use the table definition to create certain stored procedures automatically.
SQL 是一个完全不同的球类游戏,但通常通过剪切和粘贴 100 次而不是尝试执行函数可以获得更好的性能(由于执行计划的缓存或在函数中放置复杂的逻辑导致您逐行而不是在一套)。事实上,使用表定义来自动创建某些存储过程是非常有用的。
It is always better to get buy in for a code generator. But even if you don't, is it more fun to spend time cutting/pasting or is it more fun to create a Perl/Python/Ruby script once and then have that generate the code? If it takes you hours to hand code something but less time to create a code generator, then even if you use it once you have saved time and hence money. If it takes you longer to create a code generator than it takes to hand code once but you know you will have to update the code more than once, it may still make sense. If it takes you 2 hours to hand code, 4 hours to do the generator but you know you'll have to hand code equivalent work another 5 or 6 times than it is obviously better to create the generator.
购买代码生成器总是更好。但即使你不这样做,花时间剪切/粘贴更有趣还是创建一次 Perl/Python/Ruby 脚本然后生成代码更有趣?如果手动编写代码需要花费数小时而创建代码生成器的时间更少,那么即使您在节省时间和金钱后使用它。如果创建代码生成器比编写一次代码花费的时间更长,但您知道必须多次更新代码,那么它可能仍然有意义。如果手工编写代码需要 2 小时,而生成生成器需要 4 小时,但你知道你必须再手工编写 5 或 6 倍的代码,这显然比创建生成器更好。
Also some things are easier with dynamic languages than Java/C#/C/C++. In particular regular expressions come to mind. If you start using regular expressions in Perl and realize their value, you may suddenly start making use of the Java regular expression library if you haven't before. If you have then there may be something else.
此外,动态语言的某些事情比 Java/C#/C/C++ 更容易。特别是正则表达式浮现在脑海中。如果您开始在 Perl 中使用正则表达式并意识到它们的价值,那么您可能会突然开始使用 Java 正则表达式库,如果您以前没有的话。如果你有,那么可能还有别的东西。
I will leave you with one last example of a task that would have been great for a dynamic language. My work mate had to take a directory full of files and burn them to various cd's for various customers. There were a few customers but a lot of files and you had to look in them to see what they were. He did this task by hand....A Java/C# program would have saved time, but for one time and with all the development overhead it isn't worth it. However slapping something together in Perl/Python/Ruby probably would have been worth it. He spent several hours doing it. It would have taken less than one to create the Python script to inspect each file, match which customer it goes to, and then move the file to the appropriate place.....Again, not part of the standard job. But the task came up as a one off. Is it better to do it yourself, spend the larger amount of time to make Java/C# do the task, or spend a much smaller amount of time doing it in Python/Perl/Ruby. If you are using C or C++ the point is even more dramatic due to the extra concerns of programming in C or C++ (pointers, no array bounds checking, etc.).
我将留给您最后一个任务示例,该示例对于动态语言来说非常有用。我的同事不得不把一个装满文件的目录刻录到不同的 CD 上,供不同的客户使用。有几个客户,但有很多文件,你必须查看它们才能知道它们是什么。他手工完成了这项任务....Java/C# 程序本可以节省时间,但有一次,由于所有的开发开销,这是不值得的。然而,在 Perl/Python/Ruby 中组合一些东西可能是值得的。他花了几个小时做这件事。创建 Python 脚本以检查每个文件,匹配它去往哪个客户,然后将文件移动到适当的位置,只需要不到一个时间......同样,这不是标准工作的一部分。但这项任务是一次性完成的。还是自己做比较好 花更多的时间让 Java/C# 完成任务,或者花更少的时间在 Python/Perl/Ruby 中完成任务。如果您使用 C 或 C++,那么由于 C 或 C++ 编程的额外问题(指针、没有数组边界检查等),这一点更加引人注目。
回答by Chris Upchurch
Do you expect to work for this company forever? If you're ever out on the job market, pehaps some prospective employers will be aware of the Python paradox.
你希望永远在这家公司工作吗?如果你曾经在就业市场上,也许一些潜在的雇主会意识到Python 悖论。
回答by Pete Michaud
Let me turn your question on its head by asking what use it is to an American English speaker to learn another language?
让我反问你的问题,问一个说美国英语的人学习另一种语言有什么用?
The languages we speak (and those we program in) inform the way we think. This can happen on a fundamental level, such as c++ versus javascript versus lisp, or on an implementation level, in which a ruby construct provides a eureka moment for a solution in your "real job."
我们说的语言(以及我们编程的语言)会影响我们的思维方式。这可能发生在基本层面,例如 c++ 与 javascript 与 lisp,或在实现层面,其中 ruby 构造为您的“实际工作”中的解决方案提供了一个尤里卡时刻。
Speaking of your real job, if the market goes south and your employer decides to "right size" you, how do you think you'll stack up against a guy who is flexible because he's written software in tens of languages, instead of your limited exposure? All things being equal, I think the answer is clear.
说到你的实际工作,如果市场下跌,你的雇主决定“调整”你的规模,你认为你会如何与一个灵活的人抗衡,因为他用数十种语言编写软件,而不是你有限的暴露?在所有条件相同的情况下,我认为答案是明确的。
Finally, you program for a living because you love programming... right?
最后,你以编程为生是因为你喜欢编程……对吗?
回答by Mike Farmer
I have often found that learning another language, especially a dynamically typed language, can teach you things about other languages and make you an overall better programmer. Learning ruby, for example, will teach you Object Oriented programming in ways Java wont, and vice versa. All in all, I believe that it is better to be a well rounded programmer than stuck in a single language. It makes you more valuable to the companies/clients you work for.
我经常发现学习另一种语言,尤其是动态类型语言,可以教会你其他语言的知识,让你成为一个更好的程序员。例如,学习 ruby 将教您以 Java 不会的方式进行面向对象编程,反之亦然。总而言之,我相信成为一名全面的程序员比只停留在一种语言上更好。它使您对您工作的公司/客户更有价值。
回答by Jim Kiley
Philosophical issues aside, I know that I have gotten value from writing quick-and-dirty Ruby scripts to solve brute-force problems that Java was just too big for. Last year I had three separate directory structures that were all more-or-less the same, but with lots of differences among the files (the client hadn't heard of version control and I'll leave the rest to your imagination).
撇开哲学问题不谈,我知道我已经从编写快速而肮脏的 Ruby 脚本中获得了价值,以解决 Java 太大而无法解决的暴力问题。去年我有三个独立的目录结构,它们或多或少都相同,但文件之间有很多差异(客户端没有听说过版本控制,剩下的留给你想象)。
It would have taken a great deal of overhead to write an analyzer in Java, but in Ruby I had one working in about 40 minutes.
用 Java 编写分析器需要大量开销,但在 Ruby 中我可以在大约 40 分钟内完成一个分析器。
回答by Christian P.
Often, dynamc languages (especially python and lua) are embedded in programs to add a more plugin-like functionality and because they are high-level languages that make it easy to add certain behavior, where a low/mid-level language is not needed.
通常,动态语言(尤其是 python 和 lua)被嵌入到程序中以添加更多类似插件的功能,并且因为它们是高级语言,可以轻松添加某些不需要低级/中级语言的行为.
Lua specificially lacks all the low-level system calls because it was designed for easeof-use to add functionality within the program, not as a general programming language.
Lua 特别缺少所有低级系统调用,因为它是为易于使用而设计的,以便在程序中添加功能,而不是作为通用编程语言。
回答by Eli Courtwright
When I first learned Python, I worked for a Java shop. Occasionally I'd have to do serious text-processing tasks which were much easier to do with quick Python scripts than Java programs. For example, if I had to parse a complex CSV file and figure out which of its rows corresponded to rows in our Oracle database, this was much easier to do with Python than Java.
当我第一次学习 Python 时,我在一家 Java 商店工作。有时我不得不做一些严肃的文本处理任务,这些任务用 Python 脚本比 Java 程序要容易得多。例如,如果我必须解析一个复杂的 CSV 文件并找出其中的哪些行与我们的 Oracle 数据库中的行相对应,那么使用 Python 比使用 Java 更容易做到这一点。
More than that, I found that learning Python made me a much better Java programmer; having learned many of the same concepts in another language I feel that I understand those concepts much better. And as for what makes Python easier than Java, you might check out this question: Java -> Python?
不仅如此,我发现学习 Python 让我成为了一个更好的 Java 程序员;用另一种语言学习了许多相同的概念后,我觉得我更好地理解了这些概念。至于是什么让 Python 比 Java 更容易,你可以看看这个问题:Java -> Python?
回答by Jean
check out the answers to this thead:
查看此主题的答案:
Learning new languages is about keeping an open mind and learning new ways of doing things.
学习新语言就是保持开放的心态和学习新的做事方式。
回答by Arthur Thomas
Im not sure if this is what you are looking for, but we write our main application with Java at the small company I work for, but have used python to write smaller scripts quickly. Backup software, temporary scripts to manipulate data and push out results. It just seems easier sometimes to sit down with python and write a quick script than mess with classes and stuff in java.
我不确定这是否是您正在寻找的内容,但我们在我工作的小公司使用 Java 编写我们的主要应用程序,但已使用 python 快速编写较小的脚本。备份软件,用于操作数据和推出结果的临时脚本。有时坐下来使用 python 编写一个快速脚本似乎比在 java 中处理类和东西更容易。
Temp scripts that aren't going to stick around don't need a lot of design time wasted on them.
不会留下来的临时脚本不需要浪费大量的设计时间。
And I am lazy, but it is good to just learn as much as you can of course and see what features exist in other languages. Knowing more never hurts you in future career changes :)
而且我很懒惰,但是当然可以尽可能多地学习并看看其他语言中存在哪些功能是好的。在未来的职业变化中,了解更多永远不会伤害你:)
回答by Alex B
I primarily program in Java and C# but use dynamic languages (ruby/perl) to support smoother deployment, kicking off OS tasks, automated reporting, some log parsing, etc.
我主要用 Java 和 C# 编程,但使用动态语言(ruby/perl)来支持更流畅的部署、启动操作系统任务、自动报告、一些日志解析等。
After a short time learning and experimenting with ruby or perl you should be able to write some regex manipulating scripts that can alter data formats or grab information from logs. An example of a small ruby/perl script that could be written quickly would be a script to parse a very large log file and report out only a few events of interest in either a human readable format or a csv format.
在短暂地学习和试验 ruby 或 perl 之后,您应该能够编写一些正则表达式操作脚本,这些脚本可以更改数据格式或从日志中获取信息。一个可以快速编写的小型 ruby/perl 脚本的示例是解析一个非常大的日志文件并仅以人类可读格式或 csv 格式报告几个感兴趣的事件的脚本。
Also, having experience with a variety of different programming languages should help you think of new ways to tackle problems in more structured languages like Java, C++, and C#.
此外,拥有各种不同编程语言的经验应该会帮助您想出新方法来解决更结构化的语言(如 Java、C++ 和 C#)中的问题。
回答by Ed Schwehm
It's all about broadening your horizons as a developer. If you limit yourself to only strong-typed languages, you may not end up the best programmer you could.
这一切都是为了拓宽您作为开发人员的视野。如果您仅限于使用强类型语言,那么您最终可能不会成为最好的程序员。
As for tasks, Python/Lua/Ruby/Perl are great for small simple tasks, like finding some files and renaming them. They also work great when paired with a framework (e.g. Rails, Django, Lua for Windows) for developing simple apps quickly. Hell, 37Signals is based on creating simple yet very useful apps in Ruby on Rails.
至于任务,Python/Lua/Ruby/Perl 非常适合小的简单任务,比如查找一些文件并重命名它们。当与框架(例如 Rails、Django、Windows 的 Lua)搭配使用时,它们也能很好地开发简单的应用程序。地狱,37Signals 基于在 Ruby on Rails 中创建简单但非常有用的应用程序。