DEV Community

loading...

Discussion on: Are you using Void correctly?

Collapse
somedood profile image
Basti Ortiz

I think this is a very interesting take on something I never really thought about. I consider myself to be quite strict about the semantics of code, so this comes as a surprise that this has never crossed my mind.

If I may ask, what may be the other valid use cases for void calls besides logging?

Collapse
designpuddle profile image
Chris Bertrand Author

Thanks, It drives me up the wall.

There really aren't many valid use cases. Any IO operations which may include logging.

Then any entry points to an app. Eg the main() func, setting global config, automapper, DI or task runners such as Grunt, Gulp etc and Test Frameworks. In principle only anything super high level, and things that could affect the global state.

Collapse
somedood profile image
Basti Ortiz • Edited

By "entry points to an app", am I correct to assume that these include event listeners?

Also, just a tiny nitpick: doesn't the main function call ideally return an integer denoting whether or not the program was successful?

Thread Thread
designpuddle profile image
Chris Bertrand Author

Yes that would be right! The main function call can be either, and it's down to the user to decide which to use. I would recommend it returning an int, but then I think you would have guessed that already 😊