Kip

Code excerpt

Written by Kip on Monday, May 19, 2008 at 3:05 pm (EDT)
Tagged as:

Do programmers still need to understand pointers in this day and age?  Is Java a good programming language?  Why is there something as opposed to nothing?

Please do not indulge in heated debate pertaining to any of the above unanswerable philosophical questions.  Instead, just let me show you what can happen when someone has to program in Java without understanding two things about the Java language: 1) all parameters are always passed by value; 2) objects are basically pointers (whose address can only be modified by assignment).  Without this knowledge, you might write code like this1:

            //ABC-defect#123456 - SetChildren update currSel so we need to take bakup of
                //currSel so that after returning we can set it back to original currSel
           TreeNode tmpCurrSel = currSel;
       int result = setChildren(currSel,fullTree,0,tmpLevels);
          if (tmpCurrSel != null)
                currSel=tmpCurrSel; //ABC-defect#123456

Hint: it does not work as the developer expected it to (and obviously he never tested it after he coded it).

1 Code has been anonymized, but indentation and grammar is preserved for EnhancedRealism™.
No Comments
RSS feeds: Kip's - Stephanie's - Both
Admin