Hacker News new | past | comments | ask | show | jobs | submit login

Yep.

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.




Why not strlen("aha") + strlen("oho")?


Or 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.


The whole point of the code is to concatenate two C strings at runtime. That's the big problem.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: