Closed 2bndy5 closed 3 years ago
If we change it to
return !(getAddress(_nodeID) < 1) || !(getAddress(_nodeID) < 1);
I think the second check would only be evaluated if the first check fails. However, I may be mistaken in thinking C++ will actually ignore the rest of an ||
condition if the first operand is true
.
Fact: lib owner wants to make dbl.check. Original code is transparent and clear for me. Clearer then a boolen logic, when I try to find the difference in bool sides. But no difference. So it is a codeformat habit.
So it is a codeformat habit.
Yeah, that's why I said "as per NASA C style guide". Direct quote from section 7.2.4.1:
Do not use nested if statements when only the if clause contains actions.
It goes on to show an example of inappropriate nested if
statements that resembles the original code snippet in this issue's OP.
BTW there is a similar scenario in the RF24Mesh::requestAddress()
:
if (getNodeID(mesh_address) != _nodeID) {
if (getNodeID(mesh_address) != _nodeID) {
beginDefault();
return 0;
}
}
which I reduced to
if (getNodeID(mesh_address) != _nodeID && getNodeID(mesh_address) != _nodeID) {
beginDefault();
return 0;
}
on the CMake-4-Linux branch.
Maybe I didn't emphasize the question enough. I was wondering if there was some historic intention of doing a double check. Maybe a kind of signal integrity check?
getAddress
sends a packet in some cases and waits for a reply, the second check is very likely there to just increase the amount of retries, so reliability.
ok I can see that. So, switching to an ||
condition wouldn't be feasible because getAddress()
sends the MESH_ADDR_LOOKUP message to pipe 0 (& auto-ack is disabled for pipe 0 in RF24Mesh). Thus, this workaround for a manual retry. Thanks that clears up some confusion. 👍🏼
@Avamander BTW, the Nasa C style guide links in CONTRIBUTING.md files are currently broken. I'm guessing that NASA just did some kind of update to the NTRS site. Because the doc is so old, I was able to find a copy elsewhere on the web. I'll give them some time to hopefully complete the supposed site update, otherwise we may have to change the link in the CONTRIBUTING.md files.
BTW, the Nasa C style guide links in CONTRIBUTING.md files are currently broken.
They kinda like to move things around. I guess we could keep a copy if we find a nice copy. Or pick something similar but more easily accessible. It was initially picked because it was the closest one to what we had back then.
I've grown to like the practicality & flexibility in that guide. I found a copy http://www.grantronics.com.au/files/CStyleGuide.pdf
The connections is double checked for reliability as Avamander said. I’m wondering if these changes will cause it to run twice every time? That was the reason for the nested if statements.
On Jul 18, 2021, at 4:50 AM, Brendan @.***> wrote:
I've grown to like the practicality & flexibility in that guide. I found a copy http://www.grantronics.com.au/files/CStyleGuide.pdf
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
The &&
condition has to evaluate both operands. Furthermore, I've been testing with debug statements on, and I have been seeing 2 lookup types transmit and be received for both the scenarios I referenced.
That’s not really preferable as it should only do one lookup unless it fails
On Jul 18, 2021, at 11:17 AM, Brendan @.***> wrote:
The && condition has to evaluate both operands. Furthermore, I've been testing with debug statements on, and I have been seeing 2 lookup types transmit and be received for both the scenarios I referenced.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
that's what I thought it should do. I'll try using an ||
condition instead of &&
to see if that matches the originally desired behavior. If not I'll change it back to nested if
statements.
turns out C++ does evaluate both operands of an ||
condition even when the first operand evaluates to true
.
reverting back to nested if statements.
I've noticed that this lib does a double check for connection livelihood when needed. I was wondering what the intention is to check the connection again even after the first check would evaluate to
true
. On the CMake-4-Linux branch I've reducedto
as per the NASA C style guidelines (tests verify that it still works BTW).