On Sat, Apr 13, 2013 at 8:15 AM, Nick Wellnhofer <[email protected]> wrote:
> The only thing I don't like is the choice of 0 as sentinel value. I'd prefer
> -1 or any positive value beyond the Unicode planes.

Good point.  How about a symbolic value, `DONE`, or in full,
`CFISH_CBITER_DONE` and eventually also `CFISH_STRITER_DONE`?

    while (CFISH_STRITER_DONE != (code_point = Cfish_StrIter_Next(iter))) {
        ...
    }

FWIW, I'm not a fan of sentinels like UINT32_MAX which don't make sense in
high-level languages with a single integer type.  I don't expect that we'll do
a lot of string iteration in high-level host languages, but it's nice to set a
precedent going forward that it's idiomatic for Clownfish iterators to have
symbolic sentinels if any.  Sentinel return values in C are a common source of
bugs -- e.g. testing for -1 when the function may indicate failure by
returning any negative number.

> After reaching the end of the string, I can see two options which both have
> their pros and cons:
>
>     * Change to a new iterator state ("beyond string boundary") and throw
>       an exception on every subsequent access (like in your example below).
>     * Keep returning the sentinel value on calls to Next() but allow to
>       move backward via Prev(). This can result in an infinite loop in
>       faulty code.

I don't have a strong opinion.

> I think the string iterators are good candidates for "zombie" objects.
> They're small and typically only used within a single function. But +1 for
> not exposing ZombieIterators publicly.

OK, we agree on the important stuff. :)

What do you think of putting a flag into CharBuf/String which indicates how it
should deallocated?

    void
    CB_destroy(CharBuf *self) {
        if (!(self->flags & CB_HEAP_ALLOCATED)) {
            THROW(ERR, "Can't Destroy non-heap-allocated CharBuf");
        }
        ...
    }

That would allow us to get rid of the Zombie classes.  Rationale: using
subclassing to control memory allocation is odd, plus the name "Zombie" isn't
the greatest.

On the other hand, if the zombies can't escape from the core, maybe it doesn't
matter so much.

Marvin Humphrey

Reply via email to