本文共 8302 字,大约阅读时间需要 27 分钟。
python和golang
This is a guest blog post by , a software engineer in Boulder, CO. Kyle is a Python first developer with experience in Ruby, Golang, and many more languages. This post was originally authored on Kyle’s personal blog and included great discussion on .
这是一个客人博客文章由 ,博尔德一名软件工程师,CO。凯尔是在Ruby中,Golang,越来越多的语言体验和Python的显影剂。 这篇文章最初是在Kyle的个人博客上撰写的,其中包括有关精彩讨论。
In late 2014 I built a tool called . I recently felt the need to learn golang and refresh my ruby knowledge so I decided to revisit the idea of pymr and build it in multiple languages. In this post I will break down the “mr” (merr) application (pymr, gomr, rumr) and present the implementation of specific pieces in each language. I will provide an overall personal preference at the end but will leave the comparison of individual pieces up to you.
2014年底,我构建了一个名为的工具。 最近,我感到有必要学习golang和更新我的Ruby知识,因此我决定重新审视pymr的想法,并以多种语言构建它。 在这篇文章中,我将分解“ mr”(merr)应用程序(pymr,gomr,rumr),并介绍每种语言中特定部分的实现。 最后,我将提供整体的个人喜好,但将各个部分的比较交给您。
For those that want to skip directly to the code check out the .
对于那些想直接跳到代码的人,请查看 。
The basic idea of this application is that you have some set of related directories that you want to execute a single command on. The “mr” tool provides a method for registering directories, and a method for running commands on groups of registered directories. The application has the following components:
此应用程序的基本思想是,您具有要在其上执行单个命令的一组相关目录。 “ mr”工具提供了一种用于注册目录的方法,以及一种用于在已注册目录组上运行命令的方法。 该应用程序包含以下组件:
The command line interface for the “mr” tools is:
“ mr”工具的命令行界面为:
112233445566778899 |
To compare building the command-line interface let’s take a look at the register command in each language.
为了比较构建命令行界面,让我们看一下每种语言的register命令。
Python (pymr)
Python(pymr)
To build the command line interface in python I chose to use the package.
为了在python中构建命令行界面,我选择使用包。
112233445566 |
Ruby (rumr)
Ruby(谣言)
To build the command line interface in ruby I chose to use the gem.
为了在ruby中构建命令行界面,我选择使用 gem。
1122334455667788991010111112121313141415151616 |
Golang (gomr)
高朗(GOMR)
To build the command line interface in Golang I chose to use the package.
为了在Golang中构建命令行界面,我选择使用包。
1122334455667788991010111112121313141415151616171718181919202021212222 |
The registration logic is as follows:
注册逻辑如下:
--append
read the .[py|ru|go]mr
file if it exists..[...]mr
file with the new tags.--append
读取.[py|ru|go]mr
文件(如果存在)。 .[...]mr
文件。 This breaks down into a few small tasks we can compare in each language:
这分为几个小任务,我们可以用每种语言进行比较:
Python (pymr)
Python(pymr)
For python this involves the module.
对于python,这涉及模块。
112233 |
Ruby (rumr)
Ruby(谣言)
For ruby this involves the class.
对于Ruby,这涉及类。
112233 |
Golang (gomr)
高朗(GOMR)
For golang this involves the package.
对于golang,这涉及软件包。
112233 |
Python (pymr)
Python(pymr)
For python this involves the use of a .
对于python,这涉及使用 。
1122 |
Ruby (rumr)
Ruby(谣言)
For ruby this involves the use of the array method.
对于Ruby,这涉及使用数组方法。
112233445566 |
Golang (gomr)
高朗(GOMR)
For golang this involves the use of custom function.
对于golang,这涉及使用自定义函数。
112233445566778899101011111212 |
I tried to choose the simplest possible file format to use in each language.
我试图选择每种语言使用的最简单的文件格式。
Python (pymr)
Python(pymr)
For python this involves the use of the module.
对于python,这涉及使用模块。
1122334455 |
Ruby (rumr)
Ruby(谣言)
For ruby this involves the use of the module.
对于Ruby,这涉及使用模块。
1122334455667788 |
Golang (gomr)
高朗(GOMR)
For golang this involves the use of the package.
对于golang,这涉及使用软件包。
1122334455 |
The run logic is as follows:
运行逻辑如下:
.[...]mr
files.[...]mr
文件 This breaks down into a few small tasks we can compare in each language:
这分为几个小任务,我们可以用每种语言进行比较:
Python (pymr)
Python(pymr)
For python this involves the module and module.
对于python,这涉及模块和模块。
112233 |
Ruby (rumr)
Ruby(谣言)
For ruby this involves the and classes.
对于ruby,这涉及和类。
112233445566 |
Golang (gomr)
高朗(GOMR)
For golang this requires the package and a custom callback function.
对于golang,这需要包和自定义回调函数。
11223344556677 |
Python (pymr)
Python(pymr)
Nothing additional is needed in python for this task.
python中不需要任何其他操作。
1122 |
Ruby (rumr)
Ruby(谣言)
Nothing additional is needed in ruby for this task.
Ruby不需要额外的费用来完成这项任务。
1122 |
Golang (gomr)
高朗(GOMR)
For golang this requires the package.
对于golang,这需要包。
1122 |
Python (pymr)
Python(pymr)
For python this requires the module and the module.
对于python,这需要模块和模块。
1122 |
Ruby (rumr)
Ruby(谣言)
For ruby this involves the module and the Backticks syntax.
对于Ruby,这涉及模块和Backticks语法。
11223344 |
Golang (gomr)
高朗(GOMR)
For golang this involves the package and the package.
对于golang,这涉及软件包和软件包。
112233 |
The ideal mode of distribution for this tool is via a package. A user could then install it tool install [pymr,rumr,gomr]
and have a new command on there systems path to execute. I don’t want to go into packaging systems here, rather I will just show the basic configuration file needed in each language.
该工具的理想分发方式是通过包装。 然后,用户可以使用tool install [pymr,rumr,gomr]
对其进行tool install [pymr,rumr,gomr]
并在该系统路径上执行新命令。 我不想在这里进入打包系统,而只是显示每种语言所需的基本配置文件。
Python (pymr)
Python(pymr)
For python a setup.py
is required. Once the package is created and uploaded it can be installed with pip install pymr
.
对于python,需要setup.py
。 创建并上传软件包后,可以使用pip install pymr
进行安装。
112233445566778899101011111212131314141515161617171818191920202121222223232424252526262727282829293030313132323333343435353636 |
Ruby (rumr)
Ruby(谣言)
For ruby a rumr.gemspec
is required. Once the gem is created and uploaded is can be installed with gem install rumr
.
对于ruby,需要rumr.gemspec
。 一旦创建并上传了gem,就可以使用gem install rumr
进行安装。
11223344556677889910101111121213131414 |
Golang (gomr)
高朗(GOMR)
For golang the source is simply compiled into a binary that can be redistributed. There is no additional file needed and currently no package repository to push to.
对于golang,源代码可以简单地编译为可以重新分发的二进制文件。 不需要其他文件,当前也没有要推送的软件包存储库。
For this tool Golang feels like the wrong choice. I don’t need it to be very performant and I’m not utilizing the native concurrency Golang has to offer. This leaves me with Ruby and Python. For about 80% of the logic my personal preference is a toss-up between the two. Here are the pieces I find better in one language:
对于此工具,Golang感觉是错误的选择。 我不需要它具有很高的性能,也没有利用Golang提供的本机并发。 这让我有了Ruby和Python。 对于大约80%的逻辑,我个人的偏好是两者之间的折衷。 以下是我用一种语言找到的更好的作品:
Python is the winner here. The libraries decorator style declaration is clean and simple. Keep in mind I have only tried the Ruby gem so there may be better solutions in Ruby. This is also not a commentary on either language, rather that the CLI library I used in python is my preference.
Python是这里的赢家。 库装饰器样式声明简洁明了。 请记住,我只尝试了Ruby gem,所以Ruby中可能会有更好的解决方案。 这也不是对这两种语言的注释,而是我偏爱在python中使用的CLI库。
Ruby is the winner here. I found that this entire section of code was much cleaner and more readable using ruby’s Find.find()
and especially the next unless
syntax.
Ruby是这里的赢家。 我发现使用ruby的Find.find()
尤其是next unless
语法,整段代码都更加清晰易读。
Ruby is the winner here. The rumr.gemspec
file is much simpler and the process of building and pushing a gem was much simpler as well. The tool also makes installing in semi-isolated environments a snap.
Ruby是这里的赢家。 rumr.gemspec
文件要简单得多,而构建和推送gem的过程rumr.gemspec
简单得多。 工具还使在半隔离环境中的安装变得 。
翻译自:
python和golang
转载地址:http://vwhwd.baihongyu.com/