If you use Go’s “accept interfaces return concrete types” the dev/ide knows to declare the concrete type.
Type inference can actually cause more issues during refactorings - not alleviate them. Personally, I find types make the code easier to read. But when I write ago I don’t use them. I find when I review old code it is a bit harder. In Java I think it is less of an issue (on refactoring) because you normally use the interface and due to implements you have more safety. > On Apr 24, 2023, at 2:14 AM, a2800276 <a2800...@gmail.com> wrote: > > > import “os” > func main() { > file, _ := os.Open(os.Args[1]) > myfunc(file) > } > > func myfunc(file ???) { > } > > What type should I use to declare “file” in the parameter list for myfunc()? > > This argument doesn't seem logical to me. If I fully declare `file` in this > case, I also have to know which type to declare it as: > > var file ???; > file, _ = os.Open(...) > > This will also be a "distraction and waste time". I'm all for explicit > declarations in cases where they add clarity, but in idiomatic cases, I don't > feel it adds anything useful. > > Additionally, in cases where I am creating a new function to work with the > variable, surely I'm aware of more context concerning the API, e.g. in the > example, I'll assume `file` has `Read` and `Close`, but passing the variable > along, I would assume the operation on the variable will be more involved and > requiring reading the documentation anyway ... > > -tim > > > > > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/f6c9bafb-50a9-4e40-b091-59988417ebffn%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/81837BA2-D643-4526-9C79-FAEDD91C1BBA%40ix.netcom.com.