4 ms·
I disagree - there's an entire class of problems in C that stem from something that isn't in the languages you mentioned: manual memory management.
by jiaweihli 12y ago
I disagree - there's an entire class of problems in C that stem from something that isn't in the languages you mentioned: manual memory management.
- angersock 12y agoYep. That, and the lack of a sufficiently-abstract concept of strings. To wit, let's get the length of two strings in Ruby and C. Ruby: ("aha" + "oho").length C: char buffer[1024]; // lol i hope this doesn't overflow memset(buffer,0,1024); strcat(buffer, "aha"); strcat(buffer, "oho"); return strlen(buffer); And that C version? Still not always safe; consider the case where a string overflows, where somebody else fucks up that memory in the stack by (say) a bad variadic arg invocation or array access out-of-bounds. Oh, and is that string length including the null terminator (no)? And why do we even care about null terminators unless we're doing low-level memory frobbing? Anyways, imagine that sort of arcana multiplied across every string operation in your dumb little script. It's awful.
- endgame 12y agoWhy not strlen("aha") + strlen("oho")?
- angersock 12y agoOr even: strlen("ahaoho") The C code more closely reflects what the Ruby is doing, but otherwise yes, you're correct. In C++ I could probably get it all done at compile time anyways.
- JetSpiegel 12y agoThe whole point of the code is to concatenate two C strings at runtime. That's the big problem.