You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
T:code-hygieneGeneral cleanup and restructuring of code to provide clarity, flexibility, and modularity.T:testingRelated to testinggood first issueGood for newcomers
@tzdybal I was thinking that initially,
I had put assertions like assert.NotNill(fn) to verify the returned object from the helper function.
But then discussed it with Matthew and came to the conclusion that helper functions (in this case, initAndStartNodeWithCleanup) need to be robust, and in the current state, instead of propagating an error, or returning nil, they simply panic.
So, is there a need to check the type of the return value, if the program is going to panic beforehand anways, if something goes wrong?
The only reason why I suggested this change is readability. When I first saw this code I was really confused - why type assertion is used when result is discarded anyways? Why there is no error check (second variable)? It was not obvious that this code ensures that returned object is of expected type.
Switching to (not adding 😉) require.IsType make the intention of the code obvious. This code is way more expressive and still holds all the same assumptions (it will stop if something goes wrong).
The only reason why I suggested this change is readability. When I first saw this code I was really confused - why type assertion is used when result is discarded anyways? Why there is no error check (second variable)? It was not obvious that this code ensures that returned object is of expected type.
Switching to (not adding 😉) require.IsType make the intention of the code obvious. This code is way more expressive and still holds all the same assumptions (it will stop if something goes wrong).
Aha, I see! You're right, the code did look confusing in the previous state 😅
Learning new practices everyday :D
T:code-hygieneGeneral cleanup and restructuring of code to provide clarity, flexibility, and modularity.T:testingRelated to testinggood first issueGood for newcomers
Activity
PrathyushaLakkireddy commentedon Feb 28, 2024
@tzdybal I would like to work on this issue, Thank you.
AryanGodara commentedon Feb 28, 2024
@tzdybal I was thinking that initially,
I had put assertions like
assert.NotNill(fn)to verify the returned object from the helper function.But then discussed it with Matthew and came to the conclusion that helper functions (in this case,
initAndStartNodeWithCleanup) need to be robust, and in the current state, instead of propagating an error, or returningnil, they simplypanic.So, is there a need to check the type of the return value, if the program is going to panic beforehand anways, if something goes wrong?
I'm just curious about this one 😅
tzdybal commentedon Feb 28, 2024
The only reason why I suggested this change is readability. When I first saw this code I was really confused - why type assertion is used when result is discarded anyways? Why there is no error check (second variable)? It was not obvious that this code ensures that returned object is of expected type.
Switching to (not adding 😉)
require.IsTypemake the intention of the code obvious. This code is way more expressive and still holds all the same assumptions (it will stop if something goes wrong).test : Use IsType assertions in test (#1574)
AryanGodara commentedon Feb 29, 2024
Aha, I see! You're right, the code did look confusing in the previous state 😅
Learning new practices everyday :D