Replies: 6 comments 5 replies
-
I agree that a significant portion of each example is a copy-paste. However, I strongly disagree with the rest of this proposal for the following reasons:
Macros like you proposed are useful internally - see |
Beta Was this translation helpful? Give feedback.
-
Hi there, First off: Thank you for making RadioLib! Like I said, I see tradeoffs. I agree with you that obscuring what happens underneath is not good in principle. But let's look at the
As you can see, the author got tired of copying the same block yet once more, so the result codes were orred together. But your result codes are not bitmasks: what does the printed orred result code even mean? Without the orring, this would be a block of 50-something lines, just to issue four commands. At some point, IMHO, the value of "not obscuring what happens" loses to "seeing what happens in a few lines". I think my alternative is massively more readable, and thus better at teaching people how to work with RadioLib, which is the point of the examples. As for the |
Beta Was this translation helpful? Give feedback.
-
(Also, I think the typical user of the library might actually much appreciate these macros for their own use.) |
Beta Was this translation helpful? Give feedback.
-
In case you were to become convinced that their use in the examples would be ok, one could add the following to the header of all examples:
|
Beta Was this translation helpful? Give feedback.
-
@ropg, perhaps take a look at PR 995 where the proposed Starter code does pretty much what you are suggesting. |
Beta Was this translation helpful? Give feedback.
-
As you progress with LoRaWAN you'll find that this is a huge red herring - whilst entirely true, we'd expect this to happen 99% of the time because it's very asymmetrical - mostly uplinks, occasionally downlinks. Most of the library supports point to point activity - LW is a bit niche because it comes with a whole backend infrastructure that needs to be accounted for. |
Beta Was this translation helpful? Give feedback.
-
Hi all,
As it is, the RadioLib examples directory is full of repetition that, IMHO, isn't particularly meaningful and doesn't serve code readability or to teach the principles at hand. There's hundreds of minor variations of:
The code included at bottom of this post provides two macros,
RADIOLIB()
andRADIOLIB_OR_HALT()
. This makesRADIOLIB_OR_HALT(radio.begin());
execute the code and (if there's no hardware) print
[RadioLib] radio.begin() returned -2 (ERR_CHIP_NOT_FOUND) [RadioLib] Halted
(When using
RADIOLIB()
, the user can access the last result code afterwards in_radiolib_status
.)Imagine the
setup()
function in an example not being a jumbled mess of if-blocks but looking something like:I can see the tradeoffs, but compared to what's there now, I think the increase in readability and thus understandability is obvious. Not to mention it'll be considerably less tedious to write examples.
RadioLib_convenience.h
RadioLib_convenience.cpp
Beta Was this translation helpful? Give feedback.
All reactions