Randy W. Sims
10/12/2004 8:50:00 AM
Jamis Buck wrote:
> Randy W. Sims wrote:
>
>> Are there any Ruby modules that allow documentation to act as source
>> code? I was thinking of the problem of how souce code sometimes
>> diverge from its documentation. So maybe there could be a way to
>> specify the interface: the number of arguments and their types in the
>> documentation, and possibly pre- and post-conditions, and then the
>> documentation would be turned into code at runtime. I guess this would
>> be implemented something like Perl's source filters[1]. Possibly some
>> constants and such could be defined this way as well, version numbers,
>> etc.
>>
>> I'm not sure if this is a good idea or not; I haven't completely
>> thought it through. It seems like I've read about this being done
>> before in some other langage, but a brief search hasn't turned up
>> anything.
>>
>
> I haven't seen it done in Ruby, but the general idea is called "literate
> programming". If you google for that term, you'll find lots of information.
Doh! That's the term I've been trying to think of. Thanks.
> I'm not a big supporter of the idea, though I've never done more than
> tinker with it. I'd be curious to see what you come up with if you do
> find a way to do it in Ruby, though.
I'm not looking for anything comprehensive. Just something to reduce the
redundencies that often exist at least for the common cases. Just small
stuff like (if you'll forgive a perl example, I'm more familiar with it)
perl modules often declare a version:
our $VERSION = 1.03;
Then somewhere else in the POD documents, you'd have:
=head1 VERSION
blah blah version 1.03
=cut
So anytime you change the version, you have to remember to change it in
multiple places. Ideally, you could just change the docs.
This is mostly just a curiosity at the moment. I just thought I'd ask if
anything like that was available that I could play with.
Randy.