-1

This is a bit a silly question but I wanted to ask that can I use any name instead of r and w in the w http.ResponseWriter, r *http.Request or should it be r and w always?

Thanks

JFMR
  • 23,265
  • 4
  • 52
  • 76
user918204
  • 57
  • 2
  • 7
  • 2
    You can use any parameter name. You can even omit or discard the parameter name. Only the function's/method's parameter types matter when you are trying to implement a specific func type or interface. – mkopriva Mar 05 '22 at 12:15
  • @mkopriva thanks for your response. I am fairly new to Golang.Can you help me with tutorials to better objects and pointers in function in Golang? – user918204 Mar 05 '22 at 12:45
  • 1
    The official [Go website](https://go.dev/doc/) has lot of well written and easily digestible content. The most relevant being the [language spec](https://go.dev/ref/spec). Outside of the official stuff I'm aware only of Dave Cheney's [blog](https://dave.cheney.net/) being consistently solid. – mkopriva Mar 05 '22 at 12:56
  • 1
    Naming of variables in Go is obviously not governed by the language specification (except for a well-known Go's hallmark using of capitalization of the 1st letters of identifiers to make them exported from the package); it's rather a question of style and best practices. Hence such stuff is not explicitly codified. Still, there are good "alost official" guidelines: https://github.com/golang/go/wiki/CodeReviewComments and https://go.dev/blog/package-names and https://go.dev/blog/organizing-go-code (old, but everything about names still 100% holds). – kostix Mar 05 '22 at 13:01
  • 1
    See also: https://stackoverflow.com/questions/23482068/ – kostix Mar 05 '22 at 13:02
  • 2
    Also here on SO [@icza](https://stackoverflow.com/users/1705598/icza) has by far the most comprehensive answers under the Go tag. If you're interested in a specific topic, try searching through his answers and you just may find what you are looking for. For example: ["pointer"](https://stackoverflow.com/search?tab=votes&q=user%3a1705598%20pointer) – mkopriva Mar 05 '22 at 13:02

2 Answers2

1

It doesn't matter the name of the parameter, you just need to obey the function signature

func (firstParameter http.ResponseWriter, secondParameter http.ResponseWriter)
0

I believe what you asking is, is it idomatic to use r and w. I don’t think it is. So long as you give the parameters reasonable names (i.e. they don’t hinder readability) you are fine.