[Bluej-discuss] How to call an accessor method in a different class?
Ian Barland
ibarland at radford.edu
Mon Nov 19 21:26:04 GMT 2007
Aryeh M. Friedman writes:
>
> I also assume you require i=i+1 ;-)
>
After I was noticing that each semester one or two students will spend hours
and hours thrashing because they wrote (what seems reasonable to them)
`i=i++`, yes I now avoid using ++ for at least two weeks after introducing
loops. (Still, some students have seen ++ on their own, and still fall into
that trap.)
I don't actually *require* students to spell out `this.` or `i = i + 1` or
always use getters/setters, but the code I show in class does these things.
> The same person claimed that ++i was better then i++
> because it made the intent "clearer" (??!!?)
>
Well, it does render the error `i = ++i` innocuous.
On using `this.`: I like the technique, and it does help students. But it's
not a panacea: even weeks after writing methods involving multiple objects,
there is a strong kneejerk impulse to add 'this.' in front of *every* method
call, rather than actually think about what object they want to ask. (Over
time, I'm becoming less and less convinced that OO is any less confusing for
beginners than procedural programming.)
--Ian
More information about the bluej-discuss
mailing list