[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: API Design
- From: tobias@...
- Date: Mon, 18 Sep 2017 20:18:20 +0200
Hi there,
I'm designing a library which has a Buffer module that allows to
contain binary data. Think of it as a string just with less features
:-P ... except it is mutable. Now I'm writing a companion module
called Buffer.Segment that allows access to just a limited part of the
buffer which is defined by an offset and a length. I'd plan the API
look like this:
b = Buffer( 1024 ) -- buffer with 124 bytes
s = Segment( b ) -- creates a segment starting at the first
byte of the buffer as long as the buffer itself
s1 = Segment( 128, 256 ) -- Segment with 128 byte offset and 256 bytes length
s2 = Segment( 439 ) -- this is the question, shall this be:
- a segment starting at byte 439 and have a
length to the end of the buffer, or
- a segment starting at first byte being 439 bytes long
I don't think there is a 'right' answer, but to all those people who
work with this kind of stuff, what would feel more natural to you?
Also, does Segment( offset, length ) makes more sense than Segment(
length, offset ) ?
Thanks for the input,
- Tobias