Monday, July 27, 2009

What was lost and what was gained in java's designers's decision to not include the pointers of C++,?

write a short discussion

What was lost and what was gained in java's designers's decision to not include the pointers of C++,?
gained : less need for programmers to think about cleaning up the allocated memory.





loss: control over allocated memory.
Reply:There's a copious amount of documentation out there on this subject so there's no reason to write at length. I should also point out that pointers are a feature of both C and C++.





It's obvious that preventing the use of pointers significantly bolstered the amount of security that programmers could get 'for free' given that issues like stack overruns, memory corruption and inadequate/incorrect freeing of memory (though this is more an attribute of GC than lack of pointers) were largely nullified.





Given that programmers tend to be kind of ornery and resistant to change, preventing a means for direct memory access and easy manipulation of the data within rubbed a lot of programmers the wrong way. Many pointed out that the use of pointers was one of the ways that C/C++ were able to be such a high-level language while still maintaining considerable speed. While assembly language and machine code were still de rigeur amongst people that were looking to squeeze the most amount of speed and memory out of a given program, things like pointers and compilers that effectively optimized C and C++ code did a lot to win people over, not to mention that it's a hell of a lot easier to read.





With Java, however, a lot of those same programmers felt that the security that was gained was offset by the decreases in speed and the fact that a lot of the earlier JIT compilers were pretty pokey didn't help that. For all their faults, Sun's been pretty adamant about listening to the community so they've made a lot of improvements regarding in-place optimization, HotSpot, conditional compilation, etc.





Another problem that came about is the fact that removing pointers made existing C and C++ code hard to port. That's generally pretty true of any new or significantly changed language, however. Eventually people got a handle on how to best replicate pointer usage, tips and tricks got passed around and things improved.


No comments:

Post a Comment