Tips for writing clear, performant, and idiomatic Go code Packages

As part of the Go 2 design process, we’ve published these draft designs to start community discussions about three topics: generics, error handling, and error value semantics. These draft designs are not proposals in the sense of the Go proposal process. They are starting points for discussion, with an eventual goal of producing designs good enough to be turned into actual proposals. Each of the d
「ghqを使ったローカルリポジトリの統一的・効率的な管理について」というエントリで書かれているように、 ghq.root と $GOPATH/src を一緒にする運用で長年やってきて、goimports が遅いことに少し困っていたのだが、以下でめちゃくちゃ快適になった。 .goimportsignore を使う goimports-update-ignore で自動生成をする 最新の dragon-imports を使う どれくらい快適になったかというと、エディタの保存時に goimports を気兼ねなく実行させられるようになったくらい。以下解説。 .goimportsignoreを使う 最近の goimports には $GOPATH/src/.goimportsignore という除外リスト機能がある。ここにインポート対象外にしたいディレクトリを $GOPATH/src 以下の相対パ
« Software Design 2018年7月号「Vim 絶対主義」の執筆に参加しました。 | Main | ボタンを押したら golang の if err... を自動入力 » tensorflow といえば Python と思っておられる方も多いのではないでしょうか。間違いではないのですが、これは初期に作られた Python 向けのバインディングに研究者達が多く食いついた結果に過ぎないと思っています。実際 tensorflow は現在 C言語、C++、Python、Java、Go から利用する事ができ、最近では JavaScript にも移植されています。筆者自身も Go で tensorflow を使ったシステムを構築し、運用保守しています。問題も発生せず機嫌良く動いています。学習の利用部分は GPU のパフォーマンスに依存しますが、それ以外の部分については各言語の実装に依存し
Note The latest version of this document can be found online at https://dr-knz.net/go-calling-convention-x86-64.html. Alternate formats: Source, PDF. Introduction This article analyzes how the Go compiler generates code for function calls, argument passing and exception handling on x86-64 targets. This expressely does not analyze how the Go compiler lays out data in memory (other than function arg
はじめに GoでHTTP Serverを作ろうとすると、標準ライブラリを使う場合以下のようなコードをよく書くと思う。 package main import ( "fmt" "log" "net/http" ) func main() { mux := http.NewServeMux() mux.Handle("/hello", http.HandlerFunc(hello)) log.Fatal(http.ListenAndServe(":8080", mux)) } func hello(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) fmt.Fprintf(w, "Hello World") } このコードの登場人物としては以下になるが、それぞれなんだっけ?というのをいっつも忘れてしまうの
プログラミング学習のProgate、Go言語*の学習コンテンツをリリースGo言語の第一人者として著名なメルカリ現役エンジニアと初の共同開発 株式会社Progate(所在地:東京都渋谷区、代表取締役:加藤將倫、以下当社)は、7月2日(月)、世界的に需要が高まっているプログラミング言語「Go」のレッスンコンテンツをリリースします。本レッスンは、株式会社メルカリ/株式会社メルペイの現役エンジニアであり、Go言語の第一人者として著名な上田拓也氏との共同開発によるものです。これまでコンテンツを完全内製化してきた当社にとり、外部エキスパートとの協働は初の取り組みです。当社は、今後も世界市場のニーズに応えながら海外展開を強化するため、コンテンツの拡充に一層注力してまいります。 *Go言語とは:Googleが開発したサーバーサイド開発に用いられることの多いプログラミング言語です。実用性の高さから世界中で利
This is the sequel to Writing An Interpreter In Go. We're picking up right where we left off and write a compiler and a virtual machine for Monkey. Runnable and tested code front and center, built from the ground up, step by step — just like before. But this time, we're going to define bytecode, compile Monkey and execute it in our very own virtual machine. It's the next step in Monkey's evolution
Writing An Interpreter In Goという本を読んだ。 この本はMonkeyという言語のインタプリタをGo言語で実装するという内容。 全編英語だが、200ページほどだし語り口も面白くてわかりやすいので読みやすい。 流れとしては大きくLexer・Parser・Evaluaterの章に分かれていて、それぞれ字句解析〜抽象構文木〜評価器をGoの標準機能だけで実装していく感じ。 Parserの部分ではyaccなどの既存ツールを使わずにPratt ParserというJS Lintでも使われている手法を用いて実装していくところが特に面白かった。 Pratt Parserについてはググってもあんまり情報が出てこなかったけど、いくつか英語のエントリがあって特に下記のPythonで解説してくれてるやつがわかりやすかった。 Top-Down operator precedence pars
EDIT: For the latest of GopherJS/Wasm comparison, see Wasm benchmark result Hi all! This article describes about my experiment of the new WebAssembly port of Go. WebAssembly port is now available on the master branch of Go, and you'd need to compile Go yourself. tl;dr I have created GopherWasm, an agnostic WebAssembly wrapper that works both on GopherJS and WebAssembly port. Performance of GopherJ
A few weeks ago, I read an article called “Good Code vs Bad Code in Golang” where the author guides us step-by-step through the refactoring of an actual business use case. The article focuses on turning “bad code” into “good code”: more idiomatic, more legible, leveraging the specifics of the go language. But it also insists on performance being an important aspect of the project. This triggered m
Goを始めてからずっと Robo や Task といったYAMLベースのものでビルドタスクを書いていたのですが、プロジェクトが増えてきて限界を感じました。 YAMLベースと言ってもタスクの記述部はあくまでもただのシェルであり、せいぜい「Makefileよりは読みやすいよね」程度。シェルへの依存度が高いと、どうしてもこういう問題が目立ってきます。 環境依存で「動きません」って他のメンバーに言われがち。MacとLinuxで date コマンドのオプションが違うとかよくある。かといってビルド用のDockerイメージを作るほどではまだない grep sed 等で正規表現の魔術的な操作が増えると、一見何やってるのか分からなくなりがち エラー処理が雑になりがち。パイプの途中のエラー拾うとかしんどい 遅い。並行処理書くのもしんどい 個別のタスクをライブラリ化してインポートしたいけど、決まったやり方がない
Find heap allocations and nail them down to save 0.67µs (37%) on a Raspberry Pi 3 in an inner loop Heap optimization For hot code paths, it is important to reduce heap allocations. This reduces the GC pressure and it is generally a speed optimization at the same time. We’ll see real world examples below. Reducing heap usage can be done in a few ways and I’ll show case three in this post: Favor con
UPDATE: You can watch a video of me giving this talk at Gophercon 2019:
はじめに この記事でも書いたけど、最近ISUCONの面白さに気づいた。 serinuntius.hatenablog.jp 社内ISUCONはRubyで書かれていたけど、本家ISUCONでは使用言語が選択できる。 そうなったら、今なら迷わずにGoを選ぶ。 それは、何故かと言うとGoが速いとかそういう理由よりも、GolandというIDEのおかげである。 こいつの補完やらなんやらがとても良くできているので、ソースを読むのも書くのも爆速になるからである。 RubyにもJetbrains製の Rubymine というのがあるけれど、動的言語だからか完全にはコードジャンプできない。 同名のメソッドがあったときには、選択肢が出てユーザにどのメソッドですか?みたいな感じで問いかける感じ。 けど、Golandは型があるからか100%の精度でコードジャンプできる。 そのおかげで、爆速コードリーディングが可能
こんにちは、Andyです。 普段はフロントエンドチームでJSばかり書いているのですが、せっかくGoの会社に入ったので良い機会だと思いGoに入門してみました。「Goの作法」を知ればより裏側のシステムについての理解が深まり、フロント側も良いプロダクトが作れるんじゃないかなと期待しています。 せっかく新しい言語を学ぶので、学習の中でやった事や詰まった事を文字で残そうというのが本記事の目的。 とてもじゃないですが1回で全てをカバーできないので数回に分けてチャレンジします。 手探りで自分なりのベストプラクティスを模索している最中なのでマサカリ大歓迎です。 現在のスタック 学習を始めるにあたって、自分のエンジニアとしてのスタックはこんな感じ。 Ruby on Rails, ES6 (業務レベル) PHP, Perl, Python (趣味レベル) ちなみにgolangの経験値はA Tour of Go
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く