Tag Info

Hot answers tagged

6

Leave it to your main function to quit the program. Your check function's sole purpose should be to check parameters and return a valid / invalid state. IMHO it shouldn't even be responsible of printing the end user message. The least responsibility you give to a method, the easier it will be to read, reuse, document and test.


3

I'm hesitant to terminate operation in a method other than the main method, simply because it makes it harder to reuse the operation without modification, either in your application or in another application. I would prefer returning an error condition from the method that can be checked by the caller or throwing an exception or whatever similar mechanisms ...


1

Do 1 thing at a time in your functions, that way you can document and reuse them. So if your check function simply checks a value and returns a boolean, you can reuse it anywhere you have similar requirements. If it exits, then it is only valuable in this 1 program. As a best practice, exiting within functions is not a good thing to do, there are cases ...


1

In my opinion only the main() function should be responsible for stopping the program. Having a separate function to check the validity of the arguments makes this part easier to test. And think about what happens if your program expands; if you suddenly had half a dozen methods that could potentially cause the program to exit then I think you would run into ...



Only top voted, non community-wiki answers of a minimum length are eligible