John Du Hart <compwhizii <at> gmail.com> writes:

> It's just another style I've encountered on other projects and I 
> personally like.

The syntax itself is fine, but at Wikia we have found (after a recent post 
mortem) that out of 23 "Fatal Error" code defects found in production, 
7 of them were due to method calls on null object references.  If any 
method in that chain returns null then the request fails.  It most cases 
core MediaWiki objects do return a valid stub object of some kind, but 
not all of them do (and in some cases they return null. intermittently 
so the code works "most of the time", which is in many ways the worse 
scenario). Introducing a pattern like this in a code base this large is 
therefore problematic.  The "clean looking code" benefit is perhaps 
outweighed by the fact that you need to add extra "if" conditions or 
try/catch blocks everywhere to handle local null object exceptions.  
In our case, we are trying to ensure during code reviews that we just 
check for null objects in all "if" conditions, which does also lead to more 
highly nested and less readable code.  

Everything is a tradeoff, but IMHO you do need to check for null in chains 
like that, which means you can't really get away with it (at least not for 
long).  





_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to