-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Style Decision: Namespacing functions with class/static #10844
Comments
The static function thing seems to be overly restrictive, so we'll probably end up having a bunch of special cases for when we don't want to use static functions in classes. For example, it's not clear to me how to reconcile static functions on a class with traditional stateless react components, unless we created a bunch of classes each with only a single static function, which would probably be named I think better guidelines around destructured imports would likely address most of the pros you list in favor of the class approach. |
I'm a big fan of keeping modules pretty limited and generally aim for a single function/class per module. I would find it very annoying if I had to wrap each of those functions in a class and address then as |
Thanks everyone, individual exported functions for the unanimous win! Much appreciate the input! |
This was an interesting experiment, by the way. With pretty low investment from the team, you were able to turnaround asynchronously on a decision based on consensus for a code style idea. It may break down for larger or more contentious discussions, but it's great starting point in general. Had this been contentious, we would have seen a lot of back and forth in comments and could have brought the discussion to zoom or something, and we'd still have a concrete proposal like this to provide context as well as somewhere to log a decision for future generations. It also gives the community an opportunity to participate. We should do this more for concrete proposals like this. |
I have a personal preference for namespacing functions by putting them inside a class and marking them as static. Ex:
I've checked in code like this in a couple places:
https://github.com/elastic/kibana/blob/master/src/core_plugins/kibana/public/dashboard/filter_utils.js
https://github.com/elastic/kibana/blob/master/src/ui/public/utils/string_utils.js
and have more code in a view/edit PR like this (#10585)
The other common way of doing this in our code base is by exporting each function individually:
I'd like to poll the team to see if there is a strong consensus for doing it one way or the other, so I can be consistent if there is.
The reason I prefer the namespacing:
@kjbekkelund gave some reasons to prefer exporting the individual function:
If you prefer the class/static namespacing, 👍 this issue. If you prefer exporting functions individually, 👎 this issue. If you have another preference, comment, and if you don't care either way, then you can go about your day. 😸
The text was updated successfully, but these errors were encountered: