cs106a Lect9 Incrementor program... (<- !(not) a vararg (nor a lambda)... )
again just marveling at the subtle beauty of Prof Sahami’s - Stanford code - it’s simple - minimal & yet very deep (at least 2me)
i have to look again to see other code usage of the ivar - which - stores an object’s state in-between method calls (that’s a mouthful)
ie- instance variable - so named bc it relates to instances - instantiation - a new instance of a class (ie an object)
transl: an ivar stores values & those values persist & aren’t lost at the close of any particular method
---
but what i just noticed is: he actually makes use of the ivar & illustrates effective efficient use of it - i have to look carefully at other code - i think in the other code - usually - ivar’s are declared & then used only once
iff: ur only using an ivar once - (i realize) it’s more efficient to make the variable local - to the 1 usage - in a method
I’m looking at his Incrementor - Counter program - which is so simple & yet subtle & profound - perhaps profound just because of its simplicity
But he uses the counter ivar - 4 (technically 5) times - once to declare it - importantly uninitialized (to allow different usages later)
twice in overloaded constructors (that’s 3 times - counting how many times he uses the ‘counter’ ivar) & 4th inside a method (5th he increments the counter - counter++)
& the program outputs the effect of the different usages of that 1 instance variable (he also lectures in a clever & funny way about - persistence of the primitive variable (ivar) - when he says: it should “bother you” - why should it bother me ? ) - funny that i look at it now & hell yeah it bothered me!
changes to the primitive variable should NOT effect the caller- method - the changes shouldn’t persist - or - should they - what a great lesson
i think its lecture 9 (8 or 9) - the more i learn - the more i love his java class - those ‘kids’ are super/uber smart - ‘getting’ that stuff on the 1st pass - ie - live












