Who modified my local variable?
nick at byu.edu
Tue Jun 13 14:03:40 MDT 2006
On Tuesday 13 June 2006 13:11, Michael L Torrie wrote:
> Sure. But my real point was the Java habit of always doing "new" causes
> a ton of problems for Java programmers heading into C++. Rather than
> use a local variable allocated on the stack, they do "new" which leaks.
> That is the problem. So really it's not a language problem; it's a
> programmer problem. But a programmer can be trained; unfortunately Java
> is not a good trainer in this instance. In my opinion it would be
> better to subject a new CS student to C and C++ in all their glory and
> then introduce them to managed, Garbage-collected languages later,
> rather than the other way around.
Hrm. Maybe. But, silent show of hands, how many plugger's first programming
language was some dialect of BASIC?
The key concepts are dynamic allocation, and variable binding. Each can be
separated, and can be taught better in some languages than others.
Some forms of BASIC implement neither concept. Every variable is in fact 'the
variable', and there is no dynamic allocation (save for variable sized,
This is where I started. Then, I went straight to assembly language, and then
to C++. Having a good grasp of what is occurring physically in hardware
(asm) made understanding pointers trivial. To understand references, IMO,
implement a compiler (or take a compiler course), and you'll have no more
confusion--it's all about symbol tables.
The real learning issues come about when different parts of these two concepts
have overlapping syntax across languages.
IMO, better to introduce language concepts w/o dynamic memory management
first, then memory management and variable bindings as two distinct (though
interdependent) topics later.
You can teach dynamic memory management in subtle ways w/o it. For example,
teach linked lists, but implement them using arrays. Then when you introduce
pointers--tahdah!--the student already understands exactly what is happening.
The storage location has moved from the array he explicitly declared to an
intrinsic property of the computer, and now, in his mind, the pointer is no
different from the array index variable he had to use before.
Sales Team Automation, LLC
1335 West 1650 North, Suite C
Springville, UT 84663 +1 801.853.4090
More information about the PLUG