Pyramid of doom (programming): Difference between revisions

Content deleted Content added
m Object property dereferencing: idk, clearer; minor edit
m might be confusing since direct array lookup would be [] not (), also style
Line 11:
</source>
 
This code first looks in the arraycollection of windows for a window with the name "Main", gets the 5th subview within it, then calls the <code>size</code> method to return a structure with the view's dimensions, and finally calls the <code>width</code> method on that structure to produce a result that is assigned to <code>theWidth</code>.
 
The problem with this approach is that the code assumes that all of these values exist. While it is reasonable to expect that a window will have a size and that size will have a width, it is not at all reasonable to assume that a window named "Main" will exist, nor that it has five subviews. If either of those possibilities are true, one of the methods will be invoked on null, producing a null pointer error.