ripgrepをRustで書いたBurntSushiがGoとRustを語る

RustのサイトでJonathanWilburがGoを差し置いてRustを選んだ理由は?と呼びかけている。何人かがコメントを寄せているが、その中でもripgrepという高速grepをRustで書いたBurntSushiが寄せたコメントが興味深い。

https://users.rust-lang.org/t/what-made-you-choose-rust-over-go/37828/5

Go's goals actually deeply resonate with me. I very much appreciate its fast compilation times, opinionated and reasonably orthogonal design and the simplicity of the overall tooling and language.

BurntSushiは「goのopinionated(独善的)でreasonably(合理的)でorthogonal(直行性)のある設計に感謝している」と言っている。

opinionatedは「作者によって強く方向づけられた」という意味でソフトウェアに使われることが多い。設計に芯がなく、その時代ごとのトレンドに流される設計は、いつしか扱いにくくなるが、goはそうではないというわけだ。

orthogonalは前に達人プログラマについて書いたときに触れたので省略。

"simplicity" is an overloaded term that folks love to get pedantic about, so I'll just say that I'm using it in this context to refer to the number of different language constructs one needs to understand, and invariably, how long it takes (or how difficult it is) for someone to start becoming productive in the language.

simplicityというのは人々がpedantic(知ったかぶり)するときに好んで使う過剰な表現だが、goに関しては理解する必要のあるconstruct(構造)の数や、どれだけの期間で生産的になれるかという点でsimplicityという表現を使う。

とSushiさんが言ってる。難しい表現が好きなようだ。あれ、まだRustのことを語ってない。

I actually try hard to blend some of those goals that I find appealing into Rust code that I write. It can be very difficult at times.

こういったgoのよさをRustでプログラミングするときもブレンドしようとしているが、それが難しいことも多々ある。

それでも、なぜRustを使うのか。

The first is obvious: performance and control. The projects I tend to take on in my free time bias towards libraries or applications that materially benefit from as much performance tuning as you want.

ひとつはパフォーマンス。Sushi氏がフリーで関わるライブラリやアプリケーションはパフォーマンスチューニングの実質的な利益を得ている。

goで同じことをしようとすると、何かを犠牲にしなければいけない。

The second reason is harder to express, but the most succinct way I can put it is this: Go punishes you more than Rust does when you try to encapsulate things.

2つ目の理由は表現が難しい。Goはカプセル化しようとすると罰せられる。

The lack of parametric polymorphism in Go makes it hard to build reusable abstractions, even when those abstractions don't add too much complexity to the code.

具体的にはGoにはParametric polymorphimがない。Rustでジェネリックとして実装されている、様々な型を引数にできる機能だ。goには、これがないので再利用できる抽象化を作りにくい。

The lack of a first class iteration protocol. In Rust, the for loop works with anything that implements IntoIterator. You can define your own types that define their own iteration.

goにはファーストクラスなイテレーションもない。RustはIntoIteratorを実装するあらゆるものでloopできる。さらに独自のイテレーションを定義するタイプを定義できる。

IntoIteratorって、なんか読んだことあるなーと思ったが、あれ便利だったのか。逆にgoのイテレータはforしかないのか。そうなのか。(難しすぎて幽体離脱・・・)

Default values. I have a love-hate relationship with default values. On the one hand, they give Go its character and make a lot of things convenient.

最後にデフォルト値。Sushi氏はデフォルト値とlove-hate relationship(愛と憎しみの関係)を持っているとな。

まだまだSushi氏の主張は続くが、長くなるので、このあたりで。もうちょっとRustに慣れたら実感できるかもしれないので、そのときに読み直してみることにします。


この記事が気に入ったらサポートをしてみませんか?