Fair point -- although to really answer this we need to understand what the original code is trying to achieve to see what the actual problem domain is.
b.c ?? a.c might be sufficient, depending on how you want to deal with nullish values.
('c' in b ? b.c : a.c) might also do.
But whatever you're trying to do, it's unlikely that merging two objects to look up a property is the most reasonable option. :)
http://perpetual.education is a design/programming school. We like to be part of the discussion over here at Dev.to / We have time-slots for free conversations for career advice IRL : )
hmmm
Fair point -- although to really answer this we need to understand what the original code is trying to achieve to see what the actual problem domain is.
b.c ?? a.c might be sufficient, depending on how you want to deal with nullish values.
('c' in b ? b.c : a.c) might also do.
But whatever you're trying to do, it's unlikely that merging two objects to look up a property is the most reasonable option. :)
This is what the code should describe (not just to you - but to your average programmer)
I don't think that's a reasonable expectation.
The code will describe the what and the how, but I have yet to see a programming language which encapsulates the why of it.
If your argument is that it should contain comments which explain why this is being done, then I agree.
In which case, I guess your point is that the snippet provided is defective because it lacks this. :)