Skip to content

Stream2py design notes

Thor Whalen edited this page Nov 19, 2021 · 12 revisions

Interface options in making a stream reader

A few proposals

straight code

source_reader = SourceReader(**s)
stream_buffer = StreamBuffer(source_reader, **b)
buffer_reader = BufferReader(stream_buffer, **r)

fluent interface

buffer_reader = SourceReader(**s).stream_buffer(**b).buffer_reader(**r)

nested aggregator

buffer_reader = Aggreg(
    source_reader=SourceReader(**s),
    stream_buffer=StreamBuffer(**b),
    buffer_reader=BufferReader(**r)
)

flat aggregator

buffer_reader = Aggreg(**s, **b, **r)

Discussion

As a general rule, I'm for breaking things into small objects like the three objects we're talking about here, then combining them to get interfaces that might be more appropriate for some contexts.

This means that the two aggregators above don't preclude the other two proposals. In fact, I would argue that they should be built using the fluent interface or straight code methods.

The nested aggregator nicely separates the three roles and their parameters. The same parameter name (with different values) can be used in more than one role. On the other hand, the flat aggregator allows one to share and align parameters, and only a few of the params are actually required, allows for a sparse simple interface for most cases.

More proposals

Lets take this as the point of departure:

stream_reader = SourceReader(**s).stream_buffer(**b).mk_reader(**r)

We want to make a StreamReader that gives us the chain automatically with default (smart or not) b and r params, but with a means to specify these if and when needed.

We could do the flat version:

stream_reader = StreamReader(**s, **b, **r)


Or more like this this:

```python
dflt_stream_reader = StreamReader(**s)  # .stream_buffer(**b).mk_reader(**r) done automatically with defaults
stream_reader_with_custom_reader = StreamReader(**s).mk_reader(**r)  # .stream_buffer(**b) done automatically with defaults
stream_reader_with_custom_buffer = StreamReader(**s).stream_buffer(**b)  # .mk_reader(**r) done automatically with defaults
stream_reader_with_all_customs = StreamReader(**s).stream_buffer(**b).mk_reader(**r)

A problem to keep an eye on with the above is that we want multiple readers to share the same source and buffer.

Clone this wiki locally