[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Ruby extension tutorial

Wim Vander Schelden

1/22/2007 12:10:00 AM

Wim Vander Schelden schreef:
> Hi,
>
> I just finished a tutorial about writing simple ruby extensions.
> I was hoping you guys could give me some feedback on what you think
> about it.
>
> If you find any mistakes (code, spelling, grammar and explanation), I
> would also appreciate it if you told me about them?
>
> I'm looking for critisism - I hope to improve the article.
>
> kind regards,
>
> Wim
>
Silly me, I forgot to paste the link, here you go:

http://nanoblog.ath.cx/index.rb?module=readmor...

- Wim


11 Answers

GD

1/22/2007 12:24:00 AM

0

Hey Wim,

Change "fase" to "phase".

Also, I think there is a typo in the opening. Where you say
"Ruby is slow", I think what you mean is "Ruby is an extremely
powerful and flexible language". It's an understandable mistake,
all of the keys are so close to each other. ;)

Thanks for the section and examples on Ruby mark-and-sweep, this
is something I've been having some trouble with.

Garth

Wim Vander Schelden wrote:
> Wim Vander Schelden schreef:
>
>> Hi,
>>
>> I just finished a tutorial about writing simple ruby extensions.
>> I was hoping you guys could give me some feedback on what you think
>> about it.
>>
>> If you find any mistakes (code, spelling, grammar and explanation), I
>> would also appreciate it if you told me about them?
>>
>> I'm looking for critisism - I hope to improve the article.
>>
>> kind regards,
>>
>> Wim
>>
> Silly me, I forgot to paste the link, here you go:
>
> http://nanoblog.ath.cx/index.rb?module=readmor...

Daniel Finnie

1/22/2007 1:05:00 AM

0

I like the content of the tutorial, and I've been curious about writing
C extensions for a while.

One thing, though, is that I believe you have misspelled phase and fase.

Dan

Wim Vander Schelden wrote:
> Wim Vander Schelden schreef:
>> Hi,
>>
>> I just finished a tutorial about writing simple ruby extensions.
>> I was hoping you guys could give me some feedback on what you think
>> about it.
>>
>> If you find any mistakes (code, spelling, grammar and explanation), I
>> would also appreciate it if you told me about them?
>>
>> I'm looking for critisism - I hope to improve the article.
>>
>> kind regards,
>>
>> Wim
>>
> Silly me, I forgot to paste the link, here you go:
>
> http://nanoblog.ath.cx/index.rb?module=readmor...
>
> - Wim
>
>
>

Tim Hunter

1/22/2007 1:13:00 AM

0

Wim Vander Schelden wrote:
> Wim Vander Schelden schreef:
>> Hi,
>>
>> I just finished a tutorial about writing simple ruby extensions.
>> I was hoping you guys could give me some feedback on what you think
>> about it.
>>
>> If you find any mistakes (code, spelling, grammar and explanation), I
>> would also appreciate it if you told me about them?
>>
>> I'm looking for critisism - I hope to improve the article.
Nice work! Here's a couple of nitpicks...

You recommend using the "rb_" prefix on classes, modules, etc., but I'd
argue that rb_-prefixed names should be reserved for things defined by
Ruby itself, and your extension should use some other naming convention.

You use names_array->ptr[i] to access elements in an array. My choice
would be to use rb_ary_index instead, to put a little logical distance
between my code and the RArray structure definition. You could use
rb_ary_length to get the array size as well.

Regarding "Where to go from here," another good learning resource is the
C sources for the builtin classes. I frequently refer to string.c,
array.c, io.c, etc. to see how things should be done.

Wim Vander Schelden

1/22/2007 8:40:00 AM

0

Thank you all for your comments!
>
> Change "fase" to "phase".
Doh. Changed.
>
> Also, I think there is a typo in the opening. Where you say
> "Ruby is slow", I think what you mean is "Ruby is an extremely
> powerful and flexible language". It's an understandable mistake,
> all of the keys are so close to each other. ;)
I fixed that, that always happens to me, my keyboard must have been low
on batteries
>
> Thanks for the section and examples on Ruby mark-and-sweep, this
> is something I've been having some trouble with.
Your welcome :)
> You recommend using the "rb_" prefix on classes, modules, etc., but
> I'd argue that rb_-prefixed names should be reserved for things
> defined by Ruby itself, and your extension should use some other
> naming convention.
You're right, I've changed that now.
> You use names_array->ptr[i] to access elements in an array. My choice
> would be to use rb_ary_index instead, to put a little logical distance
> between my code and the RArray structure definition. You could use
> rb_ary_length to get the array size as well.
Hmmm I never even heard of that, would probably be better. I'll look
into it after my exams, and if I like it, I'll change it.
> Regarding "Where to go from here," another good learning resource is
> the C sources for the builtin classes. I frequently refer to string.c,
> array.c, io.c, etc. to see how things should be done.
You're right, I added that.
> One item on my wishlist would be to show (in perhaps a sidebar) how to
> use mkrf instead of mkmf.

I haven't heard of mkrf yet, but I'll also check that out after my
exams. Thanks for the suggestion.

Wim

Eric Hodel

1/22/2007 9:20:00 AM

0

On Jan 21, 2007, at 16:10, Wim Vander Schelden wrote:
> Wim Vander Schelden schreef:
>> I just finished a tutorial about writing simple ruby extensions.
>> I was hoping you guys could give me some feedback on what you
>> think about it.
>>
>> If you find any mistakes (code, spelling, grammar and
>> explanation), I would also appreciate it if you told me about them?
>
> http://nanoblog.ath.cx/index.rb?module=readmor...

> exit unless have_header("stdio.h")

I'd change this to:

abort 'need stdio.h' unless have_header("stdio.h")

but other than that, thank you, thank you, thank you for using an
example that doesn't proceed to write a Makefile when the right
thingies aren't found. I think about half the C extensions I've
installed puke somewhere after attempting to build rather than puking
cleanly in extconf.rb.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


Wim Vander Schelden

1/22/2007 9:46:00 AM

0

Eric Hodel schreef:
> On Jan 21, 2007, at 16:10, Wim Vander Schelden wrote:
>> Wim Vander Schelden schreef:
>>> I just finished a tutorial about writing simple ruby extensions.
>>> I was hoping you guys could give me some feedback on what you think
>>> about it.
>>>
>>> If you find any mistakes (code, spelling, grammar and explanation),
>>> I would also appreciate it if you told me about them?
>>
>> http://nanoblog.ath.cx/index.rb?module=readmor...
>
>> exit unless have_header("stdio.h")
>
> I'd change this to:
>
> abort 'need stdio.h' unless have_header("stdio.h")
>
> but other than that, thank you, thank you, thank you for using an
> example that doesn't proceed to write a Makefile when the right
> thingies aren't found. I think about half the C extensions I've
> installed puke somewhere after attempting to build rather than puking
> cleanly in extconf.rb.
>
> --Eric Hodel - drbrain@segment7.net - http://blog.se...
>
> I LIT YOUR GEM ON FIRE!
>
>
>
Yes, I first did that as well, I thought have_header and the like
aborted all by themselves. I changed it to abort 'need stdio.h' now,
looks cleaner when it fails.

Kind regards,

Wim

Eric Hodel

1/22/2007 10:05:00 AM

0

On Jan 22, 2007, at 01:46, Wim Vander Schelden wrote:
> Eric Hodel schreef:
>> I'd change this to:
>>
>> abort 'need stdio.h' unless have_header("stdio.h")
>>
> Yes, I first did that as well, I thought have_header and the like
> aborted all by themselves. I changed it to abort 'need stdio.h'
> now, looks cleaner when it fails.

It allows you to look for headers that may have different names for
different versions like:

have_header "foo1.h" or
have_header "foo2.h" or
abort "can't find headers for foo"

--
Eric Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


Wim Vander Schelden

1/22/2007 10:13:00 AM

0

Eric Hodel schreef:
> On Jan 22, 2007, at 01:46, Wim Vander Schelden wrote:
>> Eric Hodel schreef:
>>> I'd change this to:
>>>
>>> abort 'need stdio.h' unless have_header("stdio.h")
>>>
>> Yes, I first did that as well, I thought have_header and the like
>> aborted all by themselves. I changed it to abort 'need stdio.h' now,
>> looks cleaner when it fails.
>
> It allows you to look for headers that may have different names for
> different versions like:
>
> have_header "foo1.h" or
> have_header "foo2.h" or
> abort "can't find headers for foo"
>
> --Eric Hodel - drbrain@segment7.net - http://blog.se...
>
> I LIT YOUR GEM ON FIRE!
>
>
>
I might add this to the discussion of the extconf.rb file later, I think
it deserves a little extra attention.

- Wim

William Sommerwerck

3/7/2013 2:12:00 AM

0

> It means Tea Party assholes...

Before there was a Tea Party, "tea bagging" meant slapping one's testicles in
another person's face.

Frank Berger

3/7/2013 2:23:00 AM

0

William Sommerwerck wrote:
>> It means Tea Party assholes...
>
> Before there was a Tea Party, "tea bagging" meant slapping one's
> testicles in another person's face.

Of course. That's why (some) tea party haters use the term "tea baggers." I
guess they think there's something wrong with that.