Rui Maciel said:
The example you provided represented poorly written code where
a pointer refers to an object after it's lifetime as ended.
Understanding an object's storage duration is very basic stuff.
Therefore, this code goes against extremely basic concepts
which are clearly defined and therefore can only be written by
incompetent programmers. A programming language cannot be deemed
safe or unsafe due to mistakes made by incompetent programmers.
If that was the case then even the most basic scripting language
could be accused of being unsafe if a fool could inadvertently
write a script which runs any acceptable but obviously unwanted
command, such as rm -rf /*, and this isn't true.
You almost seem to be implying that only incompetent programmers
make mistakes. I think what you really mean is that only incompetent
programmes make *certain kinds* of mistakes -- but I think that's
unrealistic.
There are real advantages to languages that make even stupid mistakes
(like using a pointer outside its lifetime) either easy to detect,
or impossible to make in the first place. (And yes, there are also
real advantages to languages like C that give you enough rope to
shoot yourself in the foot, and depend on the programmer to get
things right.)
One example: pre-ANSI C didn't have prototypes, and so compilers
weren't able to diagnose function calls that pass the wrong number
of parameters. I remember running into that when I was first
learning C (coming from a Pascal background), and being horrified.
You could argue (with some justification) that I was incompetent for
writing an incorrect call, but the language design was also partly at
fault for not providing a mechanism to catch such errors. (And the
C committee apparently agreed, and added prototypes to the language.)
The safety of a language is not a simple binary attribute. But a
language (like ANSI C) that diagnoses function calls with the wrong
number of arguments is *safer* than a language (like pre-ANSI C)
that doesn't.