J
jacob navia
Richard said:> Charlie Gordon said:
>
>
> Absolutely right. Same applies to motor vehicles, kitchen knives, and
> indeed any other potentially dangerous tool that can be misused by humans.
> So what do you want people to do - go back to the Stone Age? Or maybe
> just maybe - they can learn how to use tools properly?
>
Yes, let's follow H's logic:
Driving cars is a dangerous activity that needs good concentration.
The idea of introducing a safety belt is flawed since good drivers
do not make accidents. Only bad drivers do.
THEN
If we introduce this safety belt it will make that bad drivers
could survive their accidents, provoking new accidents. This is
bad.
THEN
We should keep on with our cars like they are now. No safety
belts, and brakes that will fail if the driver drives
beyond the legal speed limit. This will make all bad drivers
have an accident sooner, they will die sooner, and only good
drivers will survive.
THEN
We will have no more accidents!!
------------------------------------------------------------------
What is obviously missing here is the fact that most drivers are good
drivers most of the time, but NOT ALWAYS!
The safety belt allows drivers that make an occasional mistake to
avoid the consequences of a driving mistake. A good designed interface
makes errors harder to do requiring less concetration from the part
of the programmer.
Any reasoning can be distorted obviously. The alternative is not to
strip C of pointers because pointers can be misused. It is creating
good designed interfaces that are less error prone.
strncpy can produce non zero terminated strings, what in C is an
accident waiting to happen. Yes, you should always REMEMBER
to zero terminate the string yourself, but...
WHY should we require from the programmer this tedious stuff
that can be done automatically by a better designed interface???
No reason but the rigid conservative attitude that has led to C being
still in the 70s.
Note that by its name, this function misleads the programmer into
believing that. The "n" variants of functions take a limit. This
is a nowhere stated rule but many programmers will believe that.
Of course you should know that it doesn't zero terminate, and
if you do not know that you are "a stupid" programmer by definition.
This is the justification by stupid people that fail to see
that when a tool is persistently "misused" the *design* of the tool
is wrong!
Programmers are always the ones that get blamed for everything by the
higher ups. In this case the people that know better and could
have included a correct function for limited string copy in their
interface AGES ago.
OF COURSE anyone can write a better function, but many people will
have a tendency of facility and use strncpy *because is there*
already and its use is "free".
> This is very, very simple to understand, and programming is a highly
> complex activity requiring considerable intelligence to do properly.
Designing interfaces too.
> Anyone not capable of understanding that strncpy is not supposed to be
> used as a "safe string copy" has no business being a programmer. If you
> find such people in your place of work, fire them. They'd be far happier
> in marketing, anyway.
>
This "elitist" attitude is at the heart of bad software engineering.
No, the tools are correct. That most people make a mistake when using
them is only THEIR FAULT.
THEY are stupid. Not the ones that persist
in an interface that is provably error prone! Of course not. Those
aren't stupid.
The central point I want to make:
Good programmers are good most of the time. NOT ALWAYS!
Good designed interfaces make errors harder to do.