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

What's the differences between helpers and utils? #808

Open
yesmeck opened this issue Jan 12, 2016 · 8 comments
Open

What's the differences between helpers and utils? #808

yesmeck opened this issue Jan 12, 2016 · 8 comments
Labels

Comments

@yesmeck
Copy link

yesmeck commented Jan 12, 2016

I mean the src/helpers and src/utils folder, what files should put in helpers folder, what should in utils folder?

@janhoogeveen
Copy link

Looks to me like /utils is a place where you can place small snippets you can use throughout the application. Small functions to build bigger things with.

/helpers is more of a place where you store code architectural snippets in my view. Things essential for bootstrapping components and developer ergonomics.

@AndrewLamYW
Copy link

AndrewLamYW commented Oct 7, 2019

Looks to me like /utils is a place where you can place small snippets you can use throughout the application. Small functions to build bigger things with.

/helpers is more of a place where you store code architectural snippets in my view. Things essential for bootstrapping components and developer ergonomics.

Hi @janhoogeveen, thanks for the answer. I couldn't quite grasp it, could you please explain in other form? Thank you :D

@thiagovilla
Copy link

I've run into this "issue" too while trying to structure a project. Here's how it fits me better:

  • index.js is the point of entry. It requires the modules in /modules
  • /modules contains the getAll.js and getById.js modules
  • /libs holds the individual steps a given module calls
  • /utils has very short and specific functions used throughout functions in /libs

@PointerToNextPole
Copy link

I just search "helper vs utils" on google and found the issue. I got the wanted answer at StackOverflow, so let me show the URL of the question at StackOverflow: What are the differences between Helper and Utility classes?

In short, the answer is:

A Utility class is understood to only have static methods and be stateless. You would not create an instance of such a class.
A Helper can be a utility class or it can be stateful or require an instance be created. I would avoid this if possible.

@pedronastasi
Copy link

pedronastasi commented Apr 29, 2023

Hope it helps someone 😄

  Helper Functions/Classes Utility Functions/Classes
Purpose Provide support or aid to other parts of the program Perform common or generic operations that are not tied to any specific part of the program
Scope Typically used within a specific module or part of the program Can be used throughout the program or in multiple programs
Dependencies Often depend on other parts of the program or external libraries Usually independent of other parts of the program
Examples Form validation functions, data formatting classes String manipulation functions, math libraries

@XinnieSol
Copy link

Nice and comprehensive explanation @pedronastasi

@sktsourav
Copy link

Is it a good practice to put the constant file inside utils folder ?

@Muilibilal
Copy link

@sktsourav you can create a "constants" folder and keep your constants.js file inside it. Better still you can have an index.js file inside there then have a different files for different contexts and export them from index.js.
This would help you keep all your constants in a centralized place whenever you decide to create constant values for different modules in your application.

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

No branches or pull requests

10 participants