Skip to main content
11 events
when toggle format what by license comment
Nov 12, 2024 at 0:50 vote accept Ganesh Tata
Nov 11, 2024 at 22:20 comment added indi “But on all sytems 1 works as failure…” Not true. On OpenVMS 1 would be success. The only portable return values are 0, EXIT_SUCCESS, and EXIT_FAILURE.
Nov 11, 2024 at 22:04 comment added pacmaninbw @LokiAstari I like self documenting code, and EXIT_SUCCESS and EXIT_FAILURE are clearly self documenting. For beginners starting out return 0 and return 1 may be harder to remember, that was based on what Unix programs should return on exit.
Nov 11, 2024 at 22:00 comment added pacmaninbw @GaneshTata You can still keep get_text_counts() but internally it should call multiple functions.
Nov 11, 2024 at 21:58 comment added Ganesh Tata Thank you for the wonderful feedback! Regarding the function complexity point: Can I still keep get_text_counts() but break the internal code into smaller functions, or would it be better to do something like get_byte_counts, get_word_counts etc.?
Nov 11, 2024 at 17:53 comment added Loki Astari The use of EXIT_FAILURE is to prevent you from returning a value that accidentally becomes zero (on some systems the return value is truncated to 8 bits). So any value over 255 becomes zero and thus looks like a success, its to prevent accidents like that. But on all sytems 1 works as failure and you can use other values to indicate other things (especially if you control the application calling this one you can pass meaning in the error code) but you do need to be careful and it becomes less portable to other systems.
Nov 11, 2024 at 17:50 comment added Loki Astari I also disagree that EXIT_SUCCESS is better. Both 0 and EXIT_SUCCESS indicate successes (note they don't have to be the same value). But I would argue that using 0 is more standard (especially since it is the default when there is no return value in C++) and as a result more consistent if you want it to work with scripts (especially since most scripts will check for zero) so if EXIT_SUCCESS is not zero you are going to get some surprising behaviors.
Nov 11, 2024 at 17:43 comment added Loki Astari Echo what Toby mentioned on search path. If you have installed libraries with some package manager they live in a location where <> will find them. If they are local to only things that you use then "" is more appropriate. So if CLI/CLI.hpp is something you have installed on your system then use <> if it is something you have pulled in locally to the project by some build processes then use "".
Nov 11, 2024 at 7:25 history edited Toby Speight CC BY-SA 4.0
Various copy-edit improvements
Nov 11, 2024 at 7:19 comment added Toby Speight Choice of <> vs "" for includes is really about search path, i.e. whether the header lives in our own work tree or it comes from an installed library. So I disagree with your reasoning there (but might agree with the recommendation, depending on how the library is installed).
Nov 11, 2024 at 2:31 history answered pacmaninbw CC BY-SA 4.0