On Thursday 25 February 2010 02:23:33 am Charles R. wrote:
I am doing a bit of research for a project I am helping out with - a
text editor - and the following question has been asked: what would your
dream API look like and be capable of? Obviously, the API will be
scriptable via Ruby.
First, make a low-level API. Then, join us in trying to build a “dream
top of that.
I’m not sure what it would look like, I have no idea what it’s like to
a text editor. I’d say, let’s look at the capabilities you have now,
that low-level API, and document everything, then we can start to talk
how you might improve it.
As for that higher-level API…
You may want to brush up on some Ruby idioms. For example, Ruby tends to
support the more flexible idiom of returning an object representing some
of handle in a longer operation (like reading a file or looping over a
file = open ‘foo’
line = file.readline
That’s needed in order to have full functionality, but we also expect
open ‘foo’ do |file|
file.each_line do |line|
(Note: The ‘file’ variable is identical in both cases, it’s just that
automatically handles closing the file for us, probably ensuring it
matter what kind of exceptions are thrown, etc.)
The same works for generating output. Look at Builder, Erector, etc, for
examples of how that can look.
So without knowing your editor’s capabilities in detail, and without
programming an editor, I don’t really know. You’ll at least want to
low-level API, in case people disagree with your approach, or in case
else comes up with a better idea. But if you want a higher-level API,
something that’ll blow us away, something like Hpricot but for text
That takes artistry.