Earlier quoted context omitted.
Calling string manipulation functions buggy and broken because they fail when you don't pass them a string is both wrong and silly.
How do you test that something in C is a string?
Deconstructing "K&R C"
131–136 of 136 posts
Re: Deconstructing "K&R C"
#132Earlier quoted context omitted.
You don't, because you can't. That's basically the same as the beginner question, "How can you test if a pointer has been freed?"
It was a rhetorical question. What's the sense in having functions that operate on "strings" if you can't figure out what a "string" is at runtime? It's much saner to have functions operate on "strings that are 80 characters or less" or "a structure containing a integer `length` and an array of `length` chars."
The point is that the function is not buggy. You may not like the specification for it. You may think it should be designed differently. This is not the same as the code being buggy.
Re: Deconstructing "K&R C"
#133I don't see his point, really. Yes, C doesn't have a statically testable string type. And yes, the convention is that a C "string" is just an array of character data with a trailing NUL-Byte. He constructs an array without a trailing NUL-Byte - so that's not a string, but an array of characters. The fact that copy() now happily runs through memory is the expected result of the bug in the calling code. No, it's not us…
> I don't see his point, really. The point is three fold: 1. K&R has defects in it when the functions in it are used out of context because they didn't include defensive programming practices considered standard today. 2. People can learn a lot about writing good code by critiquing other code, even from masters, so I'm taking them through doing that. 3. There should be no sacred cows, and people hold K&R on a pedesta…
Maybe it would be a good idea to put a bit more stress on the "no" in "no sacred cows", that's an important point beyond just K&R. Nothing should be sacred, including "Learning C The Hard Way" - and a "question everything and everyone" mindset is generally a good thing to have as a programmer [I think I read that in "The Pragmatic Programmer" ;-)]. But other than that I now think that chapter is fine. I do apologize for the somewhat passive-aggressive form of my question.
Thanks a lot!
Re: Deconstructing "K&R C"
#134Earlier quoted context omitted.
Agreed, the example used seems very strange. Every function makes functions about it's parameters and in C null terminated string are to be assumed unless otherwise noted. The std library strcpy would just behave in an identical way. Yeah, I'm all about checking your assumptions and defensive programming but k&r is hardly as fault because you throw garbage at a random function and it segfaults. I find the idea of tea…
Yeah, I'm all about checking your assumptions and defensive programming but k&r is hardly as fault because you throw garbage at a random function and it segfaults. Maybe he should write a series on "Learn Ada the Hard Way"?
During our discussion of the redis/windows release, you mentioned your team is about to release some library code around new-years day. Has that release happened? If so, where can I find it?
Thanks in advnace
--beagle3
Re: Deconstructing "K&R C"
#135Earlier quoted context omitted.
Yeah, I'm all about checking your assumptions and defensive programming but k&r is hardly as fault because you throw garbage at a random function and it segfaults. Maybe he should write a series on "Learn Ada the Hard Way"?
(apologies for hijacking an unrelated thread, but I have no way of contacting you ...) During our discussion of the redis/windows release, you mentioned your team is about to release some library code around new-years day. Has that release happened? If so, where can I find it? Thanks in advnace --beagle3
Code's up here: www.762studios.com
It's been up about a week or so. (EDIT: we had it up on the first, technically.)
We're pushing out a significant update to that code in the next few days, as well as polishing the site with the bugtracker and things.
One of the big problems we ran into was function-level specialization for certain container classes--storing smart pointers in certain cases would screw up the reference counting. The code update will be fixing that.
If you want to get in touch, shoot me an email at cre1@762studios.com
Happy hacking! :)
Re: Deconstructing "K&R C"
#136Earlier quoted context omitted.
(apologies for hijacking an unrelated thread, but I have no way of contacting you ...) During our discussion of the redis/windows release, you mentioned your team is about to release some library code around new-years day. Has that release happened? If so, where can I find it? Thanks in advnace --beagle3
Yeah, sure! Code's up here: www.762studios.com It's been up about a week or so. (EDIT: we had it up on the first, technically.) We're pushing out a significant update to that code in the next few days, as well as polishing the site with the bugtracker and things. One of the big problems we ran into was function-level specialization for certain container classes--storing smart pointers in certain cases would screw up…
Looks like a solid, high quality code base from a quick look. Keep up the good work!