Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ethan (3163)

ethan
  reversethis-{ed. ... rap.nov.olissat}

Being a 25-year old chap living in the western-most town of Germany. Stuying communication and information science and being a huge fan of XS-related things.

Journal of ethan (3163)

Sunday September 14, 2003
02:53 AM

on Perl/C/Ruby strings

[ #14694 ]

For a while I was wondering why the XS-portion of my on-going String::Ruby was so ugly and wordy. It's now over 60K, with a lot of functions taking five or six argument. A not untypical prototype of such a function looks like:

/* Returns an array of the fields */
char ** split (
    register char *string, int len,
    register char *delim, int dlen,
    int limit,
    int **lens, int *nelems      /* length of each field and how many we have */
);


But then it dawned on me that this is probably not so much my fault but rather has something to do with the difference between C strings and those of Ruby and Perl. Most functions from string.h will fail miserably when the strings contain the NULL byte, whereas this is no problem for Perl or Ruby.

Subsequently, for every string I pass to a function I need an additional length parameter. Instead of using the str* family of functions, I have to use mem* instead. This is the reason why I am progressing with the speed of a turtle. Had I thought about this before, I would have created a structure for the string. Too late now.

On the other hand, it's pretty fun. C is still a wonderfully expressive and idiomatic language. It'll also enforce some B&D strategies on the programmer. Not by making silly rules what you may not do but rather by producing segfaults which is much more convincing.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.