6 ms·
It shouldn't be ok to write code that is known to throw an error, and handle it by suppressing that error. Silently failing code is just a bug waiting to happen
by samdalton 15y ago
It shouldn't be ok to write code that is known to throw an error, and handle it by suppressing that error. Silently failing code is just a bug waiting to happen.
It's also making the interpreter do unnecessary error handling work when a simple "if ($_GET['foobar'])" would suffice.
- philjackson 15y agoIt should be ok (the poor PHP implementation aside). Auto-vivification is something that's very useful in Perl and I miss it greatly in the languages I program in now. Being able to do this: $one->{ two }->{ three } = [ $four ] Without having to check every link for definedness makes for cleaner code, IMO. Making it optional "suppressing that error" would be a good middle-ground. Coffeescipt has the existential operator, not quite on a par with Perl's autovivification, which allows: zip = lottery.drawWinner?().address?.zipcode
- samdalton 15y agoThe Coffeescript ? operator is certainly quite handy. I suppose it's explicit nature is what helps, as information on the error you're trying to mask is built into the syntax. With @ in PHP however, you simply don't know what it's trying to stop, and what undesirable affects it may cause, which I think is the main objection to it.