-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Some functions should be rewritten into methods #285
Comments
I speak only for A window should have methods only to manipulate that window. Any objects should have methods only to manipulate itself. Some external objects may want to use your window object, in this case a renderer, so be it. But they are not your concern. You cannot write a new method for your window every time somebody uses it to init their object. For instance, bytes.NewBuffer is not a method of Just look at the code, i think it looks weird. renderer := window.CreateRenderer()
renderer.Clear()
renderer.Copy()
renderer.DrawRect()
renderer.Present()
renderer.Destroy() Please remember i didn't check any other function, i merely talk about |
@dodobyte if this is the case for object creation, then we have some rogue methods that already do this as methods. // CreateTexture returns a new texture for a rendering context.
// (https://wiki.libsdl.org/SDL_CreateTexture)
func (renderer *Renderer) CreateTexture(format uint32, access int, w, h int32) (*Texture, error) {...} // CreateTextureFromSurface returns a new texture from an existing surface.
// (https://wiki.libsdl.org/SDL_CreateTextureFromSurface)
func (renderer *Renderer) CreateTextureFromSurface(surface *Surface) (*Texture, error) {...} This one is weird, not a simple getter. Though I'd rather leave is as it is now. // GetSurface returns the SDL surface associated with the window.
// (https://wiki.libsdl.org/SDL_GetWindowSurface)
func (window *Window) GetSurface() (*Surface, error) {...}
We need to decide what to do with those. This one definitely needs to be rewritten, since its a simple getter: // GameControllerMapping returns the current mapping of a Game Controller.
// (https://wiki.libsdl.org/SDL_GameControllerMapping)
func GameControllerMapping(ctrl *GameController) string {...} |
@malashin, i see. Consistency is more important than anything else. SDL doesn't imply what should be a method of what. But there are some hints in documentation, namely categories. I believe the original creator of this library also took categories into consideration. File names show that. API's in CategoryRender should be methods of
One may argue that
So it should be obvious. Window functions such as Finally,
So it's not a method of For Thanks. |
I fixed the I'm not really sure about what to do about the rest. Both of you have some valid points. I think we should wait until there's a strong case for either of the options before we make further changes. If it is already working okay for everyone then we don't need to make any changes. I was thinking of providing both options (method and function) but I guess people wouldn't like that in the long run :P |
First of all, the reason which @dodobyte mentioned (function's category) is not a good point to consider it seriously. Renderer has its own category just because it is big enough to have it.
I think it transparently shows up 'HAS-A' relations. I.e:
|
For example this three can be methods for
*Window
,*Surface
and*GameController
:You can find more with this regexp expression:
The text was updated successfully, but these errors were encountered: