-2

I was wondering if using := and not specifying the variable type reduces performance in Go.

  • 1
    If you simply want to quell worries about hurting your performance: no, short variable declarations won't hurt your programs performance. If you want an in depth explanation, hopefully someone more knowledgeable can help you out. – Hymns For Disco Nov 15 '20 at 09:00
  • 1
    no, even though you are not explictly setting the type, the compiler will deduce it given the left hand side. –  Nov 15 '20 at 09:03
  • 1
    you can try it for yourself using the parser package (https://golang.org/pkg/go/parser/) and using it to browse declarations. You will see it does always figure out a type. –  Nov 15 '20 at 09:04
  • 1
    there is a similar question that might help you https://stackoverflow.com/questions/28024884/does-a-type-assertion-type-switch-have-bad-performance-is-slow-in-go – ma_jafari Nov 15 '20 at 09:52
  • 4
    [This](https://play.golang.org/p/ppXDw-XJ7E7) does not compile: what does this tell you? – Emile Pels Nov 15 '20 at 10:22

1 Answers1

1

Using := does not impact performance.