7 ms·
I don't like this. Is there a reason for using a stringified method prefix? I'd prefer the type safety of verb-specific methods (i.e. mux.Get, mux.Post etc) th
by jamescun 3y ago
I don't like this. Is there a reason for using a stringified method prefix?
I'd prefer the type safety of verb-specific methods (i.e. mux.Get, mux.Post etc) than magic strings validated at run time. Additionally editors can autocomplete/intellisense methods.
- c7DJTLrn 3y agoNot a fan either. I want to be sure that routing is going to work at compile time, not at runtime.
- kjksf 3y agoAdding this is so trivial. If it really, really bothers you that much: func Get(mux, uri, handler) { mux.HandleFunc("GET " + uri, handler) } Obviously skipped the types for brevity.
- tazjin 3y agoIf you want type safety, pick a type-safe language.
- badrequest 3y agoGo is type safe.
- the_gipsy 3y agoThe zero-values idea, nil, reflection and stringly-typing all over stdlib and the most popular libs makes go not type safe. Were you thinking of statically typed?
- badrequest 3y agoI genuinely have no idea what you're referring to by "stringly-typing all over stdlib". I've written Go every day for the better part of a decade and used the standard library the whole time. What standard library functions require passing in the string of a type?
- the_gipsy 3y agoYou are right, stdlib doesn't have much of stringly-typing. However the core language way of dealing with enums for example is extremely weak. It's common to have a typed enum on a struct. When parsing the struct, random string (or whatever the alias is) values sneak in and the only thing you can do is validate.
- tazjin 3y agoWe're literally in the comment thread of a new stringly typed thing being introduced to the stdlib!
- drdaeman 3y agoStruct tags is the most notorious example. They’re convenient but error-prone. I think everyone who wrote a decent amount of Go had that malformed, misspelled, or misnamed (“db” vs “sql”) tag at some point.
- deleted 3y ago[deleted]
- majewsky 3y agoType safety is a spectrum, not a binary choice. Having used Go for 10 years now, next to other popular languages like JS and Python, I think it squarely falls into the "more type-safe than not" half of the spectrum. But it's definitely a positive development that, as this discussion shows, the Overton window of type safety is shifting towards the safer part of the spectrum.
- ilyt 3y ago> I don't like this. Is there a reason for using a stringified method prefix? Backward compatibility, they didn't wanted to change function signature nor add different method for it.
- kunley 3y agoThis is discussed broadly in the proposal.
- hyperturtle 3y agoI also don't prefer using strings, but to be fair, HTTP methods are just strings when the request is received. There is some beauty in that in matches the prefix of the first line of an HTTP packet