0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Goでメソッドの引数が同じ型である場合、省略して記述できる

Last updated at Posted at 2023-06-09

今年の3月まで19ヶ月ほどGoを書いていたのですが、その際は何となく雰囲気でやっていたので。
Goを基礎から勉強しなおそうと思い、A Tour of Goをやっています。

事象

メソッドの引数が同じ型である場合、最後の型を残して省略出来る様子。

func add(x, y int) int {
	return x + y
}

反省

知らなかったので、毎回省略せずに型を書いていました。
ただ、保守時の可読性を考えると、場合によっては省略せずに書いたほうが良いかもしれない🤔

他の言語が分かるとなんとなく、雰囲気で書けちゃうけど、
新しい言語をやる時は、公式や有名な教材をちゃんとやって基本を付けたほうが良さそうだね😅
受託開発メインだと、JavaやRuby・KotlinやPythonなど、
いろんな言語をやる事が多いので、一つの言語に労力を掛けにくいってのもあるんだけど…。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?