fail-hard vs log/continue

fail-hard vs log/continue 

 

if (!component.getStore) { 

wspt.error("DependentFieldPlugin requires a component that uses a Store"); 

return; 

}  

 

wspt.assert(component.getStore, "DependentFieldPlugin requires a component that uses a Store"); 

 

top way doesn't bust the page, bottom one does. in general, i think it is a very good habit to fail as hard as possible, including busting the page and getting a nice & nasty javascript error in your console. 

 

when it comes to diagnostics, we know assertions are always true, but the error/return/proceed, we can't look at the code and know our state anymore without inspecting in a debugger due to the branch, which makes remote diagnostics really-friggin-hard. fail-fast reduces possible error states & complexity. 

 

see raymond chen's blog for discussion of the issue from all sides: 

Only an idiot would have parameter validation, and only an idiot would not have it 

Hey, let's report errors only when nothing is at stake! 

 

i would add that in the case of windows and maintaining backwards compat with previously undefined behavior, they forced themselves into a corner of needing to continue even though the program behavior is no longer well-defined, because none of the code was well-defined in the first place. but in a less challenging environment forcing every single detail to be well defined at all times is appealing to me.