annacrombie / plot

plot on the command line
MIT License
113 stars 9 forks source link

Input cleanup #16

Closed holmanb closed 3 years ago

holmanb commented 3 years ago

This is an initial PR towards improving the input system to help with flexibility and to allow for future features (per discussion in #13)

currently pdtry_all_buffers() and pdtry_buffer() use an argument (shift) to branch logic depending on whether plot is called with -f/-A

within those functions, however, there is relatively little shared code

At a high level this PR reduces the amount of branching (which improves readability and flexibility in my opinion) required by separating the code that doesn't require shifting into separate functions.

The git diff doesn't look great, so here's an explanation:

in pdtry_all_buffers(), most of the function was only used by the shift=1 codepath, basically this just moves the shift=0 code path out into pdread_all_available()

pdtry_all_buffers(p, 1)    ->   pdtry_all_buffers(p)
pdtry_all_buffers(p, 0)    ->   pdread_all_available(p)

most of code path that was shared by shift=1 and shift=0 in pdtry_buffer() was previously the code used for calculating the average, this now has its own function:

pd_avg()

and since the remainder of the code in pdtry_buffer() was nested branching based on the shift value, this code was separated into its own *_shift()/*_noshift() functions

pdtry_buffer(.., 0, ..)   -> pdtry_buffer_noshift()
pdtry_buffer(.., 1, ..)   -> pdtry_buffer_shift()
annacrombie commented 3 years ago

I still haven't taken a look at this, but I wanted to let you know its on my TODO list. Hopefully I'll get to it later this week

annacrombie commented 3 years ago

Sorry this took so long, LGTM