Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

naming doesn't follow Go style for initialisms #13

Open
hanwen opened this issue Mar 2, 2016 · 8 comments
Open

naming doesn't follow Go style for initialisms #13

hanwen opened this issue Mar 2, 2016 · 8 comments

Comments

@hanwen
Copy link

hanwen commented Mar 2, 2016

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.

@rusco
Copy link
Member

rusco commented Mar 2, 2016

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.

@hanwen
Copy link
Author

hanwen commented Mar 2, 2016

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.

@rusco
Copy link
Member

rusco commented Mar 2, 2016

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.

@hanwen
Copy link
Author

hanwen commented Mar 3, 2016

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.

@rusco
Copy link
Member

rusco commented Mar 3, 2016

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"

@hanwen
Copy link
Author

hanwen commented Mar 10, 2016

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

@rusco
Copy link
Member

rusco commented Mar 11, 2016

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" ?

@flimzy
Copy link
Member

flimzy commented Jun 26, 2016

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants