jquery
jquery copied to clipboard
naming doesn't follow Go style for initialisms
hey,
a nitpick I noticed when looking at JQuery: some of the naming doesn't follow Go style for initialisms
https://github.com/golang/go/wiki/CodeReviewComments#initialisms
examples that go against this: SetHtml(), Css(), Html() etc.
It was a deliberate design decision to stick to the jQuery-isms as close as possible: Given that the jQuery has a huge head start regarding popularity and developer mindset it would create some friction switching to Go-isms. This way you can look up the well documented jQuery API and and help yourself putting your code together.
This is the reasoning behind it, it is not a "hard" decision which can not be changed. What would be a concrete benefit of sticking to Go Style ?
How would you handle the get/set scenario in idiomatic Go Style ?
///javascript code:
var gotHtml = $("#someid").html();
var jQueryInstance = $("#someid").html("<b>some html</b>");
And last: would you like to give up non-idiomatic (from a Go point of view) jQuery chaining of method calls ? It makes your code succinct.
I guess that is a defensible stance, but who is your target audience? i imagine that people who are accustomed to Go are going to find GopherJS more interesting than people that are fluent in JS. If you are accustomed to Go, the inconsistent naming is jarring.
You didn't yet answer my questions. Regarding your question: Target audience are people with jQuery know-how. Googling for "jQuery" gives 65 700 000 hits, for "Golang" I get 370 000 hits. The jQuery binding is out for some time and nobody complained about that so far, until more people show up with the same opinion I propose to stick to the current approach.
I think we misunderstand each other. My suggestion is to use the name SetHTML rather than the current SetHtml. Similar for other names with abbreviations.
What I found strange is that the topic on "initialisms" does not appear in Effective Go but there is a topic on mixed caps and Getters:
https://golang.org/doc/effective_go.html#mixed-caps https://golang.org/doc/effective_go.html#Getters
What about other bindings, like for example: https://godoc.org/honnef.co/go/js/dom or https://godoc.org/github.com/gopherjs/gopherjs/js ?
I propose to discuss this point upstream in the gopherjs project.
For now on my ToDo list are:
- Sync the bindings with the upcoming jQuery 3.0 release
- Improve the test setup, maybe using "gopherjs serve"
Maybe effective Go should also be updated, but the precedent in the standard lib is clearly there. See eg. function names in https://golang.org/pkg/crypto/rsa/
https://godoc.org/honnef.co/go/js/dom looks to follow the standard. It says HTML rather than Html.
https://godoc.org/github.com/gopherjs/gopherjs/js has no initialisms. Overall, the gopherjs package looks clean, except for https://godoc.org/github.com/gopherjs/gopherjs/compiler/typesutil where it says Js rather than JS
I can see now, the rsa library is a good showcase. I propose to update the Api when doing the 3.0 upgrade, contributions welcome !
Looking over the Api at https://godoc.org/github.com/gopherjs/jquery are the more Initialisms than "CSS" and "HTML" ?
CSS and HTML are the only initialisms I see now that are not already all-caps. We have several instances where these are already caps (ParseHTML()
) and where other initialisims are all caps (IsXMLDoc()
, ParseJSON()
, etc).
I might suggest supporting both names in this library, where jQuery uses CamelCase. Even if the decision were made to stick with Go-style initials, this might be wise for backward compatibility, any way.
-
HTML()
+Html()
-
SetHTML()
+SetHtml()
-
CSS()
+Css()
-
SetCSS()
+SetCss()
-
CSSArray()
+CssArray()