3 ms·
I wouldn't criticize anyone for posting code snippets for educational purposes without confounding the learner with all of the error checking. Pedagogy vs peda
by civility 7y ago
I wouldn't criticize anyone for posting code snippets for educational purposes without confounding the learner with all of the error checking. Pedagogy vs pedantry.
- saagarjha 7y agoIt would be a good idea to mention the error cases it doesn't handle, though.
- asveikau 7y agoI think the number of people who will copy-paste from a website and not revisit it may be alarming. It is on those who publish snippets to make these things explicit. Maybe the following is enough: if (pid < 0) { /* TODO: handle error */ } Reading the actual code I doubt it's just an oversight, the coding style used seems to lend strongly towards not thinking an error is possible: if ((pid = fork()) == 0) { //Child longTask(); } else { children[i] = pid; }
- civility 7y ago> the coding style used seems to lend strongly towards not thinking an error is possible So does every tutorial which doesn't check the return from printf or check for errors from cout. Did you notice that the parent and child are both writing to the same file descriptor? Maybe the writer should add some words and tests in his code about the inherent race condition there. A true pedant would push this even further and teach their audience how to eliminate this problem with cross process mutexes or semaphores. Better be sure to check the error codes on those calls too. I know arguing with a pedant is like wrestling with a pig, but honestly I'm more offended by the "#define N 2" than by the lack of error checking.