3 ms·
Sadly, the code YOU wrote is suboptimal. It doesn't check for bad pointers, has no comments, doesn't take memory corruption into consideration, and assumes the
by Vocalspace 16y ago
Sadly, the code YOU wrote is suboptimal. It doesn't check for bad pointers, has no comments, doesn't take memory corruption into consideration, and assumes the replacement character is not '\0'.
You would get a C- if I graded your test.
Now you'll argue that it's just a test, but the fact is your best work should not come only when under unexpected scrutiny, as it does with impromptu tests, it should be a mental process that is not bypassed for any reason.
In this case you've thought about it for weeks and still botched it.
Kudos for trying. We'll call you if we are interested.
- RiderOfGiraffes 16y agoInteresting - thank you for your feedback. It's educational to see the different points of view. However, I wonder if you've actually taken on board either the point of the exercise, or the fact that it isn't yet finished. However, questions such as those you raise are, of course, of great interest in production code, and would be raised in the discussion this code is intended to start. If someone started to write correct code that took these things into consideration the test would be stopped - it would've served its purpose already. I'd be interested to know: * Do you think every routine, every piece of code should have comments? * Do you think every routine should test its input parameters? Every time? * Do you think every routine should be checking for memory corruption? All the time? * How do you cope with memory corruption in the program code itself? * Do you think the routine fails if the char to remove is '\0'? Are you sure? You seem to claim it does. * Do you believe that all code should always be written to the same standard? Having written code in an environment where any given memory location has a MTC (Mean Time to Corruption) of 12 hours, I have considered these issues. I'd be interested to hear your experiences in these matters. I notice also that you created your username specifically to reply to this item. Welcome to Hacker News.
- cperciva 16y agoIt doesn't check for bad pointers C is a foot-shooting language. Its basic library functions are expected to do what you tell them to do, even when it's a really bad idea. Checking for bad pointers (and how exactly you define "bad" is a rather interesting question) is clearly out of scope. has no comments True, but I'm not convinced there's much point on such a trivial piece of code. doesn't take memory corruption into consideration Given that there is no redundant information available, this is an impossible challenge. and assumes the replacement character is not '\0'. Try re-reading the code a bit more closely.
- callahad 16y agohas no comments, Does the copious prose not count?
- nuxi 16y agoBut none of the things you mention were part of the requirement. Furthermore, I'd be interested to know how one checks for "bad pointers" and what exactly _you_ mean by that - just NULL, pointers to read-only memory/string literals, or something else (as far as C is concerned, there are no "bad pointers", the system underneath may disagree though). Care to elaborate on how you would've prepared a similar test?