Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I crossed a point in my life, I'm not sure exactly when, where reading c-style code is just difficult for me. I see something like (from a Google sample):

   func (f Draft75Handler) ServeHTTP(w http.ResponseWriter, req *http.Request)
and at first I have an actual hard time parsing it, and then I think, why can't this just be

   Draft75Handler.ServeHTTP(writer, request)
I partially regret this loss and partially rejoice in it. I'm sure it'd just take a bit of practice to pick it up again.

Edit: I know why it can't look like that (because it can't be dynamic), but its still what crosses my mind.



Some questions and observations from the other side of the fence:

How do you differentiate your simplified function declaration to a function invocation?

The latter means you must refer to the receiver (the instance of Draft75Handler) as "this" or "self". In Go, you name it explicitly (in this case "f") which makes the code more readable IMO (although "f" is a strange choice in this case).

The variable names "writer" and "request" will become wearying as you use them in the function body - better to say the exact type once (http.ResponseWriter) and use shorthand thereafter (w).

(And, obviously, omitting the type information in the function arguments doesn't work in a statically typed language.)


> (And, obviously, omitting the type information in the function arguments doesn't work in a statically typed language.)

It works just fine in Haskell for most cases.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: