10-03-2018 10:35 AM
@Frozen wrote:
Now that I know of this feature, I will have to think about ways to use it, and guard against it, in the future.
A better idea would be to leverage it to your advantage. 😄
You might have to ask yourself why the incoming empty array has some dimensions that have nonzero size. Maybe there is problematic code upstream (e.g. that weird "build array" of height=1 in your original example) that can easily be fixed instead of having to carry that thing around just to work around the problem with a band-aid solution far downstream.
10-03-2018 10:45 AM - edited 10-03-2018 10:46 AM
Yes, I will be looking for ways to use it (and make sure to put comments about expected behavior so someone doesn't "fix" it. )
If it was just my code, "fixing" the up-stream code would be an option. Unfortunately, I am not the only developer in my company.
10-03-2018 11:05 AM
What's the problem with notifying the "upstream" devs of bugs in their software? Easy! Doing it without hurting their feelings? Difficult! 😄
10-03-2018 11:12 AM
Well, the problem is it is not a "bug" to have an empty, non-zero array.
Good programming practice is to check your inputs. As rolfk rightly pointed out, if the code will "break" when the for-loop executes on an empty array, then you need to protect against it. Awareness is the key.
10-03-2018 06:22 PM
@Frozen wrote:
Well, the problem is it is not a "bug" to have an empty, non-zero array.
Good programming practice is to check your inputs. As rolfk rightly pointed out, if the code will "break" when the for-loop executes on an empty array, then you need to protect against it. Awareness is the key.
That's defensive programming. Design by contract is also valid and basically means "don't give me bad inputs".