Factor out song retrieval and printing. Allow request() to benefit from '|' operator. #10

Merged
dsc merged 1 commits from scoobybejesus/ircradio:master into master 6 months ago

Request should now allow 2nd_needle

Request should now allow 2nd_needle
scoobybejesus added 1 commit 7 months ago
scoobybejesus force-pushed master from f51b523cd9 to 2b9caab78b 7 months ago
scoobybejesus force-pushed master from 2b9caab78b to 88e03e1a22 7 months ago
scoobybejesus force-pushed master from 88e03e1a22 to 662bfb0d68 7 months ago
scoobybejesus force-pushed master from 662bfb0d68 to 14c3d5c163 7 months ago
scoobybejesus force-pushed master from 14c3d5c163 to 47c7616cac 7 months ago
scoobybejesus force-pushed master from 47c7616cac to e15b0e943e 7 months ago
scoobybejesus force-pushed master from e15b0e943e to 8294cd4b8f 7 months ago
scoobybejesus force-pushed master from 8294cd4b8f to c33b3ffd50 7 months ago
scoobybejesus changed title from Incorporate _search into request(). to Factor out song retrieval and printing. Allow request() to benefit from '|' operator. 7 months ago
scoobybejesus force-pushed master from c33b3ffd50 to 4acddc9660 7 months ago
scoobybejesus force-pushed master from 4acddc9660 to 238464b5d3 7 months ago
scoobybejesus force-pushed master from 238464b5d3 to 06aebe691c 7 months ago
scoobybejesus force-pushed master from 06aebe691c to a4930649fc 7 months ago
Poster

One thing that sticks out to me is that _return_song_results() is called in two places(search()and request()), and in both cases, there might be no songs as a result of the search, and both calling functions assume that _return_song_results() will print the result of the search ("None found") in that case. Importantly, search() and request() will only call _print_song_results() if songs != None (and request() only calls if there's more than one).

But in the case where there are multiple songs, "Multiple found" is printed in _print_song_results(). "Multiple found" could just as easily be printed from _return_song_results(). Or maybe you'd rather put the "None found" in _print_song_results().
The main reason I didn't do the latter is because there are two versions "None found" (the other being "None found after '|' "), and I would rather not return a variable and then pass it to _print_song_results() in order to have the two versions of "None found", because that feels unnecessarily messy and possibly not pythonic.

I can't think of a better way to architect this. Maybe it's somewhat a matter of taste. As mentioned above, _print_song_results() only gets called when there are results from a search. Perhaps if this "code invariant" were somehow made more clear, then the rest would make sense too. I don't think I like the idea of renaming _return_song_results() as _return_song_results_and_or_print_none_found() or renaming _print_song_results() as _print_song_results_only_if_there_are_results(). But maybe you do. Or maybe you like commenting code in a case like this.

The diff isn't super pretty, but the code itself feel pretty good to me.

One thing that sticks out to me is that `_return_song_results()` is called in two places(`search()`and `request()`), and in both cases, there might be no songs as a result of the search, and both calling functions assume that `_return_song_results()` will print the result of the search ("None found") in that case. Importantly, `search()` and `request()` will only call `_print_song_results()` if `songs != None` (and `request()` only calls if there's more than one). But in the case where there are multiple songs, "Multiple found" is printed in `_print_song_results()`. "Multiple found" could just as easily be printed from `_return_song_results()`. Or maybe you'd rather put the "None found" in `_print_song_results()`. The main reason I didn't do the latter is because there are two versions "None found" (the other being "None found after '|' "), and I would rather not return a variable and then pass it to `_print_song_results()` in order to have the two versions of "None found", because that feels unnecessarily messy and possibly not pythonic. I can't think of a better way to architect this. Maybe it's somewhat a matter of taste. As mentioned above, `_print_song_results()` only gets called when _there are_ results from a search. Perhaps if this "code invariant" were somehow made more clear, then the rest would make sense too. I don't think I like the idea of renaming `_return_song_results()` as `_return_song_results_and_or_print_none_found()` or renaming `_print_song_results()` as `_print_song_results_only_if_there_are_results()`. But maybe you do. Or maybe you like commenting code in a case like this. The diff isn't super pretty, but the code itself feel pretty good to me.
dsc merged commit 60f3b6c53b into master 6 months ago
dsc commented 6 months ago
Owner

Thanks
👍 💯

Thanks 👍 💯
The pull request has been merged as 60f3b6c53b.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: dsc/ircradio#10
Loading…
There is no content yet.